Skip to content

Instantly share code, notes, and snippets.

@ATaat
Created April 15, 2020 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ATaat/a46860099bb59496554d823a989236e1 to your computer and use it in GitHub Desktop.
Save ATaat/a46860099bb59496554d823a989236e1 to your computer and use it in GitHub Desktop.
Umbraco 7 Migration
using Umbraco.Web.WebApi;
[UmbracoAuthorize]
public class MigrationController : UmbracoAuthorizedApiController
{
public Result GetStartMigration()
{
try
{
Migrate();
}
catch (Exception ex)
{
return new Result() { Success = false, ErrorMessage = ex.Message.ToString() };
}
return new Result() { Success = true };
}
private void Migrate() {
var newsPage = Services.ContentTypeService.GetContentType("newsPage");
if (newsPage != null)
{
string imageAlias = "image";
// Check if homepage has property
if (!newsPage.PropertyTypes.Any(x => x.Alias == imageAlias))
{
newsPage.AddPropertyType(new PropertyType(Services.DataTypeService.GetDataTypeDefinitionByName("Media Picker"), imageAlias), "Content");
var image = newsPage.PropertyTypes.FirstOrDefault(x => x.Alias == imageAlias);
image.Name = "Afbeelding";
image.Description = "Selecteer een afbeelding voor het item (wordt getoond in overzichten).";
}
// Save newsPage
Services.ContentTypeService.Save(newsPage);
}
}
public class Result
{
public bool Success { get; set; }
public string ErrorMessage { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment