Created
April 15, 2020 14:03
-
-
Save ATaat/a46860099bb59496554d823a989236e1 to your computer and use it in GitHub Desktop.
Umbraco 7 Migration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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