diff options
author | diosmosis <benaka.moorthi@gmail.com> | 2013-02-15 13:26:43 +0400 |
---|---|---|
committer | diosmosis <benaka.moorthi@gmail.com> | 2013-02-15 13:26:43 +0400 |
commit | 91098c7f1b817b5ca9442445bb4cdaca4185ab20 (patch) | |
tree | 58f560cf12864117ca20014505c95838c2740831 /plugins/UserCountry | |
parent | d8dd525cb28003343483118f8aaac18bee6d308b (diff) |
Refs #3456, only save one broken file when doing redundant checks & add unit test for checks.
Diffstat (limited to 'plugins/UserCountry')
-rwxr-xr-x | plugins/UserCountry/GeoIPAutoUpdater.php | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/plugins/UserCountry/GeoIPAutoUpdater.php b/plugins/UserCountry/GeoIPAutoUpdater.php index 562a47d315..912425e998 100755 --- a/plugins/UserCountry/GeoIPAutoUpdater.php +++ b/plugins/UserCountry/GeoIPAutoUpdater.php @@ -501,9 +501,11 @@ class Piwik_UserCountry_GeoIPAutoUpdater * This is a safety measure used to make sure tracking isn't affected if strange * update errors occur. * - * Databases are renamed to ${original}.broken.N where 'N' is a number. + * Databases are renamed to ${original}.broken . + * + * Note: method is protected for testability. */ - private function performRedundantDbChecks() + protected function performRedundantDbChecks() { $databaseTypes = array_keys(Piwik_UserCountry_LocationProvider_GeoIp::$dbNames); @@ -534,6 +536,11 @@ class Piwik_UserCountry_GeoIPAutoUpdater if ($oldPath !== false && $newPath !== false) { + if (file_exists($newPath)) + { + unlink($newPath); + } + rename($oldPath, $newPath); } } @@ -546,7 +553,7 @@ class Piwik_UserCountry_GeoIPAutoUpdater * @param array $possibleDbNames The possible names of the database. * @return array Array with two elements, the path to the existing database, and * the path to rename it to if it is broken. The second will end - * with something like .broken.N where N is a number. + * with something like .broken . */ private function getOldAndNewPathsForBrokenDb( $possibleDbNames ) { @@ -555,18 +562,7 @@ class Piwik_UserCountry_GeoIPAutoUpdater if ($pathToDb !== false) { - // 250 used as upper limit just for sanity (updating should not fail that much) - $brokenPath = false; - for ($i = 0; $i != 250; ++$i) - { - $brokenPath = $pathToDb.".broken.$i"; - if (!file_exists($brokenPath)) - { - break; - } - } - - $newPath = $brokenPath; + $newPath = $pathToDb.".broken"; } return array($pathToDb, $newPath); |