diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-06-05 08:44:37 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-06-05 08:44:37 +0400 |
commit | 3e03b0a7ca4055b4f05be7d4ec7bcfaacf364eff (patch) | |
tree | 47afa18c0b671f38e17405078bdee156ad020058 /plugins | |
parent | 0ed11b178860844b97b967f6cfa1ffd12ab2eaab (diff) |
refs #5301 started to simplify scheduled tasks API while staying backwards compatible
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/CoreAdminHome/CoreAdminHome.php | 44 | ||||
-rw-r--r-- | plugins/CoreAdminHome/Tasks.php | 46 | ||||
-rw-r--r-- | plugins/CorePluginsAdmin/CorePluginsAdmin.php | 37 | ||||
-rw-r--r-- | plugins/CorePluginsAdmin/Tasks.php | 36 | ||||
-rw-r--r-- | plugins/CoreUpdater/CoreUpdater.php | 22 | ||||
-rw-r--r-- | plugins/CoreUpdater/Tasks.php | 25 | ||||
-rw-r--r-- | plugins/DBStats/DBStats.php | 36 | ||||
-rw-r--r-- | plugins/DBStats/Tasks.php | 34 | ||||
-rw-r--r-- | plugins/PrivacyManager/PrivacyManager.php | 19 | ||||
-rw-r--r-- | plugins/PrivacyManager/Tasks.php | 30 | ||||
-rw-r--r-- | plugins/ScheduledReports/ScheduledReports.php | 23 | ||||
-rw-r--r-- | plugins/ScheduledReports/Tasks.php | 31 | ||||
-rw-r--r-- | plugins/UserCountry/Tasks.php | 20 | ||||
-rw-r--r-- | plugins/UserCountry/UserCountry.php | 9 |
14 files changed, 223 insertions, 189 deletions
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"; |