Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagephp
title/plugins/my_plugin/my_plugin_plugin.php
<?php
class MyPluginPlugin extends Plugin {
 
    ...
 
    public function install($plugin_id) {
		Loader::loadModels($this, array("CronTasks"));

		$task = array(
			'key' => "my_task", // a string used to identify this cron task (see MyPluginPlugin::cron())
			'plugin_dir' => "my_plugin", // the plugin directory of this plugin
			'name' => "My Plugin Task", // the name of this cron task
			'description' => "This cron tasks does stuff", // the description of this task
			'type' => "time" // "time" = once per day at a defined time, "interval" = every few minutes or hours
		);
		$this->CronTasks->add($task);

		// Add additional cron tasks as needed...
    }
 
    public function cron($key) {
        // This method is invoked once for each different cron taskstask configured by the plugin and identified by $key
    }
}
?>

...

Cron tasks are automatically executed at the appropriate time as configured by Company > Automation - Company settings.