Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@googlemail.com>2014-06-05 08:44:37 +0400
committerThomas Steur <thomas.steur@googlemail.com>2014-06-05 08:44:37 +0400
commit3e03b0a7ca4055b4f05be7d4ec7bcfaacf364eff (patch)
tree47afa18c0b671f38e17405078bdee156ad020058
parent0ed11b178860844b97b967f6cfa1ffd12ab2eaab (diff)
refs #5301 started to simplify scheduled tasks API while staying backwards compatible
-rw-r--r--core/Menu/MenuAbstract.php33
-rw-r--r--core/Plugin.php38
-rw-r--r--core/Plugin/Manager.php33
-rw-r--r--core/Plugin/Tasks.php133
-rw-r--r--core/TaskScheduler.php55
-rw-r--r--plugins/CoreAdminHome/CoreAdminHome.php44
-rw-r--r--plugins/CoreAdminHome/Tasks.php46
-rw-r--r--plugins/CorePluginsAdmin/CorePluginsAdmin.php37
-rw-r--r--plugins/CorePluginsAdmin/Tasks.php36
-rw-r--r--plugins/CoreUpdater/CoreUpdater.php22
-rw-r--r--plugins/CoreUpdater/Tasks.php25
-rw-r--r--plugins/DBStats/DBStats.php36
-rw-r--r--plugins/DBStats/Tasks.php34
-rw-r--r--plugins/PrivacyManager/PrivacyManager.php19
-rw-r--r--plugins/PrivacyManager/Tasks.php30
-rw-r--r--plugins/ScheduledReports/ScheduledReports.php23
-rw-r--r--plugins/ScheduledReports/Tasks.php31
-rw-r--r--plugins/UserCountry/Tasks.php20
-rw-r--r--plugins/UserCountry/UserCountry.php9
19 files changed, 460 insertions, 244 deletions
diff --git a/core/Menu/MenuAbstract.php b/core/Menu/MenuAbstract.php
index 4ffbe8f532..06d972f064 100644
--- a/core/Menu/MenuAbstract.php
+++ b/core/Menu/MenuAbstract.php
@@ -61,42 +61,11 @@ abstract class MenuAbstract extends Singleton
return self::$menus;
}
- $pluginNames = PluginManager::getInstance()->getLoadedPluginsName();
-
- self::$menus = array();
- foreach ($pluginNames as $pluginName) {
- $menu = $this->findMenuInPlugin($pluginName);
-
- if (!empty($menu)) {
- self::$menus[] = $menu;
- }
- }
+ self::$menus = PluginManager::getInstance()->findComponents('Menu', 'Piwik\\Plugin\\Menu');
return self::$menus;
}
- private function findMenuInPlugin($pluginName)
- {
- $menuFile = PIWIK_INCLUDE_PATH . '/plugins/' . $pluginName . '/Menu.php';
-
- if (!file_exists($menuFile)) {
- return;
- }
-
- $klassName = sprintf('Piwik\\Plugins\\%s\\Menu', $pluginName);
-
- if (!class_exists($klassName)) {
- return;
- }
-
- if (!is_subclass_of($klassName, 'Piwik\\Plugin\\Menu')) {
- Log::warning(sprintf('Cannot use menu for plugin %s, class %s does not extend Piwik\Plugin\Menu', $pluginName, $klassName));
- return;
- }
-
- return new $klassName;
- }
-
/**
* Adds a new entry to the menu.
*
diff --git a/core/Plugin.php b/core/Plugin.php
index 1392fc3bc0..0c2c8e8d8b 100644
--- a/core/Plugin.php
+++ b/core/Plugin.php
@@ -277,6 +277,44 @@ class Plugin
}
/**
+ * Tries to find a component such as a Menu or Tasks within this plugin.
+ *
+ * @param string $componentName The name of the component you want to look for. In case you request a
+ * component named 'Menu' it'll look for a file named 'Menu.php' within the
+ * root of the plugin folder that implements a class named
+ * Piwik\Plugin\$PluginName\Menu . If such a file exists but does not implement
+ * this class it'll silently ignored.
+ * @param string $expectedSubclass If not empty, a check will be performed whether a found file extends the
+ * given subclass. If the requested file exists but does not extend this class
+ * a warning will be shown to advice a developer to extend this certain class.
+ *
+ * @return \stdClass|null Null if the requested component does not exist or an instance of the found
+ * component.
+ */
+ public function findComponent($componentName, $expectedSubclass)
+ {
+ $componentFile = sprintf('%s/plugins/%s/%s.php', PIWIK_INCLUDE_PATH, $this->pluginName, $componentName);
+
+ if (!file_exists($componentFile)) {
+ return;
+ }
+
+ $klassName = sprintf('Piwik\\Plugins\\%s\\%s', $this->pluginName, $componentName);
+
+ if (!class_exists($klassName)) {
+ return;
+ }
+
+ if (!empty($expectedSubclass) && !is_subclass_of($klassName, $expectedSubclass)) {
+ Log::warning(sprintf('Cannot use component %s for plugin %s, class %s does not extend %s',
+ $componentName, $this->pluginName, $klassName, $expectedSubclass));
+ return;
+ }
+
+ return new $klassName;
+ }
+
+ /**
* Detect whether there are any missing dependencies.
*
* @param null $piwikVersion Defaults to the current Piwik version
diff --git a/core/Plugin/Manager.php b/core/Plugin/Manager.php
index 9c481bb03b..5a31e484e4 100644
--- a/core/Plugin/Manager.php
+++ b/core/Plugin/Manager.php
@@ -34,6 +34,7 @@ class Manager extends Singleton
protected $pluginsToLoad = array();
protected $doLoadPlugins = true;
+
/**
* @var Plugin[]
*/
@@ -325,6 +326,38 @@ class Manager extends Singleton
}
/**
+ * Tries to find the given components such as a Menu or Tasks implemented by plugins.
+ * This method won't cache the found components. If you need to find the same component multiple times you might
+ * want to cache the result to save a tiny bit of time.
+ *
+ * @param string $componentName The name of the component you want to look for. In case you request a
+ * component named 'Menu' it'll look for a file named 'Menu.php' within the
+ * root of all plugin folders that implement a class named
+ * Piwik\Plugin\$PluginName\Menu.
+ * @param string $expectedSubclass If not empty, a check will be performed whether a found file extends the
+ * given subclass. If the requested file exists but does not extend this class
+ * a warning will be shown to advice a developer to extend this certain class.
+ *
+ * @return \stdClass[]
+ */
+ public function findComponents($componentName, $expectedSubclass)
+ {
+ $pluginNames = $this->getLoadedPlugins();
+
+ $components = array();
+
+ foreach ($pluginNames as $plugin) {
+ $component = $plugin->findComponent($componentName, $expectedSubclass);
+
+ if (!empty($component)) {
+ $components[] = $component;
+ }
+ }
+
+ return $components;
+ }
+
+ /**
* Uninstalls a Plugin (deletes plugin files from the disk)
* Only deactivated plugins can be uninstalled
*
diff --git a/core/Plugin/Tasks.php b/core/Plugin/Tasks.php
new file mode 100644
index 0000000000..2b22c90825
--- /dev/null
+++ b/core/Plugin/Tasks.php
@@ -0,0 +1,133 @@
+<?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\Plugin;
+
+use Piwik\ScheduledTask;
+use Piwik\ScheduledTime;
+
+class Tasks
+{
+ /**
+ * @var ScheduledTask[]
+ */
+ private $tasks = array();
+
+ const LOWEST_PRIORITY = ScheduledTask::LOWEST_PRIORITY;
+ const LOW_PRIORITY = ScheduledTask::LOW_PRIORITY;
+ const NORMAL_PRIORITY = ScheduledTask::NORMAL_PRIORITY;
+ const HIGH_PRIORITY = ScheduledTask::HIGH_PRIORITY;
+ const HIGHEST_PRIORITY = ScheduledTask::HIGHEST_PRIORITY;
+
+ public function schedule()
+ {
+ }
+
+ /**
+ * @return ScheduledTask[] $tasks
+ */
+ public function getScheduledTasks()
+ {
+ return $this->tasks;
+ }
+
+ /**
+ * Schedule the given tasks/method to run once every hour.
+ *
+ * @param string $methodName The name of the method that will be called when the task is being
+ * exectuted. To make it work you need to create a public method having the
+ * given method name in your Tasks class.
+ * @param null|string $methodParameter Can be null if the task does not need any parameter or a string. It is not
+ * possible to specify multiple parameters as an array etc. If you need to
+ * pass multiple parameters separate them via any characters such as '###'.
+ * For instance '$param1###$param2###$param3'
+ * @param int $priority Can be any constant such as self::LOW_PRIORITY
+ *
+ * @return ScheduledTime
+ * @api
+ */
+ protected function hourly($methodName, $methodParameter = null, $priority = self::NORMAL_PRIORITY)
+ {
+ return $this->custom($this, $methodName, $methodParameter, 'hourly', $priority);
+ }
+
+ /**
+ * Schedule the given tasks/method to run once every day.
+ *
+ * See {@link hourly()}
+ * @api
+ */
+ protected function daily($methodName, $methodParameter = null, $priority = self::NORMAL_PRIORITY)
+ {
+ return $this->custom($this, $methodName, $methodParameter, 'daily', $priority);
+ }
+
+ /**
+ * Schedule the given tasks/method to run once every week.
+ *
+ * See {@link hourly()}
+ * @api
+ */
+ protected function weekly($methodName, $methodParameter = null, $priority = self::NORMAL_PRIORITY)
+ {
+ return $this->custom($this, $methodName, $methodParameter, 'weekly', $priority);
+ }
+
+ /**
+ * Schedule the given tasks/method to run once every month.
+ *
+ * See {@link hourly()}
+ * @api
+ */
+ protected function monthly($methodName, $methodParameter = null, $priority = self::NORMAL_PRIORITY)
+ {
+ return $this->custom($this, $methodName, $methodParameter, 'monthly', $priority);
+ }
+
+ /**
+ * Schedules the given tasks/method to run depending at the given scheduled time. Unlike the convenient methods
+ * such as {@link hourly()} you need to specify the object on which the given method should be called. This can be
+ * either an instance of a class or a class name. For more information about these parameters see {@link hourly()}
+ *
+ * @param string|object $objectOrClassName
+ * @param string $methodName
+ * @param null|string $methodParameter
+ * @param string|ScheduledTime $time
+ * @param int $priority
+ *
+ * @return ScheduledTime
+ *
+ * @throws \Exception If a wrong time format is given. Needs to be either a string such as 'daily', 'weekly', ...
+ * or an instance of {@link Piwik\ScheduledTime}
+ *
+ * @api
+ */
+ protected function custom($objectOrClassName, $methodName, $methodParameter, $time, $priority = self::NORMAL_PRIORITY)
+ {
+ if (is_string($time)) {
+ $time = ScheduledTime::factory($time);
+ }
+
+ if (!($time instanceof ScheduledTime)) {
+ throw new \Exception('$time should be an instance of ScheduledTime');
+ }
+
+ if (!is_string($objectOrClassName)) {
+ $objectOrClassName = get_class($objectOrClassName);
+ }
+
+ $this->addScheduledTask(new ScheduledTask($objectOrClassName, $methodName, $methodParameter, $time, $priority));
+
+ return $time;
+ }
+
+ protected function addScheduledTask(ScheduledTask $task)
+ {
+ $this->tasks[] = $task;
+ }
+} \ No newline at end of file
diff --git a/core/TaskScheduler.php b/core/TaskScheduler.php
index a3eab34c24..85c71c9ef8 100644
--- a/core/TaskScheduler.php
+++ b/core/TaskScheduler.php
@@ -10,6 +10,7 @@
namespace Piwik;
use Exception;
+use Piwik\Plugin\Manager as PluginManager;
// When set to true, all scheduled tasks will be triggered in all requests (careful!)
define('DEBUG_FORCE_SCHEDULED_TASKS', false);
@@ -52,7 +53,7 @@ define('DEBUG_FORCE_SCHEDULED_TASKS', false);
*/
class TaskScheduler extends Singleton
{
- const GET_TASKS_EVENT = "TaskScheduler.getScheduledTasks";
+ const GET_TASKS_EVENT = 'TaskScheduler.getScheduledTasks';
private $isRunning = false;
@@ -81,34 +82,42 @@ class TaskScheduler extends Singleton
return self::getInstance()->doRunTasks();
}
- private function doRunTasks()
+
+ // for backwards compatibility
+ private function collectTasksRegisteredViaEvent()
{
- // collect tasks
$tasks = array();
/**
- * Triggered during scheduled task execution. Collects all the tasks to run.
- *
- * Subscribe to this event to schedule code execution on an hourly, daily, weekly or monthly
- * basis.
- *
- * **Example**
- *
- * public function getScheduledTasks(&$tasks)
- * {
- * $tasks[] = new ScheduledTask(
- * 'Piwik\Plugins\CorePluginsAdmin\MarketplaceApiClient',
- * 'clearAllCacheEntries',
- * null,
- * ScheduledTime::factory('daily'),
- * ScheduledTask::LOWEST_PRIORITY
- * );
- * }
- *
- * @param ScheduledTask[] &$tasks List of tasks to run periodically.
+ * @ignore
*/
Piwik::postEvent(self::GET_TASKS_EVENT, array(&$tasks));
- /** @var ScheduledTask[] $tasks */
+
+ return $tasks;
+ }
+
+ private function getScheduledTasks()
+ {
+ /** @var \Piwik\ScheduledTask[] $tasks */
+ $tasks = $this->collectTasksRegisteredViaEvent();
+
+ /** @var \Piwik\Plugin\Tasks[] $pluginTasks */
+ $pluginTasks = PluginManager::getInstance()->findComponents('Tasks', 'Piwik\\Plugin\\Tasks');
+ foreach ($pluginTasks as $pluginTask) {
+
+ $pluginTask->schedule();
+
+ foreach ($pluginTask->getScheduledTasks() as $task) {
+ $tasks[] = $task;
+ }
+ }
+
+ return $tasks;
+ }
+
+ private function doRunTasks()
+ {
+ $tasks = $this->getScheduledTasks();
// remove from timetable tasks that are not active anymore
$this->timetable->removeInactiveTasks($tasks);
diff --git a/plugins/CoreAdminHome/CoreAdminHome.php b/plugins/CoreAdminHome/CoreAdminHome.php
index 4347d60404..f6a64fe946 100644
--- a/plugins/CoreAdminHome/CoreAdminHome.php
+++ b/plugins/CoreAdminHome/CoreAdminHome.php
@@ -8,12 +8,7 @@
*/
namespace Piwik\Plugins\CoreAdminHome;
-use Piwik\DataAccess\ArchiveSelector;
-use Piwik\DataAccess\ArchiveTableCreator;
-use Piwik\Date;
use Piwik\Db;
-use Piwik\ScheduledTask;
-use Piwik\ScheduledTime;
use Piwik\Settings\UserSetting;
/**
@@ -29,7 +24,6 @@ class CoreAdminHome extends \Piwik\Plugin
return array(
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
'AssetManager.getJavaScriptFiles' => 'getJsFiles',
- 'TaskScheduler.getScheduledTasks' => 'getScheduledTasks',
'UsersManager.deleteUser' => 'cleanupUser'
);
}
@@ -39,25 +33,6 @@ class CoreAdminHome extends \Piwik\Plugin
UserSetting::removeAllUserSettingsForUser($userLogin);
}
- public function getScheduledTasks(&$tasks)
- {
- // general data purge on older archive tables, executed daily
- $purgeArchiveTablesTask = new ScheduledTask ($this,
- 'purgeOutdatedArchives',
- null,
- ScheduledTime::factory('daily'),
- ScheduledTask::HIGH_PRIORITY);
- $tasks[] = $purgeArchiveTablesTask;
-
- // lowest priority since tables should be optimized after they are modified
- $optimizeArchiveTableTask = new ScheduledTask ($this,
- 'optimizeArchiveTable',
- null,
- ScheduledTime::factory('daily'),
- ScheduledTask::LOWEST_PRIORITY);
- $tasks[] = $optimizeArchiveTableTask;
- }
-
public function getStylesheetFiles(&$stylesheets)
{
$stylesheets[] = "libs/jquery/themes/base/jquery-ui.css";
@@ -85,23 +60,4 @@ class CoreAdminHome extends \Piwik\Plugin
$jsFiles[] = "plugins/CoreAdminHome/javascripts/pluginSettings.js";
}
- function purgeOutdatedArchives()
- {
- $archiveTables = ArchiveTableCreator::getTablesArchivesInstalled();
- foreach ($archiveTables as $table) {
- $date = ArchiveTableCreator::getDateFromTableName($table);
- list($year, $month) = explode('_', $date);
-
- // Somehow we may have archive tables created with older dates, prevent exception from being thrown
- if($year > 1990) {
- ArchiveSelector::purgeOutdatedArchives(Date::factory("$year-$month-15"));
- }
- }
- }
-
- function optimizeArchiveTable()
- {
- $archiveTables = ArchiveTableCreator::getTablesArchivesInstalled();
- Db::optimizeTables($archiveTables);
- }
}
diff --git a/plugins/CoreAdminHome/Tasks.php b/plugins/CoreAdminHome/Tasks.php
new file mode 100644
index 0000000000..a15f83dc82
--- /dev/null
+++ b/plugins/CoreAdminHome/Tasks.php
@@ -0,0 +1,46 @@
+<?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\CoreAdminHome;
+
+use Piwik\DataAccess\ArchiveSelector;
+use Piwik\DataAccess\ArchiveTableCreator;
+use Piwik\Date;
+use Piwik\Db;
+
+class Tasks extends \Piwik\Plugin\Tasks
+{
+ public function schedule()
+ {
+ // general data purge on older archive tables, executed daily
+ $this->daily('purgeOutdatedArchives', null, self::HIGH_PRIORITY);
+
+ // lowest priority since tables should be optimized after they are modified
+ $this->daily('optimizeArchiveTable', null, self::LOWEST_PRIORITY);
+ }
+
+ public function purgeOutdatedArchives()
+ {
+ $archiveTables = ArchiveTableCreator::getTablesArchivesInstalled();
+ foreach ($archiveTables as $table) {
+ $date = ArchiveTableCreator::getDateFromTableName($table);
+ list($year, $month) = explode('_', $date);
+
+ // Somehow we may have archive tables created with older dates, prevent exception from being thrown
+ if($year > 1990) {
+ ArchiveSelector::purgeOutdatedArchives(Date::factory("$year-$month-15"));
+ }
+ }
+ }
+
+ public function optimizeArchiveTable()
+ {
+ $archiveTables = ArchiveTableCreator::getTablesArchivesInstalled();
+ Db::optimizeTables($archiveTables);
+ }
+} \ No newline at end of file
diff --git a/plugins/CorePluginsAdmin/CorePluginsAdmin.php b/plugins/CorePluginsAdmin/CorePluginsAdmin.php
index c3f0a5f75d..2ff38a1b21 100644
--- a/plugins/CorePluginsAdmin/CorePluginsAdmin.php
+++ b/plugins/CorePluginsAdmin/CorePluginsAdmin.php
@@ -10,12 +10,7 @@ namespace Piwik\Plugins\CorePluginsAdmin;
use Piwik\Config;
use Piwik\Plugin;
-use Piwik\ScheduledTask;
-use Piwik\ScheduledTime;
-/**
- *
- */
class CorePluginsAdmin extends \Piwik\Plugin
{
/**
@@ -26,42 +21,10 @@ class CorePluginsAdmin extends \Piwik\Plugin
return array(
'AssetManager.getJavaScriptFiles' => 'getJsFiles',
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
- 'TaskScheduler.getScheduledTasks' => 'getScheduledTasks',
'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys'
);
}
- /**
- * Gets all scheduled tasks executed by this plugin.
- */
- public function getScheduledTasks(&$tasks)
- {
- $tasks[] = new ScheduledTask(
- 'Piwik\Plugins\CorePluginsAdmin\MarketplaceApiClient',
- 'clearAllCacheEntries',
- null,
- ScheduledTime::factory('daily'),
- ScheduledTask::LOWEST_PRIORITY
- );
-
- if (self::isMarketplaceEnabled()) {
- $sendUpdateNotification = new ScheduledTask ($this,
- 'sendNotificationIfUpdatesAvailable',
- null,
- ScheduledTime::factory('daily'),
- ScheduledTask::LOWEST_PRIORITY);
- $tasks[] = $sendUpdateNotification;
- }
- }
-
- public function sendNotificationIfUpdatesAvailable()
- {
- $updateCommunication = new UpdateCommunication();
- if ($updateCommunication->isEnabled()) {
- $updateCommunication->sendNotificationIfUpdatesAvailable();
- }
- }
-
public function getStylesheetFiles(&$stylesheets)
{
$stylesheets[] = "plugins/CorePluginsAdmin/stylesheets/marketplace.less";
diff --git a/plugins/CorePluginsAdmin/Tasks.php b/plugins/CorePluginsAdmin/Tasks.php
new file mode 100644
index 0000000000..0863a485e6
--- /dev/null
+++ b/plugins/CorePluginsAdmin/Tasks.php
@@ -0,0 +1,36 @@
+<?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\CorePluginsAdmin;
+
+class Tasks extends \Piwik\Plugin\Tasks
+{
+ public function schedule()
+ {
+ $this->daily('clearAllCacheEntries', null, self::LOWEST_PRIORITY);
+
+ if (CorePluginsAdmin::isMarketplaceEnabled()) {
+ $this->daily('sendNotificationIfUpdatesAvailable', null, self::LOWEST_PRIORITY);
+ }
+ }
+
+ public function clearAllCacheEntries()
+ {
+ $marketplace = new MarketplaceApiClient();
+ $marketplace->clearAllCacheEntries();
+ }
+
+ public function sendNotificationIfUpdatesAvailable()
+ {
+ $updateCommunication = new UpdateCommunication();
+ if ($updateCommunication->isEnabled()) {
+ $updateCommunication->sendNotificationIfUpdatesAvailable();
+ }
+ }
+
+} \ No newline at end of file
diff --git a/plugins/CoreUpdater/CoreUpdater.php b/plugins/CoreUpdater/CoreUpdater.php
index e338b22ce1..1097fe04ca 100644
--- a/plugins/CoreUpdater/CoreUpdater.php
+++ b/plugins/CoreUpdater/CoreUpdater.php
@@ -31,30 +31,10 @@ class CoreUpdater extends \Piwik\Plugin
*/
public function getListHooksRegistered()
{
- $hooks = array(
+ return array(
'Request.dispatchCoreAndPluginUpdatesScreen' => 'dispatch',
'Platform.initialized' => 'updateCheck',
- 'TaskScheduler.getScheduledTasks' => 'getScheduledTasks',
);
- return $hooks;
- }
-
- public function getScheduledTasks(&$tasks)
- {
- $sendUpdateNotification = new ScheduledTask($this,
- 'sendNotificationIfUpdateAvailable',
- null,
- ScheduledTime::factory('daily'),
- ScheduledTask::LOWEST_PRIORITY);
- $tasks[] = $sendUpdateNotification;
- }
-
- public function sendNotificationIfUpdateAvailable()
- {
- $coreUpdateCommunication = new UpdateCommunication();
- if ($coreUpdateCommunication->isEnabled()) {
- $coreUpdateCommunication->sendNotificationIfUpdateAvailable();
- }
}
public static function updateComponents(Updater $updater, $componentsWithUpdateFile)
diff --git a/plugins/CoreUpdater/Tasks.php b/plugins/CoreUpdater/Tasks.php
new file mode 100644
index 0000000000..f8c652781c
--- /dev/null
+++ b/plugins/CoreUpdater/Tasks.php
@@ -0,0 +1,25 @@
+<?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\CoreUpdater;
+
+class Tasks extends \Piwik\Plugin\Tasks
+{
+ public function schedule()
+ {
+ $this->daily('sendNotificationIfUpdateAvailable', null, self::LOWEST_PRIORITY);
+ }
+
+ public function sendNotificationIfUpdateAvailable()
+ {
+ $coreUpdateCommunication = new UpdateCommunication();
+ if ($coreUpdateCommunication->isEnabled()) {
+ $coreUpdateCommunication->sendNotificationIfUpdateAvailable();
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/DBStats/DBStats.php b/plugins/DBStats/DBStats.php
index ac6ee1e355..03c04700a1 100644
--- a/plugins/DBStats/DBStats.php
+++ b/plugins/DBStats/DBStats.php
@@ -8,19 +8,13 @@
*/
namespace Piwik\Plugins\DBStats;
-use Piwik\Date;
use Piwik\Option;
use Piwik\Piwik;
use Piwik\Plugin\ViewDataTable;
use Piwik\Plugins\CoreVisualizations\Visualizations\Graph;
use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable;
use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Pie;
-use Piwik\ScheduledTask;
-use Piwik\ScheduledTime;
-/**
- *
- */
class DBStats extends \Piwik\Plugin
{
const TIME_OF_LAST_TASK_RUN_OPTION = 'dbstats_time_of_last_cache_task_run';
@@ -32,42 +26,12 @@ class DBStats extends \Piwik\Plugin
{
return array(
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
- 'TaskScheduler.getScheduledTasks' => 'getScheduledTasks',
'ViewDataTable.configure' => 'configureViewDataTable',
'ViewDataTable.getDefaultType' => 'getDefaultTypeViewDataTable',
"TestingEnvironment.addHooks" => 'setupTestEnvironment'
);
}
- /**
- * Gets all scheduled tasks executed by this plugin.
- */
- public function getScheduledTasks(&$tasks)
- {
- $cacheDataByArchiveNameReportsTask = new ScheduledTask(
- $this,
- 'cacheDataByArchiveNameReports',
- null,
- ScheduledTime::factory('weekly'),
- ScheduledTask::LOWEST_PRIORITY
- );
- $tasks[] = $cacheDataByArchiveNameReportsTask;
- }
-
- /**
- * Caches the intermediate DataTables used in the getIndividualReportsSummary and
- * getIndividualMetricsSummary reports in the option table.
- */
- public function cacheDataByArchiveNameReports()
- {
- $api = API::getInstance();
- $api->getIndividualReportsSummary(true);
- $api->getIndividualMetricsSummary(true);
-
- $now = Date::now()->getLocalized("%longYear%, %shortMonth% %day%");
- Option::set(self::TIME_OF_LAST_TASK_RUN_OPTION, $now);
- }
-
public function getStylesheetFiles(&$stylesheets)
{
$stylesheets[] = "plugins/DBStats/stylesheets/dbStatsTable.less";
diff --git a/plugins/DBStats/Tasks.php b/plugins/DBStats/Tasks.php
new file mode 100644
index 0000000000..b0919220c8
--- /dev/null
+++ b/plugins/DBStats/Tasks.php
@@ -0,0 +1,34 @@
+<?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\DBStats;
+
+use Piwik\Date;
+use Piwik\Option;
+
+class Tasks extends \Piwik\Plugin\Tasks
+{
+ public function schedule()
+ {
+ $this->weekly('cacheDataByArchiveNameReports', null, self::LOWEST_PRIORITY);
+ }
+
+ /**
+ * Caches the intermediate DataTables used in the getIndividualReportsSummary and
+ * getIndividualMetricsSummary reports in the option table.
+ */
+ public function cacheDataByArchiveNameReports()
+ {
+ $api = API::getInstance();
+ $api->getIndividualReportsSummary(true);
+ $api->getIndividualMetricsSummary(true);
+
+ $now = Date::now()->getLocalized("%longYear%, %shortMonth% %day%");
+ Option::set(DBStats::TIME_OF_LAST_TASK_RUN_OPTION, $now);
+ }
+} \ No newline at end of file
diff --git a/plugins/PrivacyManager/PrivacyManager.php b/plugins/PrivacyManager/PrivacyManager.php
index 8f0995fb50..edf0eba970 100644
--- a/plugins/PrivacyManager/PrivacyManager.php
+++ b/plugins/PrivacyManager/PrivacyManager.php
@@ -18,8 +18,6 @@ use Piwik\Option;
use Piwik\Period;
use Piwik\Period\Range;
use Piwik\Plugins\Goals\Archiver;
-use Piwik\ScheduledTask;
-use Piwik\ScheduledTime;
use Piwik\Site;
use Piwik\Tracker\GoalManager;
@@ -137,7 +135,6 @@ class PrivacyManager extends \Piwik\Plugin
{
return array(
'AssetManager.getJavaScriptFiles' => 'getJsFiles',
- 'TaskScheduler.getScheduledTasks' => 'getScheduledTasks',
'Tracker.setTrackerCacheGeneral' => 'setTrackerCacheGeneral',
'Tracker.isExcludedVisit' => array($this->dntChecker, 'checkHeaderInTracker'),
'Tracker.setVisitorIp' => array($this->ipAnonymizer, 'setVisitorIpAddress'),
@@ -150,22 +147,6 @@ class PrivacyManager extends \Piwik\Plugin
$cacheContent = $config->setTrackerCacheGeneral($cacheContent);
}
- public function getScheduledTasks(&$tasks)
- {
- // both tasks are low priority so they will execute after most others, but not lowest, so
- // they will execute before the optimize tables task
-
- $purgeReportDataTask = new ScheduledTask(
- $this, 'deleteReportData', null, ScheduledTime::factory('daily'), ScheduledTask::LOW_PRIORITY
- );
- $tasks[] = $purgeReportDataTask;
-
- $purgeLogDataTask = new ScheduledTask(
- $this, 'deleteLogData', null, ScheduledTime::factory('daily'), ScheduledTask::LOW_PRIORITY
- );
- $tasks[] = $purgeLogDataTask;
- }
-
public function getJsFiles(&$jsFiles)
{
$jsFiles[] = "plugins/PrivacyManager/javascripts/privacySettings.js";
diff --git a/plugins/PrivacyManager/Tasks.php b/plugins/PrivacyManager/Tasks.php
new file mode 100644
index 0000000000..9ed9cbcf3a
--- /dev/null
+++ b/plugins/PrivacyManager/Tasks.php
@@ -0,0 +1,30 @@
+<?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\PrivacyManager;
+
+class Tasks extends \Piwik\Plugin\Tasks
+{
+ public function schedule()
+ {
+ $this->daily('deleteReportData', null, self::LOW_PRIORITY);
+ $this->daily('deleteLogData', null, self::LOW_PRIORITY);
+ }
+
+ public function deleteReportData()
+ {
+ $privacyManager = new PrivacyManager();
+ $privacyManager->deleteReportData();
+ }
+
+ public function deleteLogData()
+ {
+ $privacyManager = new PrivacyManager();
+ $privacyManager->deleteLogData();
+ }
+} \ No newline at end of file
diff --git a/plugins/ScheduledReports/ScheduledReports.php b/plugins/ScheduledReports/ScheduledReports.php
index 8dce0524dc..8e1222d774 100644
--- a/plugins/ScheduledReports/ScheduledReports.php
+++ b/plugins/ScheduledReports/ScheduledReports.php
@@ -15,12 +15,9 @@ use Piwik\DbHelper;
use Piwik\Mail;
use Piwik\Piwik;
use Piwik\Plugins\MobileMessaging\MobileMessaging;
-use Piwik\Plugins\SegmentEditor\API as APISegmentEditor;
use Piwik\Plugins\UsersManager\API as APIUsersManager;
use Piwik\ReportRenderer;
-use Piwik\ScheduledTask;
use Piwik\ScheduledTime;
-use Piwik\Site;
use Piwik\View;
use Zend_Mime;
@@ -72,7 +69,6 @@ class ScheduledReports extends \Piwik\Plugin
public function getListHooksRegistered()
{
return array(
- 'TaskScheduler.getScheduledTasks' => 'getScheduledTasks',
'AssetManager.getJavaScriptFiles' => 'getJsFiles',
'MobileMessaging.deletePhoneNumber' => 'deletePhoneNumber',
'ScheduledReports.getReportParameters' => 'getReportParameters',
@@ -463,25 +459,6 @@ class ScheduledReports extends \Piwik\Plugin
return in_array($reportType, array_keys(self::$managedReportTypes));
}
- public function getScheduledTasks(&$tasks)
- {
- foreach (API::getInstance()->getReports() as $report) {
- if (!$report['deleted'] && $report['period'] != ScheduledTime::PERIOD_NEVER) {
-
- $timezone = Site::getTimezoneFor($report['idsite']);
-
- $schedule = ScheduledTime::getScheduledTimeForPeriod($report['period']);
- $schedule->setHour($report['hour']);
- $schedule->setTimezone($timezone);
- $tasks[] = new ScheduledTask (
- API::getInstance(),
- 'sendReport',
- $report['idreport'], $schedule
- );
- }
- }
- }
-
public function segmentUpdated($idSegment, $updatedSegment)
{
$reportsUsingSegment = API::getInstance()->getReports(false, false, false, false, $idSegment);
diff --git a/plugins/ScheduledReports/Tasks.php b/plugins/ScheduledReports/Tasks.php
new file mode 100644
index 0000000000..88c71aeea6
--- /dev/null
+++ b/plugins/ScheduledReports/Tasks.php
@@ -0,0 +1,31 @@
+<?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\ScheduledReports;
+
+use Piwik\ScheduledTime;
+use Piwik\Site;
+
+class Tasks extends \Piwik\Plugin\Tasks
+{
+ public function schedule()
+ {
+ foreach (API::getInstance()->getReports() as $report) {
+ if (!$report['deleted'] && $report['period'] != ScheduledTime::PERIOD_NEVER) {
+
+ $timezone = Site::getTimezoneFor($report['idsite']);
+
+ $schedule = ScheduledTime::getScheduledTimeForPeriod($report['period']);
+ $schedule->setHour($report['hour']);
+ $schedule->setTimezone($timezone);
+
+ $this->custom(API::getInstance(), 'sendReport', $report['idreport'], $schedule);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/UserCountry/Tasks.php b/plugins/UserCountry/Tasks.php
new file mode 100644
index 0000000000..414675fcdf
--- /dev/null
+++ b/plugins/UserCountry/Tasks.php
@@ -0,0 +1,20 @@
+<?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\UserCountry;
+
+class Tasks extends \Piwik\Plugin\Tasks
+{
+ public function schedule()
+ {
+ // add the auto updater task if GeoIP admin is enabled
+ if (UserCountry::isGeoLocationAdminEnabled()) {
+ $this->addScheduledTask(new GeoIPAutoUpdater());
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/UserCountry/UserCountry.php b/plugins/UserCountry/UserCountry.php
index fae65284ac..2299bcbb0f 100644
--- a/plugins/UserCountry/UserCountry.php
+++ b/plugins/UserCountry/UserCountry.php
@@ -45,7 +45,6 @@ class UserCountry extends \Piwik\Plugin
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
'AssetManager.getJavaScriptFiles' => 'getJsFiles',
'Tracker.newVisitorInformation' => 'enrichVisitWithLocation',
- 'TaskScheduler.getScheduledTasks' => 'getScheduledTasks',
'ViewDataTable.configure' => 'configureViewDataTable',
'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
'Tracker.setTrackerCacheGeneral' => 'setTrackerCacheGeneral',
@@ -64,14 +63,6 @@ class UserCountry extends \Piwik\Plugin
$cache['currentLocationProviderId'] = LocationProvider::getCurrentProviderId();
}
- public function getScheduledTasks(&$tasks)
- {
- // add the auto updater task if GeoIP admin is enabled
- if($this->isGeoLocationAdminEnabled()) {
- $tasks[] = new GeoIPAutoUpdater();
- }
- }
-
public function getStylesheetFiles(&$stylesheets)
{
$stylesheets[] = "plugins/UserCountry/stylesheets/userCountry.less";