Removing metadata by extending the TransportPackageHandler

One of the requirements during on of our recent projects was that content items in Tridion (Components) should have internal metadata.

The definition of the requirement is as follow:

  • Metadata should be available on every Component.
  • Metadata should not be on the “Content” tab.
  • Metadata should be searchable by content editors.
  • Metadata should NOT be available in the Tridion Content Broker database.

Adding the required metadata fields to Schemas in Tridion will cover all the requirements, except the last one. By default, Tridion will add all metadata available on any content item to the transport package during the publishing process and it will be published to the Tridion Content Broker database. This is expected behavior, because the Tridion Content delivery API allows us to query on all metadata fields.

Tridion provides extension points where you have the option to to be able to customize the standard behavior (i.e. Custom Resolver/Renderer, Event System). One of the undocumented extension points is the TransportPackageHandler. This extension point enables you to hook into the publish process just before the transport package is transported to the Deployer.

At this point we are able to manipulate the output of the publish process and remove any fields needed, like the metadata fields. The metadata fields that needs to be removed can for example be identified by prefixing the field name with “internal_”.

  1. Create a Schema; on the “Metadata Design” tab add one or more fields prefixed with “internal_” (image 1).

schema

Image 1

  1. Implement a Class that inherits from ITransportPackageHandler interface. The interface is part of the Tridion.ContentManager.Publishing.Transporting.dll. Reference the DLL in your solution.

Note: The DLL is not available in %TRIDION_HOME%\bin\client directory. Copy the DLL that is added to GAC during the installation of Tridion (Content Manager): %Windows%\Microsoft.NET\assembly\GAC_MSIL\Tridion.ContentManager.Publishing.Transporting

transporthandler
Image 2

  1. The class needs to be compiled in an strong Name assembly and registered in the GAC.
  2. Register the Handler in the configuration file Tridion.contentmanager.config in %TRIDION_HOME%\config.

The handler needs to be registered for any specific item type (i.e. Component, Page, Category)

<transporting rootStorageFolder=”c:\Temp”>
<mappings>
<clear />
<add itemType=”Tridion.ContentManager.CommunicationManagement.Page,               Tridion.ContentManager, Version=7.1.0.1290, Culture=neutral, PublicKeyToken=360aac4d3354074b”>
<handler type=”Tridion.ContentManager.Publishing.Transporting.DefaultPageHandler” assembly=”Tridion.ContentManager.Publishing.Transporting, Version=7.1.0.1290, Culture=neutral, PublicKeyToken=ddfc895746e5ee6b” />
</add>
<add itemType=”Tridion.ContentManager.ContentManagement.Component, Tridion.ContentManager, Version=7.1.0.1290, Culture=neutral, PublicKeyToken=360aac4d3354074b”>
<!– handler type=”Tridion.ContentManager.Publishing.Transporting.DefaultComponentHandler” assembly=”Tridion.ContentManager.Publishing.Transporting, Version=7.1.0.1290, Culture=neutral, PublicKeyToken=ddfc895746e5ee6b” / –>
<handler type=”Tridion.TransportPackageHandler.MetadataRemoverPackageHandler” assembly=”Tridion.TransportPackageHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9ad8c6b8da2c6bc2″ />
</add>

  1. Restart the TcmPublisher Service.

The metadata of the components are stored in the file components.xml in the transport package. The extension will remove the fields prefixed as “internal_”.

 

<Components>
<Component Id=”tcm:2003-9168″ isMultimedia=”false”>
<Mandatory>
<Title>MetadataRemover</Title>
<VersionInfo>
<Version>2</Version>
<Revision>0</Revision>
<CreationDate>2014-10-29T12:16:46</CreationDate>
<RevisionDate>2014-10-29T14:50:51</RevisionDate>
<Author>TRAIN1\Administrator</Author>
</VersionInfo>
<Schema Id=”tcm:2003-9167-8″ />
<OwningPublication Id=”tcm:0-1003-1″ />
</Mandatory>
<Custom>
 <Metadata xmlns=”uuid:2cd12384-0126-4445-b35f-417aefa96370″>
        <creator>Sia</creator>
      </Metadata>
</Custom>
</Component>
</Components>

Note: If you’re running dedicated Publisher server(s) the assembly should be installed on all publisher servers.

 

The solution is available for download on Bitbucket: https://bitbucket.org/sshibani/tridion.transportpackagehandler