Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattab <matthieu.aubry@gmail.com>2013-10-01 03:15:05 +0400
committermattab <matthieu.aubry@gmail.com>2013-10-01 03:15:05 +0400
commit58233e38185173cfd7a44656c9560e2a95ede3aa (patch)
treed6a282ec7b880ae68fc802f38f69df1b5682f9e6
parentdb6add11e5ec204ca25722d245d23add63b0816c (diff)
Refs #4133 Fixing archive.php + Logger to work with new workflow
-rw-r--r--core/Config.php20
-rw-r--r--core/Log.php30
-rw-r--r--core/Session.php4
-rw-r--r--misc/cron/archive.php50
4 files changed, 76 insertions, 28 deletions
diff --git a/core/Config.php b/core/Config.php
index 5de5b87fac..3487357a30 100644
--- a/core/Config.php
+++ b/core/Config.php
@@ -80,8 +80,7 @@ class Config
*/
protected function __construct()
{
- $this->pathGlobal = self::getGlobalConfigPath();
- $this->pathLocal = self::getLocalConfigPath();
+ $this->clear();
}
/**
@@ -214,6 +213,7 @@ class Config
$this->pathGlobal = self::getGlobalConfigPath();
$this->pathLocal = self::getLocalConfigPath();
+
}
/**
@@ -223,8 +223,9 @@ class Config
*/
public function init()
{
+ $this->clear();
$this->initialized = true;
- $reportError = empty($GLOBALS['PIWIK_TRACKER_MODE']);
+ $reportError = !empty($GLOBALS['PIWIK_TRACKER_MODE']);
// read defaults from global.ini.php
if (!is_readable($this->pathGlobal) && $reportError) {
@@ -236,17 +237,22 @@ class Config
Piwik_ExitWithMessage(Piwik_TranslateException('General_ExceptionUnreadableFileDisabledMethod', array($this->pathGlobal, "parse_ini_file()")));
}
- // read the local settings from config.ini.php
- if (!is_readable($this->pathLocal) && $reportError) {
- throw new Exception(Piwik_TranslateException('General_ExceptionConfigurationFileNotFound', array($this->pathLocal)));
+ if($reportError) {
+ $this->checkLocalConfigFound();
}
-
$this->configLocal = _parse_ini_file($this->pathLocal, true);
if (empty($this->configLocal) && $reportError) {
Piwik_ExitWithMessage(Piwik_TranslateException('General_ExceptionUnreadableFileDisabledMethod', array($this->pathLocal, "parse_ini_file()")));
}
}
+ public function checkLocalConfigFound()
+ {
+ if (!is_readable($this->pathLocal)) {
+ throw new Exception(Piwik_TranslateException('General_ExceptionConfigurationFileNotFound', array($this->pathLocal)));
+ }
+ }
+
/**
* Decode HTML entities
*
diff --git a/core/Log.php b/core/Log.php
index 8b9dc0d779..050b36a2cf 100644
--- a/core/Log.php
+++ b/core/Log.php
@@ -133,7 +133,7 @@ class Log
*
* @var string
*/
- private $logMessageFormat = "[%tag%:%datetime%] %message%";
+ private $logMessageFormat = "[%tag%%datetime%] %message%";
/**
* If we're logging to a file, this is the path to the file to log to.
@@ -236,6 +236,7 @@ class Log
*/
public function formatMessage($level, $tag, $datetime, $message)
{
+ $tag = $tag ? $tag . ':' : '';
return str_replace(
array("%tag%", "%message%", "%datetime%", "%level%"),
array($tag, $message, $datetime, $this->getStringLevel($level)),
@@ -264,7 +265,7 @@ class Log
private function setCurrentLogLevelFromConfig($logConfig)
{
if (!empty($logConfig[self::LOG_LEVEL_CONFIG_OPTION])) {
- $logLevel = $this->getLogLevelFromStringName(self::LOG_LEVEL_CONFIG_OPTION);
+ $logLevel = $this->getLogLevelFromStringName($logConfig[self::LOG_LEVEL_CONFIG_OPTION]);
if ($logLevel >= self::NONE // sanity check
&& $logLevel <= self::VERBOSE
@@ -287,11 +288,12 @@ class Log
if ($logPath[0] != '/' && $logPath[0] != DIRECTORY_SEPARATOR) {
$logPath = PIWIK_USER_PATH . '/' . $logPath;
}
+
+ $logPath = SettingsPiwik::rewriteTmpPathWithHostname($logPath);
if (is_dir($logPath)) {
$logPath .= '/piwik.log';
}
-
- $this->logToFilePath = SettingsPiwik::rewriteTmpPathWithHostname($logPath);
+ $this->logToFilePath = $logPath;
}
private function createWriterByName($writerName)
@@ -324,9 +326,20 @@ class Log
private function logToScreen($level, $tag, $datetime, $message)
{
+ static $currentRequestKey;
+ if(empty($currentRequestKey)) {
+ $currentRequestKey = substr(Common::generateUniqId(), 0, 5);
+ }
+
if (is_string($message)) {
- $message = Common::sanitizeInputValue($this->formatMessage($level, $tag, $datetime, $message));
- $message = '<pre>' . $message . '</pre>';
+ $message = '[' . $currentRequestKey . '] ' . $message;
+ $message = $this->formatMessage($level, $tag, $datetime, $message);
+
+ if(!Common::isPhpCliMode()) {
+ $message = Common::sanitizeInputValue($message);
+ $message = '<pre>' . $message . '</pre>';
+ }
+
} else {
Piwik_PostEvent(self::FORMAT_SCREEN_MESSAGE_EVENT, array(&$message, $level, $tag, $datetime, $this));
}
@@ -425,7 +438,8 @@ class Log
private function getLogLevelFromStringName($name)
{
- switch (strtoupper($name)) {
+ $name = strtoupper($name);
+ switch ($name) {
case 'NONE':
return self::NONE;
case 'ERROR':
@@ -461,6 +475,8 @@ class Log
foreach ($backtrace as $tracepoint) {
if (isset($tracepoint['class'])
&& $tracepoint['class'] != "Piwik\\Log"
+ && $tracepoint['class'] != "Piwik\\Piwik"
+ && $tracepoint['class'] != "CronArchive"
) {
return $tracepoint['class'];
}
diff --git a/core/Session.php b/core/Session.php
index 5f3c765a7a..fd17a48e59 100644
--- a/core/Session.php
+++ b/core/Session.php
@@ -148,7 +148,7 @@ class Session extends Zend_Session
*/
public static function getSessionsDirectory()
{
- //tmp
- return PIWIK_USER_PATH . '/tmp/sessions';
+ $path = PIWIK_USER_PATH . '/tmp/sessions';
+ return SettingsPiwik::rewriteTmpPathWithHostname($path);
}
}
diff --git a/misc/cron/archive.php b/misc/cron/archive.php
index cd1747280e..40eb2ba1d2 100644
--- a/misc/cron/archive.php
+++ b/misc/cron/archive.php
@@ -44,6 +44,7 @@ Notes:
* If you use Piwik to track dozens/hundreds of websites, please let the team know at hello@piwik.org
it makes us happy to learn successful user stories :)
* Enjoy!
+
";
/*
Ideas for improvements:
@@ -117,12 +118,12 @@ class CronArchive
public function init()
{
+ $this->displayHelp();
$this->initPiwikHost();
+ $this->initLog();
$this->initCore();
$this->initTokenAuth();
$this->initCheckCli();
- $this->initLog();
- $this->displayHelp();
$this->initStateFromParameters();
Piwik::setUserIsSuperUser(true);
@@ -159,6 +160,7 @@ class CronArchive
$this->initWebsitesToProcess();
flush();
+
}
/**
@@ -554,7 +556,11 @@ class CronArchive
private function log($m)
{
$this->output .= $m . "\n";
- Piwik::log($m);
+ try {
+ Piwik::log($m);
+ } catch(Exception $e) {
+ print($m . "\n");
+ }
}
/**
@@ -599,11 +605,10 @@ class CronArchive
{
$this->logError($m);
$fe = fopen('php://stderr', 'w');
- fwrite($fe, "Error in the last Piwik archive.php run: \n" . $m
+ fwrite($fe, "Error in the last Piwik archive.php run: \n" . $m . "\n"
. ($backtrace ? "\n\n Here is the full errors output:\n\n" . $this->output : '')
);
- trigger_error($m, E_USER_ERROR);
- exit;
+ exit(1);
}
private function logNetworkError($url, $response)
@@ -624,7 +629,7 @@ class CronArchive
private function usage()
{
global $USAGE;
- $this->logLines($USAGE);
+ echo $USAGE;
}
private function logLines($t)
@@ -638,8 +643,8 @@ class CronArchive
{
$config = Config::getInstance();
$config->log['log_only_when_debug_parameter'] = 0;
- $config->log['logger_writers'] = array("screen");
- $config->log['log_level'] = 'INFO';
+ $config->log[\Piwik\Log::LOG_WRITERS_CONFIG_OPTION] = array("screen");
+ $config->log[\Piwik\Log::LOG_LEVEL_CONFIG_OPTION] = 'VERBOSE';
if (!function_exists("curl_multi_init")) {
$this->log("ERROR: this script requires curl extension php_curl enabled in your CLI php.ini");
@@ -683,6 +688,7 @@ class CronArchive
private function displayHelp()
{
$displayHelp = $this->isParameterSet('help') || $this->isParameterSet('h');
+
if ($displayHelp) {
$this->usage();
exit;
@@ -833,9 +839,7 @@ class CronArchive
}
}
- // HOST is required for the Config object
- $parsed = parse_url($piwikUrl);
- Url::setHost($parsed['host']);
+ $this->initConfigObject($piwikUrl);
if (Config::getInstance()->General['force_ssl'] == 1) {
$piwikUrl = str_replace('http://', 'https://', $piwikUrl);
@@ -843,6 +847,28 @@ class CronArchive
$this->piwikUrl = $piwikUrl . "index.php";
}
+ /**
+ * Config file must be found for the script to run
+ *
+ * @param $piwikUrl
+ * @throws Exception
+ */
+ protected function initConfigObject($piwikUrl)
+ {
+ // HOST is required for the Config object
+ $parsed = parse_url($piwikUrl);
+ Url::setHost($parsed['host']);
+
+ Config::getInstance()->clear();
+
+ try {
+ Config::getInstance()->checkLocalConfigFound();
+ } catch (Exception $e) {
+ throw new Exception("The configuration file for Piwik could not be found. " .
+ "Please check that config/config.ini.php is readable by the user " .
+ get_current_user());
+ }
+ }
/**
* Returns if the requested parameter is defined in the command line arguments.