diff options
author | Stefan Giehl <stefan@matomo.org> | 2019-03-15 03:35:51 +0300 |
---|---|---|
committer | Thomas Steur <tsteur@users.noreply.github.com> | 2019-03-15 03:35:51 +0300 |
commit | 3474bf211f0119436c9439b1307bac601e673453 (patch) | |
tree | fc8ca51c401c472cc1e4e2c34f106812eaeef4ca | |
parent | a99baa987892daae0c616fbaf52fa14e97e2f890 (diff) |
Allow customization of GeoIP2 database location using DI (#13913)
-rw-r--r-- | plugins/GeoIp2/LocationProvider/GeoIp2.php | 5 | ||||
-rw-r--r-- | plugins/GeoIp2/config/config.php | 5 | ||||
-rw-r--r-- | plugins/GeoIp2/config/test.php | 5 | ||||
-rw-r--r-- | plugins/GeoIp2/tests/Integration/LocationProviderTest.php | 10 | ||||
-rw-r--r-- | plugins/GeoIp2/tests/System/ConvertRegionCodesToIsoTest.php | 1 | ||||
-rw-r--r-- | plugins/UserCountry/tests/Integration/APITest.php | 1 | ||||
-rw-r--r-- | tests/PHPUnit/Fixtures/ManySitesImportedLogs.php | 2 | ||||
-rw-r--r-- | tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php | 1 | ||||
-rw-r--r-- | tests/PHPUnit/Fixtures/UITestFixture.php | 1 | ||||
-rw-r--r-- | tests/PHPUnit/proxy/piwik.php | 2 |
10 files changed, 12 insertions, 21 deletions
diff --git a/plugins/GeoIp2/LocationProvider/GeoIp2.php b/plugins/GeoIp2/LocationProvider/GeoIp2.php index 8a7da913d2..6116b52c66 100644 --- a/plugins/GeoIp2/LocationProvider/GeoIp2.php +++ b/plugins/GeoIp2/LocationProvider/GeoIp2.php @@ -9,6 +9,7 @@ namespace Piwik\Plugins\GeoIp2\LocationProvider; use Exception; +use Piwik\Container\StaticContainer; use Piwik\Option; use Piwik\Piwik; use Piwik\Plugins\UserCountry\LocationProvider; @@ -23,8 +24,6 @@ abstract class GeoIp2 extends LocationProvider const TEST_IP = '194.57.91.215'; const SWITCH_TO_ISO_REGIONS_OPTION_NAME = 'usercountry.switchtoisoregions'; - public static $geoIPDatabaseDir = 'misc'; - /** * Cached region name array. Data is from geoipregionvars.php. * @@ -125,7 +124,7 @@ abstract class GeoIp2 extends LocationProvider */ public static function getPathForGeoIpDatabase($filename) { - return PIWIK_INCLUDE_PATH . '/' . self::$geoIPDatabaseDir . '/' . $filename; + return StaticContainer::get('path.geoip2') . $filename; } /** diff --git a/plugins/GeoIp2/config/config.php b/plugins/GeoIp2/config/config.php new file mode 100644 index 0000000000..54b0797861 --- /dev/null +++ b/plugins/GeoIp2/config/config.php @@ -0,0 +1,5 @@ +<?php + +return [ + 'path.geoip2' => DI\string('{path.root}/misc/'), +];
\ No newline at end of file diff --git a/plugins/GeoIp2/config/test.php b/plugins/GeoIp2/config/test.php new file mode 100644 index 0000000000..c45c66093f --- /dev/null +++ b/plugins/GeoIp2/config/test.php @@ -0,0 +1,5 @@ +<?php + +return [ + 'path.geoip2' => DI\string('{path.root}/tests/lib/geoip-files/'), +];
\ No newline at end of file diff --git a/plugins/GeoIp2/tests/Integration/LocationProviderTest.php b/plugins/GeoIp2/tests/Integration/LocationProviderTest.php index 02150ddc81..a127f91bb3 100644 --- a/plugins/GeoIp2/tests/Integration/LocationProviderTest.php +++ b/plugins/GeoIp2/tests/Integration/LocationProviderTest.php @@ -17,8 +17,6 @@ class LocationProviderTest extends \PHPUnit_Framework_TestCase { public function testGeoIP2City() { - GeoIp2::$geoIPDatabaseDir = 'tests/lib/geoip-files'; - $locationProvider = new GeoIp2\Php(['loc' => ['GeoIP2-City.mmdb'], 'isp' => []]); $result = $locationProvider->getLocation(['ip' => '194.57.91.215']); @@ -38,8 +36,6 @@ class LocationProviderTest extends \PHPUnit_Framework_TestCase public function testGeoIP2Country() { - GeoIp2::$geoIPDatabaseDir = 'tests/lib/geoip-files'; - $locationProvider = new GeoIp2\Php(['loc' => ['GeoIP2-Country.mmdb'], 'isp' => []]); $result = $locationProvider->getLocation(['ip' => '194.57.91.215']); @@ -53,8 +49,6 @@ class LocationProviderTest extends \PHPUnit_Framework_TestCase public function testGeoIP2ASN() { - GeoIp2::$geoIPDatabaseDir = 'tests/lib/geoip-files'; - $locationProvider = new GeoIp2\Php(['loc' => [], 'isp' => ['GeoLite2-ASN.mmdb']]); $result = $locationProvider->getLocation(['ip' => '194.57.91.215']); @@ -66,8 +60,6 @@ class LocationProviderTest extends \PHPUnit_Framework_TestCase public function testGeoIP2ISP() { - GeoIp2::$geoIPDatabaseDir = 'tests/lib/geoip-files'; - $locationProvider = new GeoIp2\Php(['loc' => [], 'isp' => ['GeoIP2-ISP.mmdb']]); $result = $locationProvider->getLocation(['ip' => '194.57.91.215']); @@ -79,8 +71,6 @@ class LocationProviderTest extends \PHPUnit_Framework_TestCase public function testGeoIP2CityAndISP() { - GeoIp2::$geoIPDatabaseDir = 'tests/lib/geoip-files'; - $locationProvider = new GeoIp2\Php(['loc' => ['GeoIP2-City.mmdb'], 'isp' => ['GeoIP2-ISP.mmdb']]); $result = $locationProvider->getLocation(['ip' => '194.57.91.215']); diff --git a/plugins/GeoIp2/tests/System/ConvertRegionCodesToIsoTest.php b/plugins/GeoIp2/tests/System/ConvertRegionCodesToIsoTest.php index ba1909ed1f..66011b030b 100644 --- a/plugins/GeoIp2/tests/System/ConvertRegionCodesToIsoTest.php +++ b/plugins/GeoIp2/tests/System/ConvertRegionCodesToIsoTest.php @@ -38,7 +38,6 @@ class ConvertRegionCodesToIsoTest extends IntegrationTestCase self::$idSite = Fixture::createWebsite('2016-01-01'); Fixture::createSuperUser(true); - GeoIp2::$geoIPDatabaseDir = 'tests/lib/geoip-files'; LocationProvider::$providers = null; LocationProvider::setCurrentProvider('geoip2php'); } diff --git a/plugins/UserCountry/tests/Integration/APITest.php b/plugins/UserCountry/tests/Integration/APITest.php index 689f1e0867..99f8a03973 100644 --- a/plugins/UserCountry/tests/Integration/APITest.php +++ b/plugins/UserCountry/tests/Integration/APITest.php @@ -42,7 +42,6 @@ class APITest extends IntegrationTestCase public function test_setLocationProvider() { - GeoIp2::$geoIPDatabaseDir = 'tests/lib/geoip-files'; $locationProvider = GeoIp2\Php::ID; $this->api->setLocationProvider($locationProvider); $this->assertEquals($locationProvider, Common::getCurrentLocationProviderId()); diff --git a/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php b/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php index dab3691789..6b4fea8102 100644 --- a/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php +++ b/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php @@ -37,7 +37,6 @@ class ManySitesImportedLogs extends Fixture $this->setUpWebsitesAndGoals(); LocationProvider::$providers = null; - GeoIp2::$geoIPDatabaseDir = 'tests/lib/geoip-files'; LocationProvider::setCurrentProvider('geoip2php'); self::createSuperUser(); @@ -49,7 +48,6 @@ class ManySitesImportedLogs extends Fixture public function tearDown() { LocationProvider::$providers = null; - GeoIp2::$geoIPDatabaseDir = 'tests/lib/geoip-files'; ManyVisitsWithGeoIP::unsetLocationProvider(); } diff --git a/tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php b/tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php index ce31f20bd0..275f72a62d 100644 --- a/tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php +++ b/tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php @@ -245,7 +245,6 @@ class ManyVisitsWithGeoIP extends Fixture public function setLocationProvider($file) { GeoIp2::$dbNames['loc'] = array($file); - GeoIp2::$geoIPDatabaseDir = 'tests/lib/geoip-files'; LocationProvider::$providers = null; LocationProvider::setCurrentProvider(self::GEOIP_IMPL_TO_TEST); diff --git a/tests/PHPUnit/Fixtures/UITestFixture.php b/tests/PHPUnit/Fixtures/UITestFixture.php index 1c6c92b9bb..03d7a4696f 100644 --- a/tests/PHPUnit/Fixtures/UITestFixture.php +++ b/tests/PHPUnit/Fixtures/UITestFixture.php @@ -79,7 +79,6 @@ class UITestFixture extends SqlDump ); // for proper geolocation - GeoIp2::$geoIPDatabaseDir = 'tests/lib/geoip-files'; LocationProvider::setCurrentProvider(GeoIp2\Php::ID); IPAnonymizer::deactivate(); diff --git a/tests/PHPUnit/proxy/piwik.php b/tests/PHPUnit/proxy/piwik.php index 64df843390..8135659410 100644 --- a/tests/PHPUnit/proxy/piwik.php +++ b/tests/PHPUnit/proxy/piwik.php @@ -33,8 +33,6 @@ try { Environment::setGlobalEnvironmentManipulator(new TestingEnvironmentManipulator(new TestingEnvironmentVariables(), $globalObservers)); - \Piwik\Plugins\GeoIp2\LocationProvider\GeoIp2::$geoIPDatabaseDir = 'tests/lib/geoip-files'; - include PIWIK_INCLUDE_PATH . '/matomo.php'; } catch (Exception $ex) { echo "Unexpected error during tracking: " . $ex->getMessage() . "\n" . $ex->getTraceAsString() . "\n"; |