original_string: public function downloadMissingGeoIpDb()
      {
          $this->dieIfGeolocationAdminIsDisabled();
          Piwik::checkUserHasSuperUserAccess();
          if ($_SERVER["REQUEST_METHOD"] == "POST") {
              try {
                  $this->checkTokenInUrl();
  
                  Json::sendHeaderJSON();
  
                  // based on the database type (provided by the 'key' query param) determine the
                  // url & output file name
                  $key = Common::getRequestVar('key', null, 'string');
  
                  if ($this->isGeoIp2Enabled()) {
                      $url = GeoIP2AutoUpdater::getConfiguredUrl($key);
                      $ext = GeoIP2AutoUpdater::getGeoIPUrlExtension($url);
                      $filename = GeoIp2::$dbNames[$key][0] . '.' . $ext;
                      $outputPath = GeoIp2::getPathForGeoIpDatabase($filename);
                  } else {
                      $url = GeoIPAutoUpdater::getConfiguredUrl($key);
                      $ext = GeoIPAutoUpdater::getGeoIPUrlExtension($url);
                      $filename = GeoIp::$dbNames[$key][0] . '.' . $ext;
  
                      if (substr($filename, 0, 15) == 'GeoLiteCity.dat') {
                          $filename = 'GeoIPCity.dat' . substr($filename, 15);
                      }
                      $outputPath = GeoIp::getPathForGeoIpDatabase($filename);
                  }
  
                  // download part of the file
                  $result = Http::downloadChunk(
                      $url, $outputPath, Common::getRequestVar('continue', true, 'int'));
  
                  // if the file is done
                  if ($result['current_size'] >= $result['expected_file_size']) {
                      if ($this->isGeoIp2Enabled()) {
                          GeoIP2AutoUpdater::unzipDownloadedFile($outputPath, $key, $unlink = true);
                      } else {
                          GeoIPAutoUpdater::unzipDownloadedFile($outputPath, $unlink = true);
                      }
  
                      $info = $this->getNextMissingDbUrlInfo();
                      if ($info !== false) {
                          return json_encode($info);
                      }
                  }
  
                  return json_encode($result);
              } catch (Exception $ex) {
                  return json_encode(array('error' => $ex->getMessage()));
              }
          }
      }
code: public function downloadMissingGeoIpDb()
      {
          $this->dieIfGeolocationAdminIsDisabled();
          Piwik::checkUserHasSuperUserAccess();
          if ($_SERVER["REQUEST_METHOD"] == "POST") {
              try {
                  $this->checkTokenInUrl();
  
                  Json::sendHeaderJSON();
  
                  // based on the database type (provided by the 'key' query param) determine the
                  // url & output file name
                  $key = Common::getRequestVar('key', null, 'string');
  
                  if ($this->isGeoIp2Enabled()) {
                      $url = GeoIP2AutoUpdater::getConfiguredUrl($key);
                      $ext = GeoIP2AutoUpdater::getGeoIPUrlExtension($url);
                      $filename = GeoIp2::$dbNames[$key][0] . '.' . $ext;
                      $outputPath = GeoIp2::getPathForGeoIpDatabase($filename);
                  } else {
                      $url = GeoIPAutoUpdater::getConfiguredUrl($key);
                      $ext = GeoIPAutoUpdater::getGeoIPUrlExtension($url);
                      $filename = GeoIp::$dbNames[$key][0] . '.' . $ext;
  
                      if (substr($filename, 0, 15) == 'GeoLiteCity.dat') {
                          $filename = 'GeoIPCity.dat' . substr($filename, 15);
                      }
                      $outputPath = GeoIp::getPathForGeoIpDatabase($filename);
                  }
  
                  // download part of the file
                  $result = Http::downloadChunk(
                      $url, $outputPath, Common::getRequestVar('continue', true, 'int'));
  
                  // if the file is done
                  if ($result['current_size'] >= $result['expected_file_size']) {
                      if ($this->isGeoIp2Enabled()) {
                          GeoIP2AutoUpdater::unzipDownloadedFile($outputPath, $key, $unlink = true);
                      } else {
                          GeoIPAutoUpdater::unzipDownloadedFile($outputPath, $unlink = true);
                      }
  
                      $info = $this->getNextMissingDbUrlInfo();
                      if ($info !== false) {
                          return json_encode($info);
                      }
                  }
  
                  return json_encode($result);
              } catch (Exception $ex) {
                  return json_encode(array('error' => $ex->getMessage()));
              }
          }
      }
code_tokens: public function downloadMissingGeoIpDb ( ) { $ this -> dieIfGeolocationAdminIsDisabled ( ) ; Piwik :: checkUserHasSuperUserAccess ( ) ; if ( $ _SERVER [ "REQUEST_METHOD" ] == "POST" ) { try { $ this -> checkTokenInUrl ( ) ; Json :: sendHeaderJSON ( ) ; // based on the database type (provided by the 'key' query param) determine the // url & output file name $ key = Common :: getRequestVar ( 'key' , null , 'string' ) ; if ( $ this -> isGeoIp2Enabled ( ) ) { $ url = GeoIP2AutoUpdater :: getConfiguredUrl ( $ key ) ; $ ext = GeoIP2AutoUpdater :: getGeoIPUrlExtension ( $ url ) ; $ filename = GeoIp2 :: $ dbNames [ $ key ] [ 0 ] . '.' . $ ext ; $ outputPath = GeoIp2 :: getPathForGeoIpDatabase ( $ filename ) ; } else { $ url = GeoIPAutoUpdater :: getConfiguredUrl ( $ key ) ; $ ext = GeoIPAutoUpdater :: getGeoIPUrlExtension ( $ url ) ; $ filename = GeoIp :: $ dbNames [ $ key ] [ 0 ] . '.' . $ ext ; if ( substr ( $ filename , 0 , 15 ) == 'GeoLiteCity.dat' ) { $ filename = 'GeoIPCity.dat' . substr ( $ filename , 15 ) ; } $ outputPath = GeoIp :: getPathForGeoIpDatabase ( $ filename ) ; } // download part of the file $ result = Http :: downloadChunk ( $ url , $ outputPath , Common :: getRequestVar ( 'continue' , true , 'int' ) ) ; // if the file is done if ( $ result [ 'current_size' ] >= $ result [ 'expected_file_size' ] ) { if ( $ this -> isGeoIp2Enabled ( ) ) { GeoIP2AutoUpdater :: unzipDownloadedFile ( $ outputPath , $ key , $ unlink = true ) ; } else { GeoIPAutoUpdater :: unzipDownloadedFile ( $ outputPath , $ unlink = true ) ; } $ info = $ this -> getNextMissingDbUrlInfo ( ) ; if ( $ info !== false ) { return json_encode ( $ info ) ; } } return json_encode ( $ result ) ; } catch ( Exception $ ex ) { return json_encode ( array ( 'error' => $ ex -> getMessage ( ) ) ) ; } } }
docstring: Starts or continues a download for a missing GeoIP database. A database is missing if
  it has an update URL configured, but the actual database is not available in the misc
  directory.
  
  Input:
  'url' - The URL to download the database from.
  'continue' - 1 if we're continuing a download, 0 if we're starting one.
  
  Output:
  'error' - If an error occurs this describes the error.
  'to_download' - The URL of a missing database that should be downloaded next (if any).
  'to_download_label' - The label to use w/ the progress bar that describes what we're
  downloading.
  'current_size' - Size of the current file on disk.
  'expected_file_size' - Size of the completely downloaded file.
docstring_tokens: Starts or continues a download for a missing GeoIP database . A database is missing if it has an update URL configured but the actual database is not available in the misc directory .