Permalinks - Update tables using cron

10 posts by 3 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: October 9   (RSS)

By gversion - October 3

Hello,

I have set up a crawler to import product listings from various websites on a daily basis. I would like to have CMSB auto generate the permalinks for the products. Is it possible to somehow get the Permalinks plugin to run via cron so my product listings table has any missing permalinks generated every hour?

Or is there a better way to do this?

Thanks for any help or advice!

Regards,
Greg

By gversion - October 6

Hi,

Further to my previous post, we have modified the crawler to create the permalink so don't need to run the permalink plugin anymore.

So now the products are being imported with a permalink value however when I view the product page at the front end I receive a 404 error.

To resolve this I just need to go into CMSB, edit the product and simply click "save" (without making any changes to any of the fields) and then the product loads correctly at the front end (no more 404!).

I have compared the product row in the database before and after saving the listing and the fields are identical so I don't know why the product suddenly loads after saving the record in CMSB.

I would be extremely grateful if someone could explain to me what's going on here.

Thank you,

Greg

By Toledoh - October 6

Hi Greg.

No idea if this will help, but in the plugin screen, there's a link to "Update table" which runs /cmsb/admin.php?_pluginAction=permalink_pluginMenu_updateTable

Could you use that somehow?

Cheers,
Tim (toledoh.com.au)

By gversion - October 6

Hi Tim,

Thanks very much for the suggestion. I tried to run this but it didn't fix the issue...

Regards,

Greg

By gversion - October 6

Problem identified! We need the crawler to update the permalinks table too. Manually running the permalinks plugin doesn't do this (I guess because the crawler has already created the permalinks).

Maybe we should just have the permalinks plugin run via cron every 5 minutes and not have the crawler create the permalinks...

Is it possible to configure the permalinks plugin to update a specific table on cron?

Thanks again,

Greg

By gversion - October 9

Hi,

If anyone could get back to me on this question it would be hugely appreciated:

Is it possible to configure the permalinks plugin to update a specific table on cron?

Thank you,

Greg

By cwuensche - October 9

Hi Greg,
I'm looking into whether or not this is possible or how it can be done. I will post an answer here when I find out more.

Carl
PHP Programmer
interactivetools.com

By gversion - October 9

Thanks, Carl. My plan is to create a new PHP file that I run with cron every 5 minutes.

This is what I have so far:

<?php
require_once('cmsb/lib/schema_functions.php');
require_once('cmsb/lib/mysql_functions.php');
require_once('cmsb/lib/database_functions.php');
require_once('cmsb/plugins/permalinks/permalinks_pluginsMenu.php');

$response = _permalink_updateTable('listings');

But when I run this I am seeing this error:

PHP Warning:  Use of undefined constant DATA_DIR - assumed 'DATA_DIR' (this will throw an Error in a future version of PHP) in /home/sites/8b/7/786382f535/public_html/cmsb/lib/schema_functions.php on line 127
PHP Warning:  scandir(): Directory name cannot be empty in /home/sites/8b/7/786382f535/public_html/cmsb/lib/schema_functions.php on line 131
PHP Warning:  Invalid argument supplied for foreach() in /home/sites/8b/7/786382f535/public_html/cmsb/lib/schema_functions.php on line 131
PHP Fatal error:  Uncaught Error: Call to undefined function startsWith() in /home/sites/8b/7/786382f535/public_html/cmsb/lib/database_functions.php:202
Stack trace:
#0 /home/sites/8b/7/786382f535/public_html/cmsb/lib/schema_functions.php(172): getTableNameWithoutPrefix('listings')
#1 /home/sites/8b/7/786382f535/public_html/cmsb/plugins/permalinks/permalinks_pluginsMenu.php(149): loadSchema('listings')
#2 /home/sites/8b/7/786382f535/public_html/update_permalinks_listings.php(7): _permalink_updateTable('listings')
#3 {main}
  thrown in /home/sites/8b/7/786382f535/public_html/cmsb/lib/database_functions.php on line 202

By cwuensche - October 9

The constant is defined in init.php, so this should fix those errors/warnings.

<?php
require_once 'cmsb/lib/init.php';
require_once 'cmsb/lib/schema_functions.php';
require_once 'cmsb/lib/mysql_functions.php';
require_once 'cmsb/lib/database_functions.php';
require_once 'cmsb/plugins/permalinks/permalinks_pluginsMenu.php';

$response = _permalink_updateTable('listings');
Carl
PHP Programmer
interactivetools.com