Migration with templates: only override physical file if it doesn't exist
When running a migration with a package.xml file that contains templates, it creates the templates in the database of Umbraco, but it also creates the physical file on the disk.
The problem is that it will also override the physical file if it already exists. Is there a way to prevent this and only create the file if it does not exist?
Some context to clarify:
We have a package that acts more or less as a very simple starter kit that head starts the development of new projects. One of the things this package does is setup the basic content structure in the tree, including an (empty) homepage with a template.
During development, this template will be updated, changed and put into source control. However, if there is a developer that joins further into development, he will get the template from source control, but because it's the first time running Umbraco, the migration will override the template possibly causing loss of data.
In case my solution gets lost in our other lengthy discussion, here is my proposed solution to the problem.
Instead of including the template views in a package xml/zip.
I removed them from the package and added the views to the Razor class library, they are then copied to the website project using the build targets file in the same way as the App_Plugins folder. Yo should then be able to use a Condition to only copy if newer or desn't exist etc.
Then in my PackageMigrationbase, I registered the views as templates.
protected override void Migrate()
{
//register the views as templates first
_fileService.CreateTemplateWithIdentity("ForumMaster", "forumMaster",null);
var master = _fileService.GetTemplate("forumMaster");
if (master != null)
{
var templatesToFind = new[] { "forum", "forumPost", "login", "members", "profile", "register", "reset", "verify", "searchPage" };
foreach (var template in templatesToFind)
{
_fileService.CreateTemplateWithIdentity(template.FirstCharToUpper(), template,null,master);
}
}
//Now the templates are registered we can import the package xml
ImportPackage.FromEmbeddedResource<ImportPackageXmlMigration>().Do();
Context.AddPostMigration<PublishRootBranchPostMigration>();
}
Migration with templates: only override physical file if it doesn't exist
When running a migration with a package.xml file that contains templates, it creates the templates in the database of Umbraco, but it also creates the physical file on the disk.
The problem is that it will also override the physical file if it already exists. Is there a way to prevent this and only create the file if it does not exist?
Some context to clarify: We have a package that acts more or less as a very simple starter kit that head starts the development of new projects. One of the things this package does is setup the basic content structure in the tree, including an (empty) homepage with a template.
During development, this template will be updated, changed and put into source control. However, if there is a developer that joins further into development, he will get the template from source control, but because it's the first time running Umbraco, the migration will override the template possibly causing loss of data.
In case my solution gets lost in our other lengthy discussion, here is my proposed solution to the problem.
Instead of including the template views in a package xml/zip.
I removed them from the package and added the views to the Razor class library, they are then copied to the website project using the build targets file in the same way as the App_Plugins folder. Yo should then be able to use a Condition to only copy if newer or desn't exist etc.
Then in my PackageMigrationbase, I registered the views as templates.
is working on a reply...