0
votes

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?
1
Andrew Eddie has an application that you install as a cron job and then it polls each plugin in the cron group on a schedule. The basic issue is that a web application that only runs in response to a request needs ... a request so it's not a reliable way to check for a cron unless you know for certain you have a lot of traffic or you somehow trigger a request automatically on a schedule. That's why crons would usually run as commandline applications. The framework will support a Daemon so you might be able to work with that but again that does seem to suppose server access.Elin
so I even would have to install an application on the server? out of the question. then I could just as well use cronjobs. And as i said, the ability to run exactly on schedule doesn't really matter; if there's not traffic at all it's perfectly fine not to run the job.codeling
If you are happy with it not being on a strict schedule you can as mentioned by other people just kick it when a request happens and check the time.Elin
As I stated in my question already, the problem I have there is not this general idea, which I already mention, but how to best store the time there. Have you even read the question?codeling
Your question is 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? I'd probably cache it or store it in the parameters of the plugin.Elin

1 Answers

1
votes

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!