Question

In my extension (a plugin) I want some SQL scripts to run every once in a while (some database cleanup operations); once a day or once a week would probably be enough. Doesn't need to be exactly in that interval, it would be well enough to be triggered if someone accesses the site.

In an ideal world those would probably be run by a cron script, but not everybody using my extension will have access to the crontab on their server, so the solution needs to work without cronjobs.

Searching for "joomla cronjob" and combinations of it I haven't yet found anything already existing in the Joomla framework (just additional extensions, like JPrc Cronjobs; but it needs to be either existing in the framework already or included into my extension).

Thinking about implementing it myself (since my plugin already runs on every site call anyway), the immediate solution coming to mind is storing a timestamp whenever doing the operation, and then for the next operation run, checking whether the appropriate interval has already passed.

However, where would I store the timestamp? A separate table seems complete overkill (although it would probably be the cleanest solution). Is there maybe some simple key-value store for Joomla extensions? I didn't see such a thing yet either.

So, my question boils down to:

  • Is there a functionality within Joomla framework (working on Joomla >= 2.5) which triggers some code every once in an interval?
  • Alternatively, is there a place to quickly and simply store a single key-value pair?
Was it helpful?

Solution

Since your code runs on every page call, your second solution would be much simpler to implement. You can utilize the built-in extension parameters to store an extension-specific value.

First, take a look here: https://stackoverflow.com/a/13221472/1867759

This solution would work perfectly for you. The only difference would be that, since you're already within your plugin, you can access the parameters via $this->params rather than calling them from JComponentHelper.

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top