コード例 #1
0
ファイル: Common.php プロジェクト: nomoto-ubicast/piwik
 /**
  * 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 (see misc/cron/archive.sh)
  *
  * @param int  $now  Current timestamp
  */
 public static function runScheduledTasks($now)
 {
     // Currently, there is no hourly tasks. When there are some,
     // this could be too agressive minimum interval (some hours would be skipped in case of low traffic)
     $minimumInterval = Piwik_Config::getInstance()->Tracker['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 = Piwik_Common::getCacheGeneral();
     if ($minimumInterval <= 0 || empty($cache['isBrowserTriggerArchivingEnabled'])) {
         printDebug("-> Scheduled tasks not running in Tracker: Browser archiving is disabled.");
         return;
     }
     $nextRunTime = $cache['lastTrackerCronRun'] + $minimumInterval;
     if (isset($GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS']) && $GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS'] || $cache['lastTrackerCronRun'] === false || $nextRunTime < $now) {
         $cache['lastTrackerCronRun'] = $now;
         Piwik_Common::setCacheGeneral($cache);
         Piwik_Common::initCorePiwikInTrackerMode();
         Piwik_SetOption('lastTrackerCronRun', $cache['lastTrackerCronRun']);
         printDebug('-> Scheduled Tasks: Starting...');
         // save current user privilege and temporarily assume super user privilege
         $isSuperUser = Piwik::isUserIsSuperUser();
         // Scheduled tasks assume Super User is running
         Piwik::setUserIsSuperUser();
         // While each plugins should ensure that necessary languages are loaded,
         // we ensure English translations at least are loaded
         Piwik_Translate::getInstance()->loadEnglishTranslation();
         $resultTasks = Piwik_TaskScheduler::runTasks();
         // restore original user privilege
         Piwik::setUserIsSuperUser($isSuperUser);
         printDebug($resultTasks);
         printDebug('Finished Scheduled Tasks.');
     } else {
         printDebug("-> Scheduled tasks not triggered.");
     }
     printDebug("Next run will be from: " . date('Y-m-d H:i:s', $nextRunTime) . ' UTC');
 }