diff options
author | mattab <matthieu.aubry@gmail.com> | 2014-02-05 06:27:41 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2014-02-05 06:27:41 +0400 |
commit | 51892f733341f20a433308d41646c72a0005b23e (patch) | |
tree | 394481f834848816368d21827c9c182a3c9efbeb | |
parent | e78d1a85f63bf6df1ef8931914018afc3b3a4b97 (diff) | |
parent | d9f08bdc401f7d8355fae91d27c2548669329d15 (diff) |
Merge remote-tracking branch 'origin/master'
-rw-r--r-- | core/CronArchive.php | 23 | ||||
-rw-r--r-- | core/FrontController.php | 4 | ||||
-rw-r--r-- | core/Tracker.php | 16 | ||||
-rw-r--r-- | core/Tracker/Db/Pdo/Mysql.php | 22 |
4 files changed, 57 insertions, 8 deletions
diff --git a/core/CronArchive.php b/core/CronArchive.php index 3f9011c5dd..a83fb2062c 100644 --- a/core/CronArchive.php +++ b/core/CronArchive.php @@ -157,6 +157,17 @@ Notes: } } + public function runScheduledTasksInTrackerMode() + { + $this->initPiwikHost(); + $this->initLog(); + $this->initCore(); + $this->initTokenAuth(); + $this->logInitInfo(); + $this->checkPiwikUrlIsValid(); + $this->runScheduledTasks(); + } + /** * Main function, runs archiving on all websites with new activity */ @@ -842,10 +853,14 @@ Notes: { // If archive.php run as a web cron, we use the current hostname+path if (!Common::isPhpCliMode()) { - // example.org/piwik/misc/cron/ - $piwikUrl = Common::sanitizeInputValue(Url::getCurrentUrlWithoutFileName()); - // example.org/piwik/ - $piwikUrl = $piwikUrl . "../../"; + if (!empty(self::$url)) { + $piwikUrl = self::$url; + } else { + // example.org/piwik/misc/cron/ + $piwikUrl = Common::sanitizeInputValue(Url::getCurrentUrlWithoutFileName()); + // example.org/piwik/ + $piwikUrl = $piwikUrl . "../../"; + } } else { // If archive.php run as CLI/shell we require the piwik url to be set $piwikUrl = $this->isParameterSet("url", true); diff --git a/core/FrontController.php b/core/FrontController.php index ff99452a94..08bcad19f8 100644 --- a/core/FrontController.php +++ b/core/FrontController.php @@ -163,7 +163,9 @@ class FrontController extends Singleton public function __destruct() { try { - if (class_exists('Piwik\\Profiler')) { + if (class_exists('Piwik\\Profiler') + && empty($GLOBALS['PIWIK_TRACKER_MODE'])) { + // in tracker mode Piwik\Tracker\Db\Pdo\Mysql does currently not implement profiling Profiler::displayDbProfileReport(); Profiler::printQueryCount(); Log::debug(Registry::get('timer')); diff --git a/core/Tracker.php b/core/Tracker.php index 311c6a68e7..46e1f68d36 100644 --- a/core/Tracker.php +++ b/core/Tracker.php @@ -299,13 +299,16 @@ class Tracker // To avoid parallel requests triggering the Scheduled Tasks, // Get last time tasks started executing $cache = Cache::getCacheGeneral(); + if ($minimumInterval <= 0 - || empty($cache['isBrowserTriggerArchivingEnabled']) + || empty($cache['isBrowserTriggerEnabled']) ) { Common::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 @@ -326,7 +329,13 @@ class Tracker // we ensure English translations at least are loaded Translate::loadEnglishTranslation(); - $resultTasks = TaskScheduler::runTasks(); + ob_start(); + CronArchive::$url = Common::sanitizeInputValue(Url::getCurrentUrlWithoutFileName()); + $cronArchive = new CronArchive(); + $cronArchive->runScheduledTasksInTrackerMode(); + + $resultTasks = ob_get_contents(); + ob_clean(); // restore original user privilege Piwik::setUserHasSuperUserAccess($isSuperUser); @@ -358,7 +367,7 @@ class Tracker $config = Config::getInstance(); try { - $db = Db::get(); + Db::get(); } catch (Exception $e) { Db::createDatabaseObject(); } @@ -532,6 +541,7 @@ class Tracker * - **dbname**: The name of the Piwik MySQL database. * - **port**: The MySQL database port to use. * - **adapter**: either `'PDO_MYSQL'` or `'MYSQLI'` + * - **type**: The MySQL engine to use, for instance 'InnoDB' */ Piwik::postEvent('Tracker.getDatabaseConfig', array(&$configDb)); diff --git a/core/Tracker/Db/Pdo/Mysql.php b/core/Tracker/Db/Pdo/Mysql.php index 1c7de0a87f..3a2e04abfd 100644 --- a/core/Tracker/Db/Pdo/Mysql.php +++ b/core/Tracker/Db/Pdo/Mysql.php @@ -119,6 +119,28 @@ class Mysql extends Db } /** + * Fetches the first column of all SQL result rows as an array. + * + * @param string $sql An SQL SELECT statement. + * @param mixed $bind Data to bind into SELECT placeholders. + * @throws \Piwik\Tracker\Db\DbException + * @return string + */ + public function fetchCol($sql, $bind = array()) + { + try { + $sth = $this->query($sql, $bind); + if ($sth === false) { + return false; + } + $result = $sth->fetchAll(PDO::FETCH_COLUMN, 0); + return $result; + } catch (PDOException $e) { + throw new DbException("Error query: " . $e->getMessage()); + } + } + + /** * Returns the first row of a query result, using optional bound parameters. * * @param string $query Query |