0

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.

Daniel Neagu
  • 1,711
  • 11
  • 13
Manoj Singh
  • 7,569
  • 34
  • 119
  • 198

2 Answers2

4

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.

Nuno Linhares
  • 10,214
  • 1
  • 22
  • 42
  • @Nuno..thanks for reply!! the objective is here that earlier we were having custom triggers on ITEMS table to update our new table PUBLISH_ACTION to get all the entries of page, component and binary, whenever there is any insert/update/delete in ITEM tables. As this is not correct approach as it voilates the support contract, I am trying to use storage extension to get it done, storage extension is already done and now i have written deployer extension to add values to DAO class, PAGE is done as we have both undeploy and deploy methods, struggling for bianry and componentm, please sugest!! – Manoj Singh Jan 10 '13 at 07:35
  • can I also create custom storage extension class like JPAComponentDAOExtension which will extend JPAComponentPresentationDAO and implement ComponentPresentationDAO to do above activities for adding/deleting/updating component and putting these values in my new database table using storage extension – Manoj Singh Jan 10 '13 at 20:42
1

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);
        }
    }
}
Manoj Singh
  • 7,569
  • 34
  • 119
  • 198