Пример #1
0
 /**
  * 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');
 }
Пример #2
0
 public function execute()
 {
     $label = $this->translator->translate('Installation_SystemCheckCronArchiveProcess');
     $comment = $this->translator->translate('Installation_SystemCheckCronArchiveProcessCLI') . ': ';
     $process = new CliMulti();
     if ($process->supportsAsync()) {
         $comment .= $this->translator->translate('General_Ok');
     } else {
         $comment .= $this->translator->translate('Installation_NotSupported') . ' ' . $this->translator->translate('Goals_Optional');
     }
     return array(DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_OK, $comment));
 }
Пример #3
0
 public function __construct($outputId)
 {
     if (!Filesystem::isValidFilename($outputId)) {
         throw new \Exception('The given output id has an invalid format');
     }
     $dir = CliMulti::getTmpPath();
     Filesystem::mkdir($dir);
     $this->tmpFile = $dir . '/' . $outputId . '.output';
 }
Пример #4
0
 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);
 }
Пример #5
0
 public function __construct($pid)
 {
     if (!Filesystem::isValidFilename($pid)) {
         throw new \Exception('The given pid has an invalid format');
     }
     $pidDir = CliMulti::getTmpPath();
     Filesystem::mkdir($pidDir);
     $this->isSupported = self::isSupported();
     $this->pidFile = $pidDir . '/' . $pid . '.pid';
     $this->timeCreation = time();
     $this->markAsNotStarted();
 }
Пример #6
0
 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;
 }
Пример #7
0
 /**
  * Get system information
  */
 public static function getSystemInformation()
 {
     global $piwik_minimumPHPVersion;
     $minimumMemoryLimit = Config::getInstance()->General['minimum_memory_limit'];
     $infos = array();
     $directoriesToCheck = array('/tmp/', '/tmp/assets/', '/tmp/cache/', '/tmp/climulti/', '/tmp/latest/', '/tmp/logs/', '/tmp/sessions/', '/tmp/tcpdf/', '/tmp/templates_c/');
     if (!DbHelper::isInstalled()) {
         // at install, need /config to be writable (so we can create config.ini.php)
         $directoriesToCheck[] = '/config/';
     }
     $infos['directories'] = Filechecks::checkDirectoriesWritable($directoriesToCheck);
     $infos['can_auto_update'] = Filechecks::canAutoUpdate();
     self::initServerFilesForSecurity();
     $infos['phpVersion_minimum'] = $piwik_minimumPHPVersion;
     $infos['phpVersion'] = PHP_VERSION;
     $infos['phpVersion_ok'] = self::isPhpVersionValid($infos['phpVersion']);
     // critical errors
     $extensions = @get_loaded_extensions();
     $needed_extensions = array('zlib', 'SPL', 'iconv', 'json', 'mbstring');
     // HHVM provides the required subset of Reflection but lists Reflections as missing
     if (!defined('HHVM_VERSION')) {
         $needed_extensions[] = 'Reflection';
     }
     $infos['needed_extensions'] = $needed_extensions;
     $infos['missing_extensions'] = array();
     foreach ($needed_extensions as $needed_extension) {
         if (!in_array($needed_extension, $extensions)) {
             $infos['missing_extensions'][] = $needed_extension;
         }
     }
     // Special case for mbstring
     if (!function_exists('mb_get_info') || (int) ini_get('mbstring.func_overload') != 0) {
         $infos['missing_extensions'][] = 'mbstring';
     }
     $infos['pdo_ok'] = false;
     if (in_array('PDO', $extensions)) {
         $infos['pdo_ok'] = true;
     }
     $infos['adapters'] = Adapter::getAdapters();
     $needed_functions = array('debug_backtrace', 'create_function', 'eval', 'gzcompress', 'gzuncompress', 'pack');
     $infos['needed_functions'] = $needed_functions;
     $infos['missing_functions'] = array();
     foreach ($needed_functions as $needed_function) {
         if (!self::functionExists($needed_function)) {
             $infos['missing_functions'][] = $needed_function;
         }
     }
     // warnings
     $desired_extensions = array('json', 'libxml', 'dom', 'SimpleXML');
     $infos['desired_extensions'] = $desired_extensions;
     $infos['missing_desired_extensions'] = array();
     foreach ($desired_extensions as $desired_extension) {
         if (!in_array($desired_extension, $extensions)) {
             $infos['missing_desired_extensions'][] = $desired_extension;
         }
     }
     $desired_functions = array('set_time_limit', 'mail', 'parse_ini_file', 'glob', 'gzopen');
     $infos['missing_desired_functions'] = array();
     foreach ($desired_functions as $desired_function) {
         if (!self::functionExists($desired_function)) {
             $infos['missing_desired_functions'][] = $desired_function;
         }
     }
     $sessionAutoStarted = (int) ini_get('session.auto_start');
     if ($sessionAutoStarted) {
         $infos['missing_desired_functions'][] = 'session.auto_start';
     }
     $desired_settings = array('session.auto_start');
     $infos['desired_functions'] = array_merge($desired_functions, $desired_settings);
     $infos['openurl'] = Http::getTransportMethod();
     $infos['gd_ok'] = SettingsServer::isGdExtensionEnabled();
     $serverSoftware = isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '';
     $infos['serverVersion'] = addslashes($serverSoftware);
     $infos['serverOs'] = @php_uname();
     $infos['serverTime'] = date('H:i:s');
     $infos['memoryMinimum'] = $minimumMemoryLimit;
     $infos['memory_ok'] = true;
     $infos['memoryCurrent'] = '';
     $raised = SettingsServer::raiseMemoryLimitIfNecessary();
     if (($memoryValue = SettingsServer::getMemoryLimitValue()) > 0) {
         $infos['memoryCurrent'] = $memoryValue . 'M';
         $infos['memory_ok'] = $memoryValue >= $minimumMemoryLimit;
     }
     $infos['isWindows'] = SettingsServer::isWindows();
     $integrityInfo = Filechecks::getFileIntegrityInformation();
     $infos['integrity'] = $integrityInfo[0];
     $infos['integrityErrorMessages'] = array();
     if (isset($integrityInfo[1])) {
         if ($infos['integrity'] == false) {
             $infos['integrityErrorMessages'][] = Piwik::translate('General_FileIntegrityWarningExplanation');
         }
         $infos['integrityErrorMessages'] = array_merge($infos['integrityErrorMessages'], array_slice($integrityInfo, 1));
     }
     $infos['timezone'] = SettingsServer::isTimezoneSupportEnabled();
     $process = new CliMulti();
     $infos['cli_process_ok'] = $process->supportsAsync();
     $infos['tracker_status'] = Common::getRequestVar('trackerStatus', 0, 'int');
     // check if filesystem is NFS, if it is file based sessions won't work properly
     $infos['is_nfs'] = Filesystem::checkIfFileSystemIsNFS();
     $infos = self::enrichSystemChecks($infos);
     return $infos;
 }
Пример #8
0
 /**
  * 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;
 }