Вопрос

I was just trying to write small deployer extension where if user publish/unpublish page/component/binary from the tridion, its records will go into specific table using storage extension.

Storage extension part is already done!!

Well I can easily write PageDeploy/ComponentDeploy and BinaryDeploy as I have got these classes in com.tridion.deployer.modules.

I can also write easily custom page undeployer class, however struggling to write component, binary undeploy as we don't have any class for that.

Please suggest whether is it possible or not, if yes point me to write class or method to get it.

Thanks.

Это было полезно?

Решение

Yup, there is no Component Undeploy or Binary Undeploy as you found out by yourself.

Frank has a good example on how to extend the binary storage to track undeploy events here and for components you'll have to use ComponentPresentationUndeploy instead.

Другие советы

Below is the sample code to track the Component and Binary in the DAO.

Component: Sample code to Add and same goes for update and delete

@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);

    }
}

Binary: Sample code Add and same goes for update and delete

@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);
        }
    }
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top