diff options
Diffstat (limited to 'plugins/GeoIp2/GeoIP2AutoUpdater.php')
-rw-r--r-- | plugins/GeoIp2/GeoIP2AutoUpdater.php | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/plugins/GeoIp2/GeoIP2AutoUpdater.php b/plugins/GeoIp2/GeoIP2AutoUpdater.php index 423256be83..dcc79dfdbd 100644 --- a/plugins/GeoIp2/GeoIP2AutoUpdater.php +++ b/plugins/GeoIp2/GeoIP2AutoUpdater.php @@ -11,6 +11,7 @@ namespace Piwik\Plugins\GeoIp2; require_once PIWIK_INCLUDE_PATH . "/core/ScheduledTask.php"; // for the tracker which doesn't include this file use Exception; +use GeoIp2\Database\Reader; use Piwik\Common; use Piwik\Container\StaticContainer; use Piwik\Date; @@ -21,7 +22,6 @@ use Piwik\Option; use Piwik\Piwik; use Piwik\Plugins\GeoIp2\LocationProvider\GeoIp2 AS LocationProviderGeoIp2; use Piwik\Plugins\GeoIp2\LocationProvider\GeoIp2\Php; -use Piwik\Plugins\UserCountry\GeoIPAutoUpdater; use Piwik\Scheduler\Scheduler; use Piwik\Scheduler\Task; use Piwik\Scheduler\Timetable; @@ -200,7 +200,7 @@ class GeoIP2AutoUpdater extends Task $content = $unzip->listContent(); if (empty($content)) { - throw new Exception(Piwik::translate('UserCountry_CannotListContent', + throw new Exception(Piwik::translate('GeoIp2_CannotListContent', array("'$path'", $unzip->errorInfo()))); } @@ -253,7 +253,7 @@ class GeoIP2AutoUpdater extends Task $success = $unzip->extract($outputPath); if ($success !== true) { - throw new Exception(Piwik::translate('UserCountry_CannotUnzipDatFile', + throw new Exception(Piwik::translate('General_CannotUnzipFile', array("'$path'", $unzip->errorInfo()))); } @@ -263,7 +263,7 @@ class GeoIP2AutoUpdater extends Task } } else { $ext = end(explode(basename($path), '.', 2)); - throw new Exception(Piwik::translate('UserCountry_UnsupportedArchiveType', "'$ext'")); + throw new Exception(Piwik::translate('GeoIp2_UnsupportedArchiveType', "'$ext'")); } try { @@ -286,11 +286,11 @@ class GeoIP2AutoUpdater extends Task Log::info("GeoIP2AutoUpdater: Encountered exception when testing newly downloaded" . " GeoIP 2 database: %s", $e->getMessage()); - throw new Exception(Piwik::translate('UserCountry_ThisUrlIsNotAValidGeoIPDB')); + throw new Exception(Piwik::translate('GeoIp2_ThisUrlIsNotAValidGeoIPDB')); } if (empty($location)) { - throw new Exception(Piwik::translate('UserCountry_ThisUrlIsNotAValidGeoIPDB')); + throw new Exception(Piwik::translate('GeoIp2_ThisUrlIsNotAValidGeoIPDB')); } // delete the existing GeoIP database (if any) and rename the downloaded file @@ -403,7 +403,7 @@ class GeoIP2AutoUpdater extends Task && $period != self::SCHEDULE_PERIOD_WEEKLY ) { throw new Exception(Piwik::translate( - 'UserCountry_InvalidGeoIPUpdatePeriod', + 'GeoIp2_InvalidGeoIPUpdatePeriod', array("'$period'", "'" . self::SCHEDULE_PERIOD_MONTHLY . "', '" . self::SCHEDULE_PERIOD_WEEKLY . "'") )); } @@ -415,9 +415,6 @@ class GeoIP2AutoUpdater extends Task $scheduler->rescheduleTaskAndRunTomorrow(new GeoIP2AutoUpdater()); } - - // clear option for GeoIP as not needed if GeoIP2 is set up - GeoIPAutoUpdater::clearOptions(); } /** @@ -559,7 +556,7 @@ class GeoIP2AutoUpdater extends Task && $ext != 'gz' && $ext != 'mmdb.gz' ) { - throw new \Exception(Piwik::translate('UserCountry_UnsupportedArchiveType', "'$ext'")); + throw new \Exception(Piwik::translate('GeoIp2_UnsupportedArchiveType', "'$ext'")); } } @@ -592,9 +589,13 @@ class GeoIP2AutoUpdater extends Task // test the provider. on error, we rename the broken DB. try { + // check database directly, as location provider ignores invalid database errors + $pathToDb = LocationProviderGeoIp2::getPathToGeoIpDatabase($customNames); + $reader = new Reader($pathToDb); + $location = $provider->getLocation(array('ip' => LocationProviderGeoIp2::TEST_IP)); } catch (\Exception $e) { - if($logErrors) { + if ($logErrors) { Log::error("GeoIP2AutoUpdater: Encountered exception when performing redundant tests on GeoIP2 " . "%s database: %s", $type, $e->getMessage()); } |