1

Closed

Automate upgrading discriminators from code

description

We are developing a CMS for multiple sites. Sometimes we need to handle changing type names of Content Items. With multiple sites and multiple environments, this take a long time to do manually. In production you would turn of the FixClass.aspx page so it has be be something more automatically.
 
The way we have handled it is to make a IPluginInitializer with AutoInitialize, that handles the upgrade which will get a connection to the database and run a couple of queries to the database.
 
[AutoInitialize]
public class DiscriminatorUpgradeInitializer : IPluginInitializer
{
    public void Initialize(IEngine engine)
    {
        var handler = engine.Resolve<IDiscriminatorUpgradeHandler>();
 
        handler.DeleteObsolete("ReallyOldContentItem");
        handler.UpdateObsolete<NewContentItem>("OldContentItem");
    }
}
 
This works, although much of the code in the implementation of IDiscriminatorUpgradeHandler is copied and refactored from FixClass.aspx.cs. It would be great if this functionality could be provided from N2, because then it's much easier for us and others to automate that process.
 
Also, InstallationManager is also hard to mock since it doesn't have virtual properties/methods or implementing an interface. The only this from it that we needed in this case is the GetConnection and GetCommand. So I would also suggest to refactor those two methods into an interface.
 
If you think this is a good idea, I'm happy to provide some more code on what we have done.
Closed Apr 9 at 3:17 AM by bherila
Moved to github

comments

bherila wrote Apr 8 at 9:44 PM

Hi there, I think this is a great idea. I moved this issue to https://github.com/n2cms/n2cms/issues/98 so please comment there with more information or send a pull request to allow us to integrate this functionality into the official n2 branch. Thanks!