Take the community feedback survey now.
AI OnAI Off
Take the community feedback survey now.
I have not looked at the code in detail but my guess is that the migration step is run before the Model synchronization (that is when there is dynamically created proxy classes are created that "links" together the typed properties on your model class with the backing PropertyDataCollection).
If that is the case then you could try to access the data the "old" way as:
(model.Property["ContentReferenceToBeCopied"] as PropertyContentReference).ContentLink
public class MyMigrationStep : MigrationStep { private readonly Injected _contentRepository;
private readonly Injected _contentTypeRepository;
private readonly Injected _contentModelUsage;
public override void AddChanges()
{
var contentType = _contentTypeRepository.Service.Load();
var contentReferences = _contentModelUsage.Service.ListContentOfContentType(contentType)
.Select(contentUsage => contentUsage.ContentLink);
foreach (var contentReference in contentReferences)
{
var model = _contentRepository.Service.Get(contentReference);
if (model.ContentReferenceToBeCopied != null) // PROBLEM: this is null when running as a MigrationStep
{
var clone = (MyPageModel)model.CreateWritableClone();
if (clone.ContentAreaToCopyTo == null)
{
clone.ContentAreaToCopyTo = new ContentArea();
}
if (clone.ContentAreaToCopyTo.IsEmpty)
{
clone.ContentAreaToCopyTo.Items.Add(new ContentAreaItem
{
ContentLink = clone.ContentReferenceToBeCopied
});
_contentRepository.Service.Publish(clone);
}
}
}
}
}
[ContentType(DisplayName = "MyPageModel", GUID = "ab83f1e2-2619-43c1-90a4-42e2fd35618b", Description = "")]
public class MyPageModel : PageTypeBaseModel
{
[Display(
Name = "ContentReferenceToBeCopied",
GroupName = SystemTabNames.Content,
Order = 100)]
[Required]
[UIHint(UIHint.CatalogEntry)]
[AllowedTypes(typeof(MyVariationContent))]
public virtual ContentReference ContentReferenceToBeCopied { get; set; }
[Display(
Name = "ContentAreaToCopyTo",
Description = "",
GroupName = SystemTabNames.Content,
Order = 200)]
[Required]
[UIHint(UIHint.CatalogEntry)]
[AllowedTypes(typeof(MyVariationContent))]
public virtual ContentArea ContentAreaToCopyTo { get; set; }
}
But running the same manually from a controller works: Any ideas are welcome! Using EPiServer.Framework 10.10.4.