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;
 }
Esempio n. 2
0
 /**
  * Tests forbidden call to setDay on Daily
  */
 public function testSetDayScheduledTimeDaily()
 {
     try {
         $dailySchedule = \Piwik\ScheduledTime::factory('daily');
         $dailySchedule->setDay(1);
     } catch (Exception $e) {
         return;
     }
     $this->fail('Expected exception not raised');
 }
Esempio n. 3
0
 /**
  * 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');
     }
     $this->scheduleTask(new ScheduledTask($objectOrClassName, $methodName, $methodParameter, $time, $priority));
     return $time;
 }
Esempio n. 4
0
 /**
  * @group Plugins
  */
 public function testGetScheduledTasks()
 {
     // stub API to control getReports() return values
     $report1 = self::getDailyPDFReportData($this->idSite);
     $report1['idreport'] = 1;
     $report1['hour'] = 0;
     $report1['deleted'] = 0;
     $report2 = self::getMonthlyEmailReportData($this->idSite);
     $report2['idreport'] = 2;
     $report2['idsite'] = 2;
     $report2['hour'] = 0;
     $report2['deleted'] = 0;
     $report3 = self::getMonthlyEmailReportData($this->idSite);
     $report3['idreport'] = 3;
     $report3['deleted'] = 1;
     // should not be scheduled
     $report4 = self::getMonthlyEmailReportData($this->idSite);
     $report4['idreport'] = 4;
     $report4['idsite'] = 1;
     $report4['hour'] = 8;
     $report4['deleted'] = 0;
     $report5 = self::getMonthlyEmailReportData($this->idSite);
     $report5['idreport'] = 5;
     $report5['idsite'] = 2;
     $report5['hour'] = 8;
     $report5['deleted'] = 0;
     // test no exception is raised when a scheduled report is set to never send
     $report6 = self::getMonthlyEmailReportData($this->idSite);
     $report6['idreport'] = 6;
     $report6['period'] = ScheduledTime::PERIOD_NEVER;
     $report6['deleted'] = 0;
     $stubbedAPIScheduledReports = $this->getMock('\\Piwik\\Plugins\\ScheduledReports\\API', array('getReports', 'getInstance'), $arguments = array(), $mockClassName = '', $callOriginalConstructor = false);
     $stubbedAPIScheduledReports->expects($this->any())->method('getReports')->will($this->returnValue(array($report1, $report2, $report3, $report4, $report5, $report6)));
     \Piwik\Plugins\ScheduledReports\API::setSingletonInstance($stubbedAPIScheduledReports);
     // initialize sites 1 and 2
     Site::setSites(array(1 => array('timezone' => 'Europe/Paris'), 2 => array('timezone' => 'UTC-6.5')));
     // expected tasks
     $scheduleTask1 = ScheduledTime::factory('daily');
     $scheduleTask1->setHour(0);
     // paris is UTC-1, period ends at 23h UTC
     $scheduleTask1->setTimezone('Europe/Paris');
     $scheduleTask2 = new Monthly();
     $scheduleTask2->setHour(0);
     // site is UTC-6.5, period ends at 6h30 UTC, smallest resolution is hour
     $scheduleTask2->setTimezone('UTC-6.5');
     $scheduleTask3 = new Monthly();
     $scheduleTask3->setHour(8);
     // paris is UTC-1, configured to be sent at 8h
     $scheduleTask3->setTimezone('Europe/Paris');
     $scheduleTask4 = new Monthly();
     $scheduleTask4->setHour(8);
     // site is UTC-6.5, configured to be sent at 8h
     $scheduleTask4->setTimezone('UTC-6.5');
     $expectedTasks = array(new ScheduledTask(APIScheduledReports::getInstance(), 'sendReport', 1, $scheduleTask1), new ScheduledTask(APIScheduledReports::getInstance(), 'sendReport', 2, $scheduleTask2), new ScheduledTask(APIScheduledReports::getInstance(), 'sendReport', 4, $scheduleTask3), new ScheduledTask(APIScheduledReports::getInstance(), 'sendReport', 5, $scheduleTask4));
     $pdfReportPlugin = new Tasks();
     $pdfReportPlugin->schedule();
     $tasks = $pdfReportPlugin->getScheduledTasks();
     $this->assertEquals($expectedTasks, $tasks);
     \Piwik\Plugins\ScheduledReports\API::unsetInstance();
 }
Esempio n. 5
0
 /**
  * @group Core
  * 
  * @dataProvider executeTaskTestCases
  */
 public function testExecuteTask($methodName, $parameterValue)
 {
     // assert the scheduled method is executed once with the correct parameter
     $mock = $this->getMock('TaskSchedulerTest', array($methodName));
     $mock->expects($this->once())->method($methodName)->with($this->equalTo($parameterValue));
     $executeTask = new ReflectionMethod('\\Piwik\\TaskScheduler', 'executeTask');
     $executeTask->setAccessible(true);
     $this->assertNotEmpty($executeTask->invoke(new TaskScheduler(), new ScheduledTask($mock, $methodName, $parameterValue, \Piwik\ScheduledTime::factory('daily'))));
 }
 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;
 }
 /**
  * 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);
 }
Esempio n. 8
0
 /**
  * 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;
 }