/** * Tracker requests will automatically trigger the Scheduled tasks. * This is useful for users who don't setup the cron, * but still want daily/weekly/monthly PDF reports emailed automatically. * * This is similar to calling the API CoreAdminHome.runScheduledTasks */ public function runScheduledTasks() { $now = time(); // Currently, there are no hourly tasks. When there are some, // this could be too aggressive minimum interval (some hours would be skipped in case of low traffic) $minimumInterval = TrackerConfig::getConfigValue('scheduled_tasks_min_interval'); // If the user disabled browser archiving, he has already setup a cron // To avoid parallel requests triggering the Scheduled Tasks, // Get last time tasks started executing $cache = Cache::getCacheGeneral(); if ($minimumInterval <= 0 || empty($cache['isBrowserTriggerEnabled'])) { Common::printDebug("-> Scheduled tasks not running in Tracker: Browser archiving is disabled."); return; } $nextRunTime = $cache['lastTrackerCronRun'] + $minimumInterval; if (defined('DEBUG_FORCE_SCHEDULED_TASKS') && DEBUG_FORCE_SCHEDULED_TASKS || $cache['lastTrackerCronRun'] === false || $nextRunTime < $now) { $cache['lastTrackerCronRun'] = $now; Cache::setCacheGeneral($cache); Option::set('lastTrackerCronRun', $cache['lastTrackerCronRun']); Common::printDebug('-> Scheduled Tasks: Starting...'); $invokeScheduledTasksUrl = "?module=API&format=csv&convertToUnicode=0&method=CoreAdminHome.runScheduledTasks&trigger=archivephp"; $cliMulti = new CliMulti(); $cliMulti->runAsSuperUser(); $responses = $cliMulti->request(array($invokeScheduledTasksUrl)); $resultTasks = reset($responses); Common::printDebug($resultTasks); Common::printDebug('Finished Scheduled Tasks.'); } else { Common::printDebug("-> Scheduled tasks not triggered."); } Common::printDebug("Next run will be from: " . date('Y-m-d H:i:s', $nextRunTime) . ' UTC'); }
private function assertRequestReturnsValidResponses($urls, $expectedResponseIds) { $actualResponse = $this->cliMulti->request($urls); $this->assertInternalType('array', $actualResponse); $this->assertCount(count($expectedResponseIds), $actualResponse); $expected = array(); foreach ($expectedResponseIds as $expectedResponseId) { $expected[] = $this->responses[$expectedResponseId]; } $this->assertEquals($expected, $actualResponse); }
public function request(array $piwikUrls) { if (empty(FakeCliMulti::$specifiedResults)) { return parent::request($piwikUrls); } $results = array(); foreach ($piwikUrls as $url) { if ($url instanceof Request) { $url->start(); $url = (string) $url; } $results[] = $this->getSpecifiedResult($url); } return $results; }
/** * Issues a request to $url */ private function request($url) { $url = $this->piwikUrl . $url . self::APPEND_TO_API_REQUEST; if ($this->shouldStartProfiler) { $url .= "&xhprof=2"; } if ($this->testmode) { $url .= "&testmode=1"; } try { $cliMulti = new CliMulti(); $cliMulti->setAcceptInvalidSSLCertificate($this->acceptInvalidSSLCertificate); $responses = $cliMulti->request(array($url)); $response = !empty($responses) ? array_shift($responses) : null; } catch (Exception $e) { return $this->logNetworkError($url, $e->getMessage()); } if ($this->checkResponse($response, $url)) { return $response; } return false; }