Asset Facotry Plugin to Copy Pages Across Sites

jklingman's Avatar

jklingman

29 Oct, 2010 07:59 PM

I am trying to figure out a way for a customer to create a page in a site, and automatically have that page copied to multiple (5+) sites into specified folders. Is this possible with an asset factory plugin, or would a workflow trigger work here? I'd rather do an asset factory plugin since they're not using workflows right now, but I'll take whatever works. I know an asset factory can produce copies of pages, but I didn't know if those pages could be copied into another site, into a specific folder within that site. Any examples would be very helpful. Thanks!

  1. 1 Posted by Mike on 09 Nov, 2010 10:40 PM

    Mike's Avatar

    I think this is possible using an asset factory plugin because you can set the parent folder of a new asset using the Cascade API. I was looking to see if we have our asset factory plugin code available somewhere (the actual plugins themselves, not just the sample project), but I haven't found it. Reason I say that is our Create Resized Images plugin creates new assets.

    Anyway, here is the snippet of code that does the new asset creation:

    private static final void persistNewImage(File newFile, String username) throws FatalPluginException
    {
        Create create = new Create();
        create.setUsername(username);
        create.setAsset(newFile);
        create.setInstantiateWorkflow(false);
        create.setCreateNewInstance(true);
        try
        {
            create.perform();
        }
        catch (Exception e)
        {
            throw new FatalPluginException("Unable to create a resized copy: " + e.getMessage(), e);
        }
    }

    So, the newFile parameter here is actually the asset that is passed to the plugin (via the doPluginActionPost() method), but the byte data has been modified (resized). So, you could do something similar with a Page and do something like:

    private static final void persistNewPage(Page newPage, String username) throws FatalPluginException
    {
       newPage.setParentFolderIdentifier(<some folder Identifier>);
    
        Create create = new Create();
        create.setUsername(username);
        create.setAsset(newPage);
        create.setInstantiateWorkflow(false);
        create.setCreateNewInstance(true);
        try
        {
            create.perform();
        }
        catch (Exception e)
        {
            throw new FatalPluginException("Unable to create page: " + e.getMessage(), e);
        }
    }

    If the folder identifier you specify is in another site, then that might work. Another option is to read a Folder in another site by path using the Read operation and then you can use the setParentFolder() method rather than setParentFolderIdentifier().

    You will actually have to store the current Page's parent folder in a local variable somewhere before you use the method above because otherwise the asset create by the asset factory will be put into the last parent folder that was set on the asset.

    Asset creation is kind of weird when using the API, but it will be getting slightly better in 6.8.

    Let me know if that makes sense.

  2. 2 Posted by jklingman on 11 Nov, 2010 02:36 AM

    jklingman's Avatar

    Mike,

    Thank you very much for the response! We're in the requirements gathering phase right now, so I'll take this into consideration and try it in a few weeks. Thanks again!

  3. jklingman closed this discussion on 11 Nov, 2010 02:36 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac