我想構建一個Sitecore管道處理器,它可以在上傳時獲取媒體項目的ID並將該ID保存到現有的由第三方應用程序使用的自定義數據庫。如何創建一個Sitecore管道處理器,當一個新項目上傳到媒體庫時運行
我一直無法找到任何操作方法或示例如何做到這一點?
我爲我的代碼使用Sitecore 8.0 Update 5和MVC結構。
我想構建一個Sitecore管道處理器,它可以在上傳時獲取媒體項目的ID並將該ID保存到現有的由第三方應用程序使用的自定義數據庫。如何創建一個Sitecore管道處理器,當一個新項目上傳到媒體庫時運行
我一直無法找到任何操作方法或示例如何做到這一點?
我爲我的代碼使用Sitecore 8.0 Update 5和MVC結構。
可以在uiUpload
管道檢查,但不會針對編程創建的項目,即它只會在用戶通過CMS接口上傳的物品火災。
創建一個新的處理器類:
public class ExternalSystemProcessor
{
public void Process(UploadArgs args)
{
foreach (Item file in args.UploadedItems.Where(file => file.Paths.IsMediaItem))
{
// Custom code here
SaveToExternalSystem(file.ID);
}
}
}
然後修補後在默認保存處理器:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
<sitecore>
<processors>
<uiUpload>
<processor type="MyProject.Custom.Pipelines.ExternalSystemProcessor, MyProject.Custom" mode="on"
patch:after="*[@type='Sitecore.Pipelines.Upload.Save, Sitecore.Kernel']" />
</uiUpload>
</processors>
</sitecore>
</configuration>
我不記得在新項目上傳到媒體庫時將執行的任何管道,但您應該能夠使用item:created
事件。
只需檢查args中的項目(ItemCreatedEventArgs
)是否爲媒體項目並執行您的代碼。
public void OnItemCreated(object sender, EventArgs args)
{
var createdArgs = Event.ExtractParameter(args, 0) as ItemCreatedEventArgs;
if (createdArgs != null)
{
if (createdArgs.Item != null)
{
...
}
}
}
可以檢查的項目是使用'item.Paths.IsMediaItem'媒體 – jammykam