OJS Plugin custom scheduledTask in OJS (v2.4.8.2)

Hey all,

Is it possible to add a custom scheduledTask to a custom OJS plugin that extends on the functionality of scheduledTasks.xml and adds a new one such as the following:

<task class="classes.tasks.EmailArticlePublished">
	<descr>Send automated email to all article authors and editors once the article has been published</descr>
	<frequency hour="0"/>
</task>

Let me know if this is possible to do with a plugin?

Thanks!

Hey all,

Just wondering if there is a way to have a hook or plugin that adds a new scheduledTask or cron to OJS?

Thanks!

Hi @LiamNorman

Yes, that is possible. See for example the book for review plugin: it has a scheduledTasks.xml. For it to be considered/run, there should be a cron job executing this:

php tools/runScheduledTasks.php plugins/generic/booksForReview/xml/scheduledTasks.xml

Thus, you could do the same in your plugin: add the scheduledTasks.xml and an appropriate line in your cron job.

You could also take a look in the crossref export plugin. It uses AcronPlugin::parseCronTab hook, in order for its scheduled task to be considered when the acron plugin is used.

Let me know if you need some other information…

Best,
Bozana

Hey @bozana. Thank you so much! You wouldn’t by any chance have an example that I could look at or a git repo? Also would I need to configure anything for the default cronjob in order to run that or?

We aren’t using Acron so I think your first approach sounds best, just wondering about the above, thanks!

Hey sorry to digress but I was wondering if I add a new method to a DAO. Can I just extend that DAO in a plugin or? If so then how would I call it? Sorry I am new to OJS but really liking it.

Thanks!

Hi @LiamNorman

You have a new, you own plugin, correct? If so, you can add a file scheduledTasks.xml to your plugin folder, e.g. like in the Book For Review plugin: ojs/scheduledTasks.xml at ojs-stable-2_4_8 · pkp/ojs · GitHub. If not, you can create such a file and position it anywhere, e.g. in the OJS main folder.
Of course you would also need to implement the class you want to be executed, I suppose EmailArticlePublished. This class should implement the function executeActions. See e.g. these examples:
ojs/BooksForReviewReminder.inc.php at ojs-stable-2_4_8 · pkp/ojs · GitHub
ojs/CrossrefInfoSender.inc.php at ojs-stable-2_4_8 · pkp/ojs · GitHub
Then you would only need to configure you cron job, to call php tools/runScheduledTasks.php path/to/your/scheduledTasks.xml

Could you please explain a little bit more what would you exactly like to do with DAO?

Best,
Bozana