Custom Setup Module

Topics: Customizing Orchard, Writing modules
Jun 7, 2012 at 11:26 AM

Hi guys,

I would like to make a setup module to insert custom data in my custom modules.

How can I do that?

Tnx

Coordinator
Jun 8, 2012 at 6:39 AM

What do you mean?

Jun 8, 2012 at 7:06 AM

@Salvodif: if i understand you, then "setup module to insert custom data" should do some initial data inserts. You could use migration or implement IFeatureEventHandler.

Jun 10, 2012 at 8:43 PM

@agono: yes I mean it!

Jun 11, 2012 at 5:51 PM
agono wrote:

@Salvodif: if i understand you, then "setup module to insert custom data" should do some initial data inserts. You could use migration or implement IFeatureEventHandler.

Excuse me, I need something that starts when recipe is selected during orchard setup. A something that can make me able to create pages instances and others in order to populate my database with default custom data. I suppose the same behavior used to create default welcome page during initial setup.

I think that I need to extend the DefaultOrchardCommandHandler class.

is it right?

Thanks


Jun 12, 2012 at 9:16 AM

Yes  if you want to create your content via commands in recipe, it is necessary to extend DefaultOrchardCommandHandler as in Orchard.Web\Modules\Orchard.Pages\Commands\PageCommands.cs. But the approach agono suggested is also possible. Implement your IFeatureEventHandler and create your content in the Enabled event.

 

        void IFeatureEventHandler.Enabled(Feature feature)
        {
            if (feature.Descriptor.Name == "yourFeatureName")
            {
                MethodToCreateYourContent();
            }

        }

And in the method create your content in any way you need ( ContentManager, Commands ...)

 

Jun 12, 2012 at 11:11 AM

I did the following:

public partial class PortalSectionMigrations : DataMigrationImpl, IFeatureEventHandler
	{
		private IOrchardServices _services;

		public PortalSectionMigrations(IOrchardServices services)
		{
			_services = services;
		}

		public int Create()
		{
			// Creates content types and related database schemas.
			SchemaBuilder.CreateTable("PortalSectionPartRecord",
				table => table
					.ContentPartRecord()
					.Column<string>("SubTitle", c => c
						.WithLength(255))
					.Column<string>("Payoff", c => c
						.WithLength(255))
					.Column<string>("ColorCode", c => c
...............................
				);

......................


		public void Enabled(Feature feature)
		{
			var record = _services.ContentManager.New("PortalSectionPart");
			_services.ContentManager.Create(record, VersionOptions.Published);

			var portalSection = record.As<PortalSectionPart>();

                        /// portalSection is null

			_services.ContentManager.Publish(record);
		}
the Create function is not call before the Enabled :-\

Jun 12, 2012 at 11:21 AM

I would definitely separate the Data migration implementation and the feature handler. I tried to implement the data creation in the data migration class and encountered a few problems, so I had to put the data creation to a separate class.

Jun 12, 2012 at 11:30 AM
Edited Jun 12, 2012 at 11:35 AM

Ok I found the first one, I need to check if it's the right feature... of course, if it still doesn't work I will change class