如何在tridion 2011中编写部署器扩展的Component Undeploy和Binary Undeploy功能

时间:2013-01-10 06:30:57

标签: tridion tridion-2011 tridion-content-delivery tridion-deploy-extension

我只是尝试编写小型部署者扩展,如果用户从tridion发布/取消发布页面/组件/二进制,其记录将使用存储扩展名进入特定表。

存储扩展部分已经完成!!

我可以轻松编写 PageDeploy / ComponentDeploy和BinaryDeploy ,因为我在com.tridion.deployer.modules中有这些类。

我也可以轻松编写自定义页面undeployer类,但是很难编写组件,二进制取消部署,因为我们没有任何类。

请建议是否可能,如果是,请指点我写课程或方法来获得它。

感谢。

2 个答案:

答案 0 :(得分:4)

是的,您自己发现没有组件取消部署或二进制取消部署。

Frank有一个很好的例子,说明如何扩展二进制存储以跟踪取消部署事件here以及组件,您必须使用ComponentPresentationUndeploy。

答案 1 :(得分:1)

以下是跟踪DAO中的Component和Binary的示例代码。

组件:要添加的示例代码以及用于更新和删除的示例代码

@Component("JPAComponentDAOExtension")
@Scope("prototype")

public class JPAComponentDAOExtension extends JPAComponentPresentationDAO implements ComponentPresentationDAO 
{

    public JPAComponentDAOExtension(String storageId, EntityManagerFactory entityManagerFactory, String storageName) 
    {
        super(storageId, entityManagerFactory, storageName);
    }

    public JPAComponentDAOExtension(String storageId, EntityManagerFactory entityManagerFactory, EntityManager entityManager, String storageName) 
    {
        super(storageId, entityManagerFactory, entityManager, storageName);
    }

    public void create(ComponentPresentation itemToCreate, ComponentPresentationTypeEnum componentPresentationType) throws StorageException 
    {
        super.create(itemToCreate,componentPresentationType);   
        String tcmURI = Integer.toString(itemToCreate.getComponentId());
        ItemDAO item = (ItemDAO) StorageManagerFactory.getDAO(itemToCreate.getPublicationId(),StorageTypeMapping.COMPONENT_META);
        ComponentMeta meta = (ComponentMeta) item.findByPrimaryKey(itemToCreate.getPublicationId(),itemToCreate.getComponentId());
        String schemaID = Integer.toString(meta.getSchemaId()) ;

        PublishActionDAO publishActionDAO = (PublishActionDAO) StorageManagerFactory.getDefaultDAO("PublishAction");
        PublishAction publishAction = new PublishAction();
        publishAction.setAction("ADD"); 
        publishAction.setTcmUri(tcmURI);
        publishAction.setSchemaID(schemaID);
        publishActionDAO.store(publishAction);

    }
}

二进制:示例代码添加,同样适用于更新和删除

@Component("JPABinaryDAOExtension")
@Scope("prototype")

public class JPABinaryDAOExtension extends JPABinaryContentDAO implements BinaryContentDAO 
{

    public JPABinaryDAOExtension(String storageId, EntityManagerFactory entityManagerFactory, String storageName) 
    {
        super(storageId, entityManagerFactory, storageName);
    }

    public JPABinaryDAOExtension(String storageId, EntityManagerFactory entityManagerFactory, EntityManager entityManager, String storageName) 
    {
        super(storageId, entityManagerFactory, entityManager, storageName);
    }

    public void create(final BinaryContent binaryContent, final String relativePath) throws StorageException 
    {
        super.create(binaryContent, relativePath);  
        String url = relativePath;
        String tcmURI = Integer.toString(binaryContent.getBinaryId());

        ItemDAO item = (ItemDAO) StorageManagerFactory.getDAO(binaryContent.getPublicationId(),StorageTypeMapping.BINARY_META);
        BinaryMeta binarymeta = (BinaryMeta) item.findBinaryByPrimaryKey(binaryContent.getPublicationId(),binaryContent.getBinaryId());
        binarymeta.getBinaryType();//to get the binary type

        //You can also check the Relative path as below for specific binary type entries as suggested by Mihai
        if (relativePath.toLowerCase().endsWith(".pdf")) //Looking for PDFs only
        { 
            PublishActionDAO publishActionDAO = (PublishActionDAO) StorageManagerFactory.getDefaultDAO("PublishAction");
            PublishAction publishAction = new PublishAction();
            publishAction.setAction("ADD");
            publishAction.setUrl(url);
            publishAction.setTcmUri(tcmURI);
            publishActionDAO.store(publishAction);
        }
    }
}