diff options
author | mattab <matthieu.aubry@gmail.com> | 2013-11-11 13:10:40 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2013-11-11 13:10:40 +0400 |
commit | e0e83ef063827840e876642088e01e0e583f2adf (patch) | |
tree | b8d45e16f2cb8345eea718c15494762deaddb007 | |
parent | 8cc4127127f2a8f9e95642470cac2e870e1f0d1a (diff) |
Simplifying API for creating scheduled tasks, ScheduledTime objects now created via factory eg. ScheduledTime::factory('daily');
-rw-r--r-- | core/ScheduledTime.php | 29 | ||||
-rw-r--r-- | core/ScheduledTime/Daily.php | 3 | ||||
-rw-r--r-- | core/ScheduledTime/Hourly.php | 1 | ||||
-rw-r--r-- | core/ScheduledTime/Monthly.php | 1 | ||||
-rw-r--r-- | core/ScheduledTime/Weekly.php | 1 | ||||
-rw-r--r-- | plugins/CoreAdminHome/CoreAdminHome.php | 5 | ||||
-rw-r--r-- | plugins/CorePluginsAdmin/CorePluginsAdmin.php | 3 | ||||
-rw-r--r-- | plugins/DBStats/DBStats.php | 3 | ||||
-rw-r--r-- | plugins/PrivacyManager/PrivacyManager.php | 5 | ||||
-rw-r--r-- | tests/PHPUnit/Core/ScheduledTime/DailyTest.php | 6 | ||||
-rw-r--r-- | tests/PHPUnit/Core/TaskSchedulerTest.php | 2 | ||||
-rw-r--r-- | tests/PHPUnit/Plugins/ScheduledReportsTest.php | 2 |
12 files changed, 36 insertions, 25 deletions
diff --git a/core/ScheduledTime.php b/core/ScheduledTime.php index 3c345706f0..7bd09a9ae4 100644 --- a/core/ScheduledTime.php +++ b/core/ScheduledTime.php @@ -19,11 +19,12 @@ use Piwik\ScheduledTime\Weekly; /** * The ScheduledTime abstract class is used as a base class for different types of scheduling intervals. - * ScheduledTime subclasses are used to schedule tasks within Piwik. + * ScheduledTime::factory() is used to create a ScheduledTime object. * * @see \Piwik\ScheduledTask * @package Piwik * @subpackage ScheduledTime + * @api */ abstract class ScheduledTime { @@ -31,6 +32,7 @@ abstract class ScheduledTime const PERIOD_DAY = 'day'; const PERIOD_WEEK = 'week'; const PERIOD_MONTH = 'month'; + const PERIOD_HOUR = 'hour'; const PERIOD_YEAR = 'year'; const PERIOD_RANGE = 'range'; @@ -39,7 +41,7 @@ abstract class ScheduledTime * Defaults to midnight * @var integer */ - public $hour = 0; + protected $hour = 0; /** * For weekly scheduling : http://php.net/manual/en/function.date.php, format string : 'N', defaults to Monday @@ -47,12 +49,13 @@ abstract class ScheduledTime * month), defaults to first day of the month * @var integer */ - public $day = 1; + protected $day = 1; /** * @param $period * @return Daily|Monthly|Weekly * @throws \Exception + * @ignore */ static public function getScheduledTimeForPeriod($period) { @@ -63,6 +66,8 @@ abstract class ScheduledTime return new Weekly(); case self::PERIOD_DAY: return new Daily(); + case self::PERIOD_HOUR: + return new Hourly(); default: throw new Exception('period ' . $period . 'is undefined.'); @@ -85,6 +90,7 @@ abstract class ScheduledTime * * @abstract * @return integer Returns the rescheduled time measured in the number of seconds since the Unix Epoch + * @ignore */ abstract public function getRescheduledTime(); @@ -133,8 +139,7 @@ abstract class ScheduledTime * Returns a new ScheduledTime instance using a string description of the scheduled period type * and a string description of the day within the period to execute the task on. * - * @param string $periodType The scheduled period type. Can be `'hourly'`, `'daily'`, `'weekly'`, - * or `'monthly'`. + * @param string $periodType The scheduled period type. Can be `'hourly'`, `'daily'`, `'weekly'`, or `'monthly'`. * @param string|int|false $periodDay A string describing the day within the scheduled period to execute * the task on. Only valid for week and month periods. * @@ -154,14 +159,18 @@ abstract class ScheduledTime return new Daily(); case 'weekly': $result = new Weekly(); - $result->setDay($periodDay); + if($periodDay !== false) { + $result->setDay($periodDay); + } return $result; case 'monthly': $result = new Monthly($periodDay); - if (is_int($periodDay)) { - $result->setDay($periodDay); - } else { - $result->setDayOfWeekFromString($periodDay); + if($periodDay !== false) { + if (is_int($periodDay)) { + $result->setDay($periodDay); + } else { + $result->setDayOfWeekFromString($periodDay); + } } return $result; default: diff --git a/core/ScheduledTime/Daily.php b/core/ScheduledTime/Daily.php index 70c73200a0..b3b8df11a0 100644 --- a/core/ScheduledTime/Daily.php +++ b/core/ScheduledTime/Daily.php @@ -20,13 +20,13 @@ use Piwik\ScheduledTime; * @package Piwik * @subpackage ScheduledTime * - * @api */ class Daily extends ScheduledTime { /** * @see ScheduledTime::getRescheduledTime * @return int + * */ public function getRescheduledTime() { @@ -51,6 +51,7 @@ class Daily extends ScheduledTime * @see ScheduledTime::setDay * @param int $_day * @throws \Exception + * @ignore */ public function setDay($_day) { diff --git a/core/ScheduledTime/Hourly.php b/core/ScheduledTime/Hourly.php index 1474ce25ff..b1f0e9bb39 100644 --- a/core/ScheduledTime/Hourly.php +++ b/core/ScheduledTime/Hourly.php @@ -20,7 +20,6 @@ use Piwik\ScheduledTime; * @package Piwik * @subpackage ScheduledTime * - * @api */ class Hourly extends ScheduledTime { diff --git a/core/ScheduledTime/Monthly.php b/core/ScheduledTime/Monthly.php index b7a5d5c709..48954e7d42 100644 --- a/core/ScheduledTime/Monthly.php +++ b/core/ScheduledTime/Monthly.php @@ -20,7 +20,6 @@ use Piwik\ScheduledTime; * @package Piwik * @subpackage ScheduledTime * - * @api */ class Monthly extends ScheduledTime { diff --git a/core/ScheduledTime/Weekly.php b/core/ScheduledTime/Weekly.php index 7bb3fea50f..6bb1b56a66 100644 --- a/core/ScheduledTime/Weekly.php +++ b/core/ScheduledTime/Weekly.php @@ -20,7 +20,6 @@ use Piwik\ScheduledTime; * @package Piwik * @subpackage ScheduledTime * - * @api */ class Weekly extends ScheduledTime { diff --git a/plugins/CoreAdminHome/CoreAdminHome.php b/plugins/CoreAdminHome/CoreAdminHome.php index 280229238e..b26fe660ba 100644 --- a/plugins/CoreAdminHome/CoreAdminHome.php +++ b/plugins/CoreAdminHome/CoreAdminHome.php @@ -18,6 +18,7 @@ use Piwik\Menu\MenuAdmin; use Piwik\Piwik; use Piwik\ScheduledTask; use Piwik\ScheduledTime\Daily; +use Piwik\ScheduledTime; use Piwik\Settings\Manager as SettingsManager; use Piwik\Settings\UserSetting; @@ -52,7 +53,7 @@ class CoreAdminHome extends \Piwik\Plugin $purgeArchiveTablesTask = new ScheduledTask ($this, 'purgeOutdatedArchives', null, - new Daily(), + ScheduledTime::factory('daily'), ScheduledTask::HIGH_PRIORITY); $tasks[] = $purgeArchiveTablesTask; @@ -60,7 +61,7 @@ class CoreAdminHome extends \Piwik\Plugin $optimizeArchiveTableTask = new ScheduledTask ($this, 'optimizeArchiveTable', null, - new Daily(), + ScheduledTime::factory('daily'), ScheduledTask::LOWEST_PRIORITY); $tasks[] = $optimizeArchiveTableTask; } diff --git a/plugins/CorePluginsAdmin/CorePluginsAdmin.php b/plugins/CorePluginsAdmin/CorePluginsAdmin.php index e97ce1761f..03a62a6753 100644 --- a/plugins/CorePluginsAdmin/CorePluginsAdmin.php +++ b/plugins/CorePluginsAdmin/CorePluginsAdmin.php @@ -15,6 +15,7 @@ use Piwik\Menu\MenuAdmin; use Piwik\Piwik; use Piwik\ScheduledTask; use Piwik\ScheduledTime\Daily; +use Piwik\ScheduledTime; /** * @@ -45,7 +46,7 @@ class CorePluginsAdmin extends \Piwik\Plugin 'Piwik\Plugins\CorePluginsAdmin\MarketplaceApiClient', 'clearAllCacheEntries', null, - new Daily(), + ScheduledTime::factory('daily'), ScheduledTask::LOWEST_PRIORITY ); } diff --git a/plugins/DBStats/DBStats.php b/plugins/DBStats/DBStats.php index f32d07bce6..d82fd8e728 100644 --- a/plugins/DBStats/DBStats.php +++ b/plugins/DBStats/DBStats.php @@ -20,6 +20,7 @@ use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable; use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Pie; use Piwik\ScheduledTask; use Piwik\ScheduledTime\Weekly; +use Piwik\ScheduledTime; /** * @@ -60,7 +61,7 @@ class DBStats extends \Piwik\Plugin $this, 'cacheDataByArchiveNameReports', null, - new Weekly(), + ScheduledTime::factory('weekly'), ScheduledTask::LOWEST_PRIORITY ); $tasks[] = $cacheDataByArchiveNameReportsTask; diff --git a/plugins/PrivacyManager/PrivacyManager.php b/plugins/PrivacyManager/PrivacyManager.php index 8bb2040870..7685d3a460 100644 --- a/plugins/PrivacyManager/PrivacyManager.php +++ b/plugins/PrivacyManager/PrivacyManager.php @@ -26,6 +26,7 @@ use Piwik\Piwik; use Piwik\Plugins\Goals\Archiver; use Piwik\ScheduledTask; use Piwik\ScheduledTime\Daily; +use Piwik\ScheduledTime; use Piwik\Site; use Piwik\Tracker\GoalManager; @@ -141,12 +142,12 @@ class PrivacyManager extends \Piwik\Plugin // they will execute before the optimize tables task $purgeReportDataTask = new ScheduledTask( - $this, 'deleteReportData', null, new Daily(), ScheduledTask::LOW_PRIORITY + $this, 'deleteReportData', null, ScheduledTime::factory('daily'), ScheduledTask::LOW_PRIORITY ); $tasks[] = $purgeReportDataTask; $purgeLogDataTask = new ScheduledTask( - $this, 'deleteLogData', null, new Daily(), ScheduledTask::LOW_PRIORITY + $this, 'deleteLogData', null, ScheduledTime::factory('daily'), ScheduledTask::LOW_PRIORITY ); $tasks[] = $purgeLogDataTask; } diff --git a/tests/PHPUnit/Core/ScheduledTime/DailyTest.php b/tests/PHPUnit/Core/ScheduledTime/DailyTest.php index ae1dce887b..835c7f2562 100644 --- a/tests/PHPUnit/Core/ScheduledTime/DailyTest.php +++ b/tests/PHPUnit/Core/ScheduledTime/DailyTest.php @@ -32,7 +32,7 @@ class ScheduledTime_DailyTest extends PHPUnit_Framework_TestCase public function testSetHourScheduledTimeDailyNegative() { try { - $dailySchedule = new Daily(); + $dailySchedule = \Piwik\ScheduledTime::factory('daily'); $dailySchedule->setHour(-1); } catch (Exception $e) { @@ -48,7 +48,7 @@ class ScheduledTime_DailyTest extends PHPUnit_Framework_TestCase public function testSetHourScheduledTimeDailyOver24() { try { - $dailySchedule = new Daily(); + $dailySchedule = \Piwik\ScheduledTime::factory('daily'); $dailySchedule->setHour(25); } catch (Exception $e) { return; @@ -63,7 +63,7 @@ class ScheduledTime_DailyTest extends PHPUnit_Framework_TestCase public function testSetDayScheduledTimeDaily() { try { - $dailySchedule = new Daily(); + $dailySchedule = \Piwik\ScheduledTime::factory('daily'); $dailySchedule->setDay(1); } catch (Exception $e) { return; diff --git a/tests/PHPUnit/Core/TaskSchedulerTest.php b/tests/PHPUnit/Core/TaskSchedulerTest.php index 31b525acaa..8837bbcc91 100644 --- a/tests/PHPUnit/Core/TaskSchedulerTest.php +++ b/tests/PHPUnit/Core/TaskSchedulerTest.php @@ -177,7 +177,7 @@ class TaskSchedulerTest extends PHPUnit_Framework_TestCase $this->assertNotEmpty($executeTask->invoke( new TaskScheduler(), - new ScheduledTask ($mock, $methodName, $parameterValue, new Daily()) + new ScheduledTask ($mock, $methodName, $parameterValue, \Piwik\ScheduledTime::factory('daily')) )); } diff --git a/tests/PHPUnit/Plugins/ScheduledReportsTest.php b/tests/PHPUnit/Plugins/ScheduledReportsTest.php index bbf0b26730..8c5ffc79ea 100644 --- a/tests/PHPUnit/Plugins/ScheduledReportsTest.php +++ b/tests/PHPUnit/Plugins/ScheduledReportsTest.php @@ -355,7 +355,7 @@ class ScheduledReportsTest extends DatabaseTestCase ); // expected tasks - $scheduleTask1 = new Daily(); + $scheduleTask1 = ScheduledTime::factory('daily'); $scheduleTask1->setHour(23); // paris is UTC-1, period ends at 23h UTC $scheduleTask2 = new Monthly(); |