Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I programmatically disable an Orchard module?

Tags:

orchardcms

From Migrations.cs, I want to disable one module if it is enabled, and enable another one if it is not already enabled. How can I do this?

like image 951
Giscard Biamby Avatar asked Oct 24 '12 19:10

Giscard Biamby


2 Answers

OK, I figured this out by looking at the Controller and Command classes in Orchard.Modules. First I had to add a project reference to Orchard.Modules, and then in Migrations.cs:

    public int UpdateFrom2() {
        var features = _moduleService.GetAvailableFeatures().ToDictionary(m=>m.Descriptor.Id, m=>m);
        if (features.ContainsKey("TinyMce") && features["TinyMce"].IsEnabled) {
            _moduleService.DisableFeatures(new string[] { "TinyMce" });
        }

        if (features.ContainsKey("TinyMceDeluxe") && !features["TinyMceDeluxe"].IsEnabled) {
            _moduleService.EnableFeatures(new string[] { "TinyMceDeluxe" });
        }

        return 3; 
    }
like image 198
Giscard Biamby Avatar answered Oct 31 '22 06:10

Giscard Biamby


I think you should take a look at the Orchard tool: you can enable and disable features and get a list of the enabled ones. Look at FeatureCommands.cs in Orchard.Modules project. Hope this helps you.

like image 1
fg_garda Avatar answered Oct 31 '22 05:10

fg_garda