Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <tsteur@users.noreply.github.com>2019-05-13 11:46:11 +0300
committerGitHub <noreply@github.com>2019-05-13 11:46:11 +0300
commitaccdec4ab34ece7b4a0aa3c34055fdaafd4fde08 (patch)
treeaacac0d028ceb739295df3c7e6685be4060e9bd3 /plugins
parent1b2ee7fc984580d57ab63fde61843a3974016149 (diff)
Copy geoip archive into temporary folder instead of in the geoip folder (#14380)
* Copy geoip archive into temporary folder instead of in the geoip folder I noticed the geoip tar.gz archive is downloaded and extracted into the `misc` directory or whatever is configured eg through ` 'path.geoip2' => DI\string('{path.root}/misc/geoip/'),`. However, only the `misc/GeoLite2-City.mmdb` might have write access but not any other file. This causes the updating of the geodb to fail. Instead, it should be extracted into the `tmp/latest` folder which we use for such cases (eg matomo update, plugin update, ...) * If a path is given, load the DB from that path directly * Update Php.php * ignore error if unlink fails * move file check to getPathForGeoIpDatabase
Diffstat (limited to 'plugins')
-rw-r--r--plugins/GeoIp2/GeoIP2AutoUpdater.php17
-rw-r--r--plugins/GeoIp2/LocationProvider/GeoIp2.php4
2 files changed, 15 insertions, 6 deletions
diff --git a/plugins/GeoIp2/GeoIP2AutoUpdater.php b/plugins/GeoIp2/GeoIP2AutoUpdater.php
index 056b5f7988..9e2fe00f81 100644
--- a/plugins/GeoIp2/GeoIP2AutoUpdater.php
+++ b/plugins/GeoIp2/GeoIP2AutoUpdater.php
@@ -129,7 +129,7 @@ class GeoIP2AutoUpdater extends Task
// NOTE: using the first item in $dbNames[$dbType] makes sure GeoLiteCity will be renamed to GeoIPCity
$zippedFilename = LocationProviderGeoIp2::$dbNames[$dbType][0] . '.' . $ext;
- $zippedOutputPath = LocationProviderGeoIp2::getPathForGeoIpDatabase($zippedFilename);
+ $zippedOutputPath = self::getTemporaryFolder($zippedFilename);
$url = self::removeDateFromUrl($url);
@@ -158,6 +158,11 @@ class GeoIP2AutoUpdater extends Task
Log::info("GeoIP2AutoUpdater: successfully updated GeoIP 2 database '%s'", $url);
}
+ protected static function getTemporaryFolder($file)
+ {
+ return \Piwik\Container\StaticContainer::get('path.tmp') . '/latest/' . $file;
+ }
+
/**
* Unzips a downloaded GeoIP 2 database. Only unzips .gz & .tar.gz files.
*
@@ -201,7 +206,7 @@ class GeoIP2AutoUpdater extends Task
$dbFilename = basename($fileToExtract);
$tempFilename = $dbFilename . '.new';
- $outputPath = LocationProviderGeoIp2::getPathForGeoIpDatabase($tempFilename);
+ $outputPath = self::getTemporaryFolder($tempFilename);
// write unzipped to file
$fd = fopen($outputPath, 'wb');
@@ -212,7 +217,7 @@ class GeoIP2AutoUpdater extends Task
$dbFilename = basename($path);
$tempFilename = $dbFilename . '.new';
- $outputPath = LocationProviderGeoIp2::getPathForGeoIpDatabase($tempFilename);
+ $outputPath = self::getTemporaryFolder($tempFilename);
$success = $unzip->extract($outputPath);
@@ -235,7 +240,7 @@ class GeoIP2AutoUpdater extends Task
'loc' => array(),
'isp' => array()
);
- $customDbNames[$dbType] = array($tempFilename);
+ $customDbNames[$dbType] = array($outputPath);
$phpProvider = new Php($customDbNames);
@@ -255,10 +260,10 @@ class GeoIP2AutoUpdater extends Task
// delete the existing GeoIP database (if any) and rename the downloaded file
$oldDbFile = LocationProviderGeoIp2::getPathForGeoIpDatabase($dbFilename);
if (file_exists($oldDbFile)) {
- unlink($oldDbFile);
+ @unlink($oldDbFile);
}
- $tempFile = LocationProviderGeoIp2::getPathForGeoIpDatabase($tempFilename);
+ $tempFile = self::getTemporaryFolder($tempFilename);
if (@rename($tempFile, $oldDbFile) !== true) {
//In case the $tempfile cannot be renamed, we copy the file.
copy($tempFile, $oldDbFile);
diff --git a/plugins/GeoIp2/LocationProvider/GeoIp2.php b/plugins/GeoIp2/LocationProvider/GeoIp2.php
index 6116b52c66..6258a8cb9d 100644
--- a/plugins/GeoIp2/LocationProvider/GeoIp2.php
+++ b/plugins/GeoIp2/LocationProvider/GeoIp2.php
@@ -124,6 +124,10 @@ abstract class GeoIp2 extends LocationProvider
*/
public static function getPathForGeoIpDatabase($filename)
{
+ if (strpos($filename, '/') !== false && file_exists($filename)) {
+ return $filename;
+ }
+
return StaticContainer::get('path.geoip2') . $filename;
}