From 23e77a0f8ccfcb128f9a22ad1b9c2a6715b50505 Mon Sep 17 00:00:00 2001 From: Fabian Becker Date: Fri, 1 Mar 2013 15:19:50 +0100 Subject: More code cleanup and better use of Piwik::log --- core/ArchiveProcessing.php | 14 +++++++++----- core/FrontController.php | 5 +---- core/Http.php | 5 ++--- core/PluginsManager.php | 10 +++++----- core/Session.php | 11 +++++++---- plugins/UserCountry/GeoIPAutoUpdater.php | 4 ++-- plugins/UserCountry/LocationProvider/GeoIp/Php.php | 2 +- 7 files changed, 27 insertions(+), 24 deletions(-) diff --git a/core/ArchiveProcessing.php b/core/ArchiveProcessing.php index b16bc343e7..586199a6cc 100644 --- a/core/ArchiveProcessing.php +++ b/core/ArchiveProcessing.php @@ -567,11 +567,15 @@ abstract class Piwik_ArchiveProcessing { $temporary = 'temporary archive'; } - Piwik::log("'" . $this->period->getLabel() . "'" - .", idSite = ". $this->idsite." ($temporary)" - .", segment = '". $this->getSegment()->getString()."'" - .", report = '". $this->getRequestedReport()."'" - .", UTC datetime [".$this->startDatetimeUTC." -> ".$this->endDatetimeUTC." ]..."); + Piwik::log(sprintf("'%s, idSite = %d (%s), segment '%s', report = '%s', UTC datetime [%s -> %s]", + $this->period->getLabel(), + $this->idSite, + $temporary, + $this->getSegment()->getString(), + $this->getRequestedReport(), + $this->startDatetimeUTC, + $this->endTimestampUTC + )); } /** diff --git a/core/FrontController.php b/core/FrontController.php index 411c13d428..055f4058aa 100644 --- a/core/FrontController.php +++ b/core/FrontController.php @@ -121,8 +121,7 @@ class Piwik_FrontController { $action = $controller->getDefaultAction(); } - -// Piwik::log("Dispatching $module / $action, parameters: ".var_export($parameters, $return = true)); + if( !is_callable(array($controller, $action))) { throw new Exception("Action '$action' not found in the controller '$controllerClassName'."); @@ -328,8 +327,6 @@ class Piwik_FrontController Piwik_ExitWithMessage($e->getMessage(), false, true); } - -// Piwik::log('End FrontController->init() - Request: '. var_export($_REQUEST, true)); } protected function handleMaintenanceMode() diff --git a/core/Http.php b/core/Http.php index 33f5b308c8..7e921d354d 100644 --- a/core/Http.php +++ b/core/Http.php @@ -636,7 +636,7 @@ class Piwik_Http if ($expectedFileSize == 0) { - Piwik::log("HEAD request for '$url' failed, got following: ".print_r($expectedFileSizeResult, true)); + Piwik::log(sprintf("HEAD request for '%s' failed, got following: %s", $url, print_r($expectedFileSizeResult, true))); throw new Exception(Piwik_Translate('General_DownloadFail_HttpRequestFail')); } @@ -647,8 +647,7 @@ class Piwik_Http $expectedFileSize = (int)Piwik_GetOption($downloadOption); if ($expectedFileSize === false) // sanity check { - throw new Exception( - "Trying to continue a download that never started?! That's not supposed to happen..."); + throw new Exception("Trying to continue a download that never started?! That's not supposed to happen..."); } } diff --git a/core/PluginsManager.php b/core/PluginsManager.php index 6d60ef2653..ae6980bf02 100644 --- a/core/PluginsManager.php +++ b/core/PluginsManager.php @@ -240,7 +240,7 @@ class Piwik_PluginsManager $existingPlugins = $this->readPluginsDirectory(); if( array_search($pluginName, $existingPlugins) === false) { - Piwik::log("Unable to find the plugin '$pluginName' in activatePlugin."); + Piwik::log(sprintf("Unable to find the plugin '%s' in activatePlugin.", $pluginName)); return; } @@ -423,19 +423,19 @@ class Piwik_PluginsManager { return $this->loadedPlugins[$pluginName]; } - $pluginFileName = $pluginName . '/' . $pluginName . '.php'; - $pluginClassName = 'Piwik_'.$pluginName; + $pluginFileName = sprintf("%s/%s.php", $pluginName, $pluginName); + $pluginClassName = sprintf('Piwik_%s', $pluginName); if( !Piwik_Common::isValidFilename($pluginName)) { - throw new Exception("The plugin filename '$pluginFileName' is not a valid filename"); + throw new Exception(sprintf("The plugin filename '%s' is not a valid filename", $pluginFileName)); } $path = PIWIK_INCLUDE_PATH . '/plugins/' . $pluginFileName; if(!file_exists($path)) { -// Piwik::log("Unable to load plugin '$pluginName' because '$path' couldn't be found."); + Piwik::log(sprintf("Unable to load plugin '%s' because '%s' couldn't be found.", $pluginName, $path)); return null; } diff --git a/core/Session.php b/core/Session.php index 119bbf6397..8f5f5912ab 100644 --- a/core/Session.php +++ b/core/Session.php @@ -129,10 +129,13 @@ class Piwik_Session extends Zend_Session we recommend that you enable database session storage."; } - $message = 'Error: ' . Piwik_Translate('General_ExceptionUnableToStartSession') - . ' ' .Piwik::getErrorMessageMissingPermissions(Piwik_Common::getPathToPiwikRoot() . '/tmp/sessions/') - . $enableDbSessions - . "\n
Debug: the original error was \n". $e->getMessage()."
"; + $message = sprintf("Error: %s %s %s\n
Debug: the original error was \n%s
", + Piwik_Translate('General_ExceptionUnableToStartSession'), + Piwik::getErrorMessageMissingPermissions(Piwik_Common::getPathToPiwikRoot() . '/tmp/sessions/'), + $enableDbSessions, + $e->getMessage() + ); + Piwik_ExitWithMessage($message); } } diff --git a/plugins/UserCountry/GeoIPAutoUpdater.php b/plugins/UserCountry/GeoIPAutoUpdater.php index 912425e998..1f29d8a1bb 100755 --- a/plugins/UserCountry/GeoIPAutoUpdater.php +++ b/plugins/UserCountry/GeoIPAutoUpdater.php @@ -112,7 +112,7 @@ class Piwik_UserCountry_GeoIPAutoUpdater . "'$zippedOutputPath'! (Unknown error)"); } - Piwik::log("Piwik_UserCountry_GeoIPAutoUpdater: successfully downloaded '$url'"); + Piwik::log(sprintf("Piwik_UserCountry_GeoIPAutoUpdater: successfully downloaded '%s'", $url)); try { @@ -124,7 +124,7 @@ class Piwik_UserCountry_GeoIPAutoUpdater . "downloading " . "'$url': ".$ex->getMessage()); } - Piwik::log("Piwik_UserCountry_GeoIPAutoUpdater: successfully updated GeoIP database '$url'"); + Piwik::log(sprintf("Piwik_UserCountry_GeoIPAutoUpdater: successfully updated GeoIP database '%s'", $url)); } /** diff --git a/plugins/UserCountry/LocationProvider/GeoIp/Php.php b/plugins/UserCountry/LocationProvider/GeoIp/Php.php index f12878344a..c2443822fd 100755 --- a/plugins/UserCountry/LocationProvider/GeoIp/Php.php +++ b/plugins/UserCountry/LocationProvider/GeoIp/Php.php @@ -133,7 +133,7 @@ class Piwik_UserCountry_LocationProvider_GeoIp_Php extends Piwik_UserCountry_Loc $result[self::COUNTRY_CODE_KEY] = geoip_country_code_by_addr($locationGeoIp, $ip); break; default: // unknown database type, log warning and fallback to country edition - Piwik::log("Found unrecognized database type: ".$locationGeoIp->databaseType); + Piwik::log(sprintf("Found unrecognized database type: %s", $locationGeoIp->databaseType)); $result[self::COUNTRY_CODE_KEY] = geoip_country_code_by_addr($locationGeoIp, $ip); break; -- cgit v1.2.3 From 78034b6e09479ac3266a3e1a185e706fe811cea8 Mon Sep 17 00:00:00 2001 From: Fabian Becker Date: Fri, 1 Mar 2013 20:29:19 +0100 Subject: Fix broken build. Didn't fail locally? --- core/ArchiveProcessing.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/ArchiveProcessing.php b/core/ArchiveProcessing.php index 586199a6cc..099b0824a5 100644 --- a/core/ArchiveProcessing.php +++ b/core/ArchiveProcessing.php @@ -569,7 +569,7 @@ abstract class Piwik_ArchiveProcessing } Piwik::log(sprintf("'%s, idSite = %d (%s), segment '%s', report = '%s', UTC datetime [%s -> %s]", $this->period->getLabel(), - $this->idSite, + $this->idsite, $temporary, $this->getSegment()->getString(), $this->getRequestedReport(), -- cgit v1.2.3 From 434a88024140c9b2f831fec3d0f8d7bff5a3f22e Mon Sep 17 00:00:00 2001 From: Fabian Becker Date: Fri, 1 Mar 2013 22:24:29 +0100 Subject: Enable colored output for phpunit --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b420cc6233..97d004a4a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ env: - TEST_SUITE=CoreTests - TEST_SUITE=IntegrationTests -script: phpunit --configuration phpunit.xml --testsuite $TEST_SUITE --coverage-text +script: phpunit --configuration phpunit.xml --testsuite $TEST_SUITE --coverage-text --colors before_script: - mysql -e 'create database piwik_test;' -- cgit v1.2.3