Almost everything that ImportExport does in TCM can be
detected in TCM event system extension. You can do that by examining Session.ContextData
collection. ImportExport stores Export-/Import-/UndoInstruction object there
with the “tcm:ImportExportService”
key. Constant for that string (as well as identifiers of other Tridion components,
such as Publilsher or Workflow service which identify themselves by putting
their Ids into ContextData) is publicly available in TcmApplicationId.ImportExportService in
Tridion.ContentManager.Common.dll.
Below is the prototype for event handlers that will
intercept application data reads/writes. In case call is initiated from
ImportExport, application data can be patched to replace TCM URIs to WebDAV
URLs.
public class CustomAppDataPatchingExtension : TcmExtension
{
public CustomAppDataPatchingExtension()
{
EventSystem.Subscribe<IdentifiableObject, LoadApplicationDataEventArgs>(PatchApplicationDataOnExport, EventPhases.Processed);
EventSystem.Subscribe<IdentifiableObject, SaveApplicationDataEventArgs>(PatchApplicationDataOnImport, EventPhases.Initiated);
}
private void PatchApplicationDataOnExport(IdentifiableObject
subject, LoadApplicationDataEventArgs eventArgs, EventPhases phase)
{
if (eventArgs.ApplicationId == "your appdata id" &&
subject.Session.ContextData.ContainsKey(TcmApplicationId.ImportExportService)
&&
subject.Session.ContextData[TcmApplicationId.ImportExportService] is ExportInstruction)
{
// patch application data by replacing TCM URI with WebDAV
URL (or whatever)
}
}
private void PatchApplicationDataOnImport(IdentifiableObject
subject, SaveApplicationDataEventArgs eventArgs, EventPhases phase)
{
if
(subject.Session.ContextData.ContainsKey(TcmApplicationId.ImportExportService) &&
subject.Session.ContextData[TcmApplicationId.ImportExportService] is ImportInstruction)
{
foreach (var applicationData in
eventArgs.ApplicationDataCollection.Where(ad => ad.ApplicationId == "your appdata id"))
{
// patch application data by replacing WebDAV URL back to
TCM URI (or whatever)
}
}
}
}
Downside of this approach is that there is no event is
generated when global application data (with subjectId == null) is ported.
Every action (read, save, localize etc.) that ImportExport does during export/import/undo is identified with this marker in ContextData. So you can use this marker when you want
to disable some custom actions implemented via event system (such as initiating
workflow or publishing of an item) that should only be done when user interacts
with the Tridion, but not on bulk import.
View comments