Skip to content

Commit

Permalink
#6622 Logger refactoring: updated the geoipUpdateRows.php script
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Dec 18, 2014
1 parent c9fac0a commit bebef28
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
17 changes: 13 additions & 4 deletions misc/others/cli-script-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
use Piwik\Config;

use Piwik\Container\StaticContainer;
use Piwik\FrontController;
use Symfony\Bridge\Monolog\Handler\ConsoleHandler;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;

error_reporting(E_ALL | E_NOTICE);

Expand All @@ -34,5 +37,11 @@
$GLOBALS['PIWIK_TRACKER_DEBUG'] = false;
define('PIWIK_ENABLE_DISPATCH', false);

Config::getInstance()->log['string_message_format'] = "%message%";
FrontController::getInstance()->init();
if (Piwik\Common::isPhpCliMode()) {
StaticContainer::setEnvironment('cli');
/** @var ConsoleHandler $consoleLogHandler */
$consoleLogHandler = StaticContainer::getContainer()->get('Symfony\Bridge\Monolog\Handler\ConsoleHandler');
$consoleLogHandler->setOutput(new ConsoleOutput());
}

FrontController::getInstance()->init();
28 changes: 12 additions & 16 deletions misc/others/geoipUpdateRows.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@
try {
Piwik::checkUserHasSuperUserAccess();
} catch (Exception $e) {
Log::error('[error] You must be logged in as Super User to run this script. Please login in to Piwik and refresh this page.');
Log::error('You must be logged in as Super User to run this script. Please login in to Piwik and refresh this page.');
exit;
}
}

Log::getInstance()->setLogLevel(Log::VERBOSE);
Log::getInstance()->addLogWriter('screen');

if (!Common::isPhpCliMode()) {
// the 'start' query param will be supplied by the AJAX requests, so if it's not there, the
// user is viewing the page in the browser.
Expand Down Expand Up @@ -105,18 +102,18 @@ function geoipUpdateError($message)
$provider = new Pecl();
if (!$provider->isAvailable()) {
if ($displayNotes) {
Log::info("[note] The GeoIP PECL extension is not installed.");
Log::info("The GeoIP PECL extension is not installed.");
}

$provider = null;
} else {
$workingOrError = $provider->isWorking();
if ($workingOrError !== true) {
if ($displayNotes) {
Log::info("[note] The GeoIP PECL extension is broken: $workingOrError");
Log::info("The GeoIP PECL extension is broken: $workingOrError");
}
if (Common::isPhpCliMode()) {
Log::info("[note] Make sure your command line PHP is configured to use the PECL extension.");
Log::info("Make sure your command line PHP is configured to use the PECL extension.");
}
$provider = null;
}
Expand All @@ -125,33 +122,33 @@ function geoipUpdateError($message)
// use php api if pecl extension cannot be used
if (is_null($provider)) {
if ($displayNotes) {
Log::info("[note] Falling back to PHP API. This may become too slow for you. If so, you can read this link on how to install the PECL extension: http://piwik.org/faq/how-to/#faq_164");
Log::info("Falling back to PHP API. This may become too slow for you. If so, you can read this link on how to install the PECL extension: http://piwik.org/faq/how-to/#faq_164");
}

$provider = new Php();
if (!$provider->isAvailable()) {
if ($displayNotes) {
Log::info("[note] The GeoIP PHP API is not available. This means you do not have a GeoIP location database in your ./misc directory. The database must be named either GeoIP.dat or GeoIPCity.dat based on the type of database it is.");
Log::info("The GeoIP PHP API is not available. This means you do not have a GeoIP location database in your ./misc directory. The database must be named either GeoIP.dat or GeoIPCity.dat based on the type of database it is.");
}
$provider = null;
} else {
$workingOrError = $provider->isWorking();
if ($workingOrError !== true) {
if ($displayNotes) {
Log::info("[note] The GeoIP PHP API is broken: $workingOrError");
Log::info("The GeoIP PHP API is broken: $workingOrError");
}
$provider = null;
}
}
}

if (is_null($provider)) {
geoipUpdateError("\n[error] There is no location provider that can be used with this script. Only the GeoIP PECL module or the GeoIP PHP API can be used at present. Please install and configure one of these first.");
geoipUpdateError("There is no location provider that can be used with this script. Only the GeoIP PECL module or the GeoIP PHP API can be used at present. Please install and configure one of these first.");
}

$info = $provider->getInfo();
if ($displayNotes) {
Log::info("[note] Found working provider: {$info['id']}");
Log::info("Found working provider: {$info['id']}");
}

// perform update
Expand All @@ -162,7 +159,7 @@ function geoipUpdateError($message)
'location_longitude' => LocationProvider::LONGITUDE_KEY);

if ($displayNotes) {
Log::info("\n$count rows to process in " . Common::prefixTable('log_visit')
Log::info("$count rows to process in " . Common::prefixTable('log_visit')
. " and " . Common::prefixTable('log_conversion') . "...");
}
flush();
Expand Down Expand Up @@ -230,6 +227,5 @@ function geoipUpdateError($message)
}
if ($start >= $count) {
Log::info("100% done!");
Log::info("");
Log::info("[note] Now that you've geolocated your old visits, you need to force your reports to be re-processed. See this FAQ entry: http://piwik.org/faq/how-to/#faq_59");
}
Log::info("Now that you've geolocated your old visits, you need to force your reports to be re-processed. See this FAQ entry: http://piwik.org/faq/how-to/#faq_59");
}

0 comments on commit bebef28

Please sign in to comment.