public function downloadFreeGeoIPDB()
{
$this->dieIfGeolocationAdminIsDisabled();
Piwik::checkUserHasSuperUserAccess();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$this->checkTokenInUrl();
Json::sendHeaderJSON();
$outputPath = GeoIp::getPathForGeoIpDatabase('GeoIPCity.dat') . '.gz';
try {
$result = Http::downloadChunk($url = GeoIp::GEO_LITE_URL, $outputPath, $continue = Common::getRequestVar('continue', true, 'int'));
// if the file is done
if ($result['current_size'] >= $result['expected_file_size']) {
GeoIPAutoUpdater::unzipDownloadedFile($outputPath, $unlink = true);
// setup the auto updater
GeoIPAutoUpdater::setUpdaterOptions(array('loc_db' => GeoIp::GEO_LITE_URL, 'period' => GeoIPAutoUpdater::SCHEDULE_PERIOD_MONTHLY));
// make sure to echo out the geoip updater management screen
$result['next_screen'] = $this->getGeoIpUpdaterManageScreen();
}
return json_encode($result);
} catch (Exception $ex) {
return json_encode(array('error' => $ex->getMessage()));
}
}
}