Get page_url value before update it in db

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Get page_url value before update it in db

Post by nervino »

Hello,
how can I get the alternate url field value (page's option tab) just before save it in db?

My goal is to make a UDT that, in conjunction with the ContentEditPre event, does:

1) queries the cms_content table and stores in a variable the value of the page_url field

2) gets the new Page URL value (alternate url in option tab)

2) queries a custom db table to see if there are duplicates entries for that url

3) if there are not, inserts the url in the custom table and update the .htaccess file with a 301 status, redirecting the old url to the new one

I'm using cmsms 1.10.3

thanks
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Get page_url value before update it in db

Post by calguy1000 »

The Content object attached to the ContentEditPre event already contains the values that were either calculated or entered by the user. The old data (before the change) is not included.

Your event handler could 'query' the content table for the appropriate content id and extract the page_url field.

i.e:

Code: Select all

$content_obj = $params['content'];
$query = 'SELECT page_url FROM '.cms_db_prefix().'content WHERE content_id = ?';
$old_url = $db->GetOne($query,array($content->Id());
$new_url = $content_obj->URL();

if( $old_url != $new_url ) {
  // ... do your stuff ....
}
And BTW. Please do not write to the CMSMS content tables etc. or the tables of any other module. Go ahead and read whatever you want, but writing to the database of another module or the core may lead to problems.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Post Reply

Return to “Developers Discussion”