Import Data not updating properties

  • Updated

When updating a value for a property and then overwriting that value with an import data file, the property value does not change back to the original value during the import.

Steps: 
1. Export data with content type for example an Image File for All Site Data folder. 
2. Modify the Copyright for an image file 
3. Import data into the All Site Data folder.

The problem is the property value does not change back to the original value during the import.

After selecting the Upload and Verify File button, there‚Äôs a warning message Local property "xxx" originates from code and therefore it is not overwritten by imported property

Which makes the property value does not change back to the original value during the import. please see http://take.ms/vf6gz 

What you could do is to register an event handler for IDataImportEvents.ContentImporting event (will be raised before a content item is imported) and in the event handler set Saved date for the content that is to be imported to now. Then each imported content will be considered newer than the existing content and hence it will overwrite the existing content. 
See the following code  for an example on how such event handler could be implemented.

using EPiServer.DataAbstraction;
using EPiServer.Enterprise;
using EPiServer.Enterprise.Transfer;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
namespace ReferenceSite
{
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class ForceContentImportModule : IInitializableModule
{
private IDataImportEvents _dataImportEvents;
private DateTime _importStarted = DateTime.UtcNow;
public void Initialize(InitializationEngine context)
{
_dataImportEvents = context.Locate.Advanced.GetInstance<IDataImportEvents>();
_dataImportEvents.Starting += SetImportStartedTime;
_dataImportEvents.ContentImporting += SetSavedTime;
}
public void Uninitialize(InitializationEngine context)
{
_dataImportEvents.Starting -= SetImportStartedTime;
_dataImportEvents.ContentImporting -= SetSavedTime;
}
private void SetImportStartedTime(ITransferContext transferContext, DataImporterContextEventArgs e)
{
_importStarted = DateTime.UtcNow;
}
private void SetSavedTime(ITransferContext transferContext, ContentImportingEventArgs e)
{
var savedProperties = e.TransferContentData.RawLanguageData.Concat(new[] { e.TransferContentData.RawContentData }).Select(c => c.Property.FirstOrDefault(p => p.Name.Equals(MetaDataProperties.PageSaved)));
foreach (var savedDateProperty in savedProperties.Where(p => p != null))
{
savedDateProperty.Value = _importStarted.ToString("R", CultureInfo.InvariantCulture);
}
}
}
}