Optionally inserting records into a database based on custom metadata on publish
Hi,
I've seen that you can publish entire pages to a database using a transport, but I was wondering if it is possible to optionally insert/update/delete a record in an external database depending on selected custom metadata.
For example, let's say I've got a sidebar on all pages in a given section of a website, and I want to randomly display selected content from other enabled pages in that sidebar. Meanwhile, other sections may have a sidebar that displays different content. My thought is to have two custom metadata fields, one with a code (or codes) representing the type of content in the page, and another with a checkbox for displaying the content in the relevant sidebar. When publishing, if the box is checked, it would insert a record with the page id, code(s) and selected content from the page into an external database. If the record already exists, it would update it, if the box is unchecked, it would delete it.
My guess is that the answer is no, and that I'd need to publish the entire site to a database, and then check for that metadata in there, but I wanted to ask if anyone had done anything else like this.
Thanks.
Discussions are closed to public comments.
If you need help with Cascade CMS please
start a new discussion.
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
1 Posted by Ryan Griffith on May 30, 2014 @ 12:45 PM
Hi,
I believe you can accomplish this using a custom Publish Trigger, which are triggered each time an asset is published. This trigger would need to check the asset being published to see if it is an applicable page, and if so, read your metadata and content and update the database.
I wrote a sample publish trigger not long ago that is similar. It calls an external script with custom GET variables appended onto the script URL. You will most likely need to tweak the code, but this may be able to provide a good starting point.
A few other possible ways you could go about this is to:
Please let me know if you have any questions.
Thanks!
2 Posted by Wing Ming Chan on May 30, 2014 @ 01:04 PM
I can offer an easy web service solution, as suggested by Ryan. Using my AssetTree class, I can traverse a site, visit every page, check a metadata flag, and do something to the page accordingly. See AssetTree Recipes for an example. Combined with
$cascade->getSites
, this can be done to all sites.Wing
3 Posted by tomlinson on Jun 02, 2014 @ 03:37 PM
Thanks to both of you, this information is of great help! Custom Publish Triggers are exactly what I'm looking for.
4 Posted by Ryan Griffith on Jun 02, 2014 @ 04:18 PM
Thank you for following up, I am glad to hear we were able to point you in the right direction.
I'm going to go ahead and close this discussion, but please feel free to comment or reply to re-open if you have any additional questions.
Have a great day!
Ryan Griffith closed this discussion on Jun 02, 2014 @ 04:18 PM.