diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-06-05 09:01:03 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-06-05 09:01:03 +0400 |
commit | 756d1e0dc348a411a0b3fbe6ed07bf63f8793ea9 (patch) | |
tree | 5bc88c591c8f4451d5677169f90ef06f741997fe /plugins | |
parent | 3e03b0a7ca4055b4f05be7d4ec7bcfaacf364eff (diff) |
refs #5301 added scheduled task generator, some code tweaks and more docs
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/CoreConsole/Commands/GenerateScheduledTask.php | 58 | ||||
-rw-r--r-- | plugins/ExamplePlugin/Tasks.php | 37 | ||||
-rw-r--r-- | plugins/PrivacyManager/Tasks.php | 1 | ||||
-rw-r--r-- | plugins/UserCountry/Tasks.php | 2 |
4 files changed, 97 insertions, 1 deletions
diff --git a/plugins/CoreConsole/Commands/GenerateScheduledTask.php b/plugins/CoreConsole/Commands/GenerateScheduledTask.php new file mode 100644 index 0000000000..541e93239d --- /dev/null +++ b/plugins/CoreConsole/Commands/GenerateScheduledTask.php @@ -0,0 +1,58 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ + +namespace Piwik\Plugins\CoreConsole\Commands; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +/** + */ +class GenerateScheduledTask extends GeneratePluginBase +{ + protected function configure() + { + $this->setName('generate:scheduledtask') + ->setDescription('Adds a tasks class to an existing plugin which allows you to specify scheduled tasks') + ->addOption('pluginname', null, InputOption::VALUE_REQUIRED, 'The name of an existing plugin which does not have any tasks defined yet'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $pluginName = $this->getPluginName($input, $output); + + $exampleFolder = PIWIK_INCLUDE_PATH . '/plugins/ExamplePlugin'; + $replace = array('ExamplePlugin' => $pluginName); + $whitelistFiles = array('/Tasks.php'); + + $this->copyTemplateToPlugin($exampleFolder, $pluginName, $replace, $whitelistFiles); + + $this->writeSuccessMessage($output, array( + sprintf('Tasks.php for %s generated.', $pluginName), + 'You can now start specifying your scheduled tasks', + 'Enjoy!' + )); + } + + /** + * @param InputInterface $input + * @param OutputInterface $output + * @return array + * @throws \RunTimeException + */ + protected function getPluginName(InputInterface $input, OutputInterface $output) + { + $pluginNames = $this->getPluginNamesHavingNotSpecificFile('Tasks.php'); + $invalidName = 'You have to enter the name of an existing plugin which does not already have any tasks defined'; + + return $this->askPluginNameAndValidate($input, $output, $pluginNames, $invalidName); + } + +} diff --git a/plugins/ExamplePlugin/Tasks.php b/plugins/ExamplePlugin/Tasks.php new file mode 100644 index 0000000000..4ccb2bbd69 --- /dev/null +++ b/plugins/ExamplePlugin/Tasks.php @@ -0,0 +1,37 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ +namespace Piwik\Plugins\ExamplePlugin; + +class Tasks extends \Piwik\Plugin\Tasks +{ + public function schedule() + { + $this->hourly('myTask'); // method will be executed once every hour + $this->daily('myTask'); // method will be executed every daily + $this->weekly('myTask'); // method will be executed once every weekly + $this->monthly('myTask'); // method will be executed once every monthly + + // pass a parameter to the task + $this->weekly('myTaskWithParam', 'anystring'); + + // specify a different priority + $this->monthly('myTask', null, self::LOWEST_PRIORITY); + $this->monthly('myTaskWithParam', 'anystring', self::HIGH_PRIORITY); + } + + public function myTask() + { + // do something + } + + public function myTaskWithParam($param) + { + // do something + } +}
\ No newline at end of file diff --git a/plugins/PrivacyManager/Tasks.php b/plugins/PrivacyManager/Tasks.php index 9ed9cbcf3a..e7eafc2e4e 100644 --- a/plugins/PrivacyManager/Tasks.php +++ b/plugins/PrivacyManager/Tasks.php @@ -10,6 +10,7 @@ namespace Piwik\Plugins\PrivacyManager; class Tasks extends \Piwik\Plugin\Tasks { + public function schedule() { $this->daily('deleteReportData', null, self::LOW_PRIORITY); diff --git a/plugins/UserCountry/Tasks.php b/plugins/UserCountry/Tasks.php index 414675fcdf..5bb9b15c3a 100644 --- a/plugins/UserCountry/Tasks.php +++ b/plugins/UserCountry/Tasks.php @@ -14,7 +14,7 @@ class Tasks extends \Piwik\Plugin\Tasks { // add the auto updater task if GeoIP admin is enabled if (UserCountry::isGeoLocationAdminEnabled()) { - $this->addScheduledTask(new GeoIPAutoUpdater()); + $this->scheduleTask(new GeoIPAutoUpdater()); } } }
\ No newline at end of file |