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 /plugins/GeoIp2 | |
parent | a99baa987892daae0c616fbaf52fa14e97e2f890 (diff) |
Allow customization of GeoIP2 database location using DI (#13913)
Diffstat (limited to 'plugins/GeoIp2')
-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 |
5 files changed, 12 insertions, 14 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'); } |