function geoip_detect_update() { // TODO: Currently cron is scheduled but not executed. Remove scheduling. if (get_option('geoip-detect-source') != 'auto') { return; } $download_url = 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz'; $download_url = apply_filters('geoip_detect2_download_url', $download_url); $outFile = geoip_detect_get_database_upload_filename(); // Download $tmpFile = download_url($download_url); if (is_wp_error($tmpFile)) { return $tmpFile->get_error_message(); } // Ungzip File $zh = gzopen($tmpFile, 'r'); $h = fopen($outFile, 'w'); if (!$zh) { return __('Downloaded file could not be opened for reading.', 'geoip-detect'); } if (!$h) { return sprintf(__('Database could not be written (%s).', 'geoip-detect'), $outFile); } while (($string = gzread($zh, 4096)) != false) { fwrite($h, $string, strlen($string)); } gzclose($zh); fclose($h); unlink($tmpFile); return true; }
protected function openFile() { $this->handle = gzopen($this->filename, 'w9'); if ($this->handle === false) { throw new \RuntimeException(sprintf('Impossible to open the file %s in write mode', $this->filename)); } }
function fopen($filename, $mode = 'r') { if ($this->has_gzip()) { return gzopen($filename, $mode); } return fopen($filename, $mode); }
public function animetitlesUpdate() { $pdo = $this->pdo; $lastUpdate = $pdo->queryOneRow('SELECT max(unixtime) as utime FROM animetitles'); if (isset($lastUpdate['utime']) && time() - $lastUpdate['utime'] < 604800) { if ($this->echooutput) { echo "\n"; echo $this->c->info("Last update occurred less than 7 days ago, skipping full dat file update.\n\n"); } return; } if ($this->echooutput) { echo $this->c->header("Updating animetitles by grabbing full dat AniDB dump.\n\n"); } $zh = gzopen('http://anidb.net/api/anime-titles.dat.gz', 'r'); preg_match_all('/(\\d+)\\|\\d\\|.+\\|(.+)/', gzread($zh, '10000000'), $animetitles); if (!$animetitles) { return false; } $pdo->queryExec('DELETE FROM animetitles WHERE anidbid IS NOT NULL'); if ($this->echooutput) { echo $this->c->header("Total of " . count($animetitles[1]) . " titles to add\n\n"); } for ($loop = 0; $loop < count($animetitles[1]); $loop++) { $pdo->queryInsert(sprintf('INSERT IGNORE INTO animetitles (anidbid, title, unixtime) VALUES (%d, %s, %d)', $animetitles[1][$loop], $pdo->escapeString(html_entity_decode($animetitles[2][$loop], ENT_QUOTES, 'UTF-8')), time())); } if ($loop % 2500 == 0 && $this->echooutput) { echo $this->c->header("Completed Processing " . $loop . " titles.\n\n"); } gzclose($zh); if ($this->echooutput) { echo $this->c->header("Completed animetitles update.\n\n"); } }
/** * Compress file on disk * * @param string $source * @param int $level * @return string|false */ function gzcompressfile($source, $level = false) { if (file_exists($source)) { $dest = $source . '.gz'; $mode = 'wb' . $level; $error = false; if ($fp_out = gzopen($dest, $mode)) { if ($fp_in = fopen($source, 'rb')) { while (!feof($fp_in)) { gzwrite($fp_out, fread($fp_in, 4096)); } fclose($fp_in); } else { $error = true; } gzclose($fp_out); } else { $error = true; } if ($error) { return false; } return $dest; } return false; }
/** * Gzip a file * * @param string $sSourceFile Path to the source file * @param string $sDestinationFile [optional] Path to save the zip contents. * <p> * If NULL, the default value is $this->getDefaultDestinationFilename($sSourceFile) * </p> * * @return string Path to the saved zip file * * @throws FileOpenException if there is any error opening the source or output files * @throws FileReadException if there is an error reading the source file * @throws FileWriteException if there is an error writing the output file */ public function zip($sSourceFile, $sDestinationFile = null) { if ($sDestinationFile === null) { $sDestinationFile = $this->getDefaultDestinationFilename($sSourceFile); } if (!($fh = fopen($sSourceFile, 'rb'))) { throw new FileOpenException($sSourceFile); } if (!($zp = gzopen($sDestinationFile, 'wb9'))) { throw new FileOpenException($sDestinationFile); } while (!feof($fh)) { $data = fread($fh, static::READ_SIZE); if (false === $data) { throw new FileReadException($sSourceFile); } $sz = strlen($data); if ($sz !== gzwrite($zp, $data, $sz)) { throw new FileWriteException($sDestinationFile); } } gzclose($zp); fclose($fh); return $sDestinationFile; }
/** * updates the GeoIP database file * works only if directory geoip has rights 777, set it in ftp client */ function updateGeoIpFile() { global $cpd_path; // set directory mode @chmod($cpd_path . '/geoip', 0777); // function checks if (!ini_get('allow_url_fopen')) { return 'Sorry, <code>allow_url_fopen</code> is disabled!'; } if (!function_exists('gzopen')) { return __('Sorry, necessary functions (zlib) not installed or enabled in php.ini.', 'cpd'); } $gzfile = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz'; $file = $cpd_path . '/geoip/GeoIP.dat'; // get remote file $h = gzopen($gzfile, 'rb'); $content = gzread($h, 1500000); fclose($h); // delete local file if (is_file($file)) { unlink($file); } // file deleted? $del = is_file($file) ? 0 : 1; // write new locale file $h = fopen($file, 'wb'); fwrite($h, $content); fclose($h); @chmod($file, 0777); if (is_file($file) && $del) { return __('New GeoIP database installed.', 'cpd'); } else { return __('Sorry, an error occurred. Try again or check the access rights of directory "geoip" is 777.', 'cpd'); } }
function import_sql($filename) { $handle = @gzopen($filename, "r"); // can open normal files, too. $query = ""; $queries = 0; while ($handle && !feof($handle)) { $line = gzgets($handle, 1024); // keep string manipulations sane if ($line != "" && substr($line, 0, 2) != "--") { // line doesnt start with comment $query .= $line; if (substr(trim($line), -1, 1) == ";") { if (!mysql_query($query)) { if (defined("DEBUG")) { echo "MYSQL Error: " . mysql_error() . "<Br><br>in query: {$query}"; } else { echo "MYSQL Error: " . mysql_error(); } } $query = ""; $queries++; } } } return true; }
protected function openResource() { if ($this->gzip_file) { return gzopen($this->resource, 'a'); } return fopen($this->resource, 'a'); }
/** * Rotate all files in var/log which ends with .log */ public function rotateLogs() { $var = Mage::getBaseDir('log'); $logDir = new Varien_Io_File(); $logDir->cd($var); $logFiles = $logDir->ls(Varien_Io_File::GREP_FILES); foreach ($logFiles as $logFile) { if ($logFile['filetype'] == 'log') { $filename = $logFile['text']; if (extension_loaded('zlib')) { $zipname = $var . DS . $this->getArchiveName($filename); $zip = gzopen($zipname, 'wb9'); gzwrite($zip, $logDir->read($filename)); gzclose($zip); } else { $logDir->cp($filename, $this->getArchiveName($filename)); } foreach ($this->getFilesOlderThan(self::MAX_FILE_DAYS, $var, $filename) as $oldFile) { $logDir->rm($oldFile['text']); } $logDir->rm($filename); } } $logDir->close(); }
function WRITE($hash, $overwrite = 0) { $id = $hash["id"]; $version = $hash["version"]; $dbfile = $this->FN("{$id}.{$version}"); if (!$overwrite && file_exists($dbfile)) { return; } #-- read-lock if (file_exists($dbfile)) { $lock = fopen($dbfile, "rb"); flock($lock, LOCK_EX); } #-- open file for writing, secondary lock if ($f = gzopen($dbfile, "wb" . $this->gz)) { if (!lock) { flock($f, LOCK_EX); } $r = gzwrite($f, serialize($hash)); gzclose($f); $this->SETVER($id, $version); $this->CACHE_ADD($id, $version); return 1; } #-- dispose lock if ($lock) { flock($lock, LOCK_UN); fclose($lock); } return 0; }
function restoreAction() { $backupFile = new UploadedFile("backupFile"); if (!$backupFile->wasUploaded()) { return; } $gzipMode = $this->request->fileType == "gzip"; $fileName = $backupFile->getTempName(); $fp = $gzipMode ? gzopen($fileName, "r") : fopen($fileName, "r"); $inString = false; $query = ""; while (!feof($fp)) { $line = $gzipMode ? gzgets($fp) : fgets($fp); if (!$inString) { $isCommentLine = false; foreach (array("#", "--") as $commentTag) { if (strpos($line, $commentTag) === 0) { $isCommentLine = true; } } if ($isCommentLine || trim($line) == "") { continue; } } $deslashedLine = str_replace('\\', '', $line); if ((substr_count($deslashedLine, "'") - substr_count($deslashedLine, "\\'")) % 2) { $inString = !$inString; } $query .= $line; if (substr_compare(rtrim($line), ";", -1) == 0 && !$inString) { $this->database->sqlQuery($query); $query = ""; } } }
/** * Open a descriptor for this archive * * @param GitPHP_Archive $archive archive * @return boolean true on success */ public function Open($archive) { if (!$archive) { return false; } if ($this->handle) { return true; } $args = array(); $args[] = '--format=tar'; $args[] = "--prefix='" . $archive->GetPrefix() . "'"; $args[] = $archive->GetObject()->GetHash(); $this->handle = $this->exe->Open($archive->GetProject()->GetPath(), GIT_ARCHIVE, $args); // hack to get around the fact that gzip files // can't be compressed on the fly and the php zlib stream // doesn't seem to daisy chain with any non-file streams $this->tempfile = tempnam(sys_get_temp_dir(), "GitPHP"); $mode = 'wb'; if ($this->compressLevel) { $mode .= $this->compressLevel; } $temphandle = gzopen($this->tempfile, $mode); if ($temphandle) { while (!feof($this->handle)) { gzwrite($temphandle, fread($this->handle, 1048576)); } gzclose($temphandle); $temphandle = fopen($this->tempfile, 'rb'); } if ($this->handle) { pclose($this->handle); } $this->handle = $temphandle; return $this->handle !== false; }
public function testCreate() { $sitemap = new Sitemap(['maxUrlsCountInFile' => 1]); $sitemapDirectory = $sitemap->sitemapDirectory = $this->path; $sitemap->addModel(Category::className()); $sitemap->setDisallowUrls(['#category_2#']); $sitemap->create(); $sitemapFileNames = array(); foreach (glob("{$sitemapDirectory}/sitemap*") as $sitemapFilePath) { $sitemapFileNames[] = basename($sitemapFilePath); } $this->assertEquals($sitemapFileNames, array('sitemap.xml', 'sitemap.xml.gz', 'sitemap1.xml', 'sitemap1.xml.gz', 'sitemap2.xml', 'sitemap2.xml.gz')); $xmlData = file_get_contents("{$sitemapDirectory}/sitemap.xml"); $this->assertNotFalse(strpos($xmlData, '<?xml version="1.0" encoding="UTF-8"?>')); $xmlData = file_get_contents("{$sitemapDirectory}/sitemap2.xml"); $this->assertNotFalse(strpos($xmlData, '<loc>http://localhost/category_3</loc>')); $gzSitemap = gzopen("{$sitemapDirectory}/sitemap.xml.gz", "r"); $sitemap = fopen("{$sitemapDirectory}/sitemap.xml", "r"); $this->assertEquals(fread($gzSitemap, 2000), fread($sitemap, 2000)); gzclose($gzSitemap); fclose($sitemap); $gzSitemap = gzopen("{$sitemapDirectory}/sitemap2.xml.gz", "r"); $sitemap = fopen("{$sitemapDirectory}/sitemap2.xml", "r"); $this->assertEquals(fread($gzSitemap, 2000), fread($sitemap, 2000)); gzclose($gzSitemap); fclose($sitemap); }
/** * Pimcore * * This source file is available under two different licenses: * - GNU General Public License version 3 (GPLv3) * - Pimcore Enterprise License (PEL) * Full copyright and license information is available in * LICENSE.md which is distributed with this source code. * * @copyright Copyright (c) 2009-2016 pimcore GmbH (http://www.pimcore.org) * @license http://www.pimcore.org/license GPLv3 and PEL */ function gzcompressfile($source, $level = null, $target = null) { // this is a very memory efficient way of gzipping files if ($target) { $dest = $target; } else { $dest = $source . '.gz'; } $mode = 'wb' . $level; $error = false; $fp_out = gzopen($dest, $mode); $fp_in = fopen($source, 'rb'); if ($fp_out && $fp_in) { while (!feof($fp_in)) { gzwrite($fp_out, fread($fp_in, 1024 * 512)); } fclose($fp_in); gzclose($fp_out); } else { $error = true; } if ($error) { return false; } else { return $dest; } }
function geoip_detect_update() { $download_url = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz'; $outFile = geoip_detect_get_database_upload_filename(); // Download $tmpFile = download_url($download_url); if (is_wp_error($tmpFile)) { return $tmpFile->get_error_message(); } // Ungzip File $zh = gzopen($tmpFile, 'r'); $h = fopen($outFile, 'w'); if (!$zh) { return __('Downloaded file could not be opened for reading.', 'geoip-detect'); } if (!$h) { return sprintf(__('Database could not be written (%s).', 'geoip-detect'), $outFile); } while (($string = gzread($zh, 4096)) != false) { fwrite($h, $string, strlen($string)); } gzclose($zh); fclose($h); //unlink($tmpFile); return true; }
function LoadBackUp() { global $SAMSConf; global $USERConf; $DB = new SAMSDB(); $lang = "./lang/lang.{$SAMSConf->LANG}"; require $lang; if ($USERConf->ToWebInterfaceAccess("C") != 1) { exit; } PageTop("reark_48.jpg", "{$backupbuttom_2_loadbase_LoadBackUp_1}"); if (($finp = gzopen($_FILES['userfile']['tmp_name'], "r")) != NULL) { while (gzeof($finp) == 0) { $string = gzgets($finp, 10000); $QUERY = strtok($string, ";"); if (strstr($QUERY, "#") == FALSE) { echo "{$QUERY}<BR>"; $num_rows = $DB->samsdb_query($QUERY . ";"); } $count++; } } print "<SCRIPT>\n"; print " parent.lframe.location.href=\"lframe.php\"; \n"; print "</SCRIPT> \n"; }
private function setFile() { $recognize = ''; $recognize = implode('_', $this->dbName); $fileName = $this->trimPath($this->config['path'] . self::DIR_SEP . time() . '.sql'); $path = $this->setPath($fileName); if ($path !== true) { $this->error("无法创建备份目录目录 '{$path}'"); } if ($this->config['isCompress'] == 0) { if (!file_put_contents($fileName, $this->content, LOCK_EX)) { $this->error('写入文件失败,请检查磁盘空间或者权限!'); } } else { if (function_exists('gzwrite')) { $fileName .= '.gz'; if ($gz = gzopen($fileName, 'wb')) { gzwrite($gz, $this->content); gzclose($gz); } else { $this->error('写入文件失败,请检查磁盘空间或者权限!'); } } else { $this->error('没有开启gzip扩展!'); } } if ($this->config['isDownload']) { $this->downloadFile($fileName); } }
public function extractTar($src, $dest) { if ($this->is_tar($src)) { file_put_contents($tmp = '~tmp(' . microtime() . ').tar', $src); $src = $tmp; } $ptr = gzopen($src, 'r'); while (!gzeof($ptr)) { $infos = $this->readTarHeader($ptr); if ($infos['type'] == '5') { if (!file_exists($dest . $infos['name'])) { mkdir($dest . $infos['name'], 0777, true); } $result[] = $dest . $infos['name']; } elseif ($infos['type'] == '0' || $infos['type'] == chr(0)) { $dirPath = substr($infos['name'], 0, strrpos($infos['name'], '/')); if (!file_exists($dest . $dirPath)) { mkdir($dest . $dirPath, 0777, true); } if (file_put_contents($dest . $infos['name'], $infos['data'])) { $result[] = $dest . $infos['name']; } } if ($infos) { chmod($dest . $infos['name'], 0777); } } if (is_file($tmp)) { unlink($tmp); } return $result; }
/** * Opens a gzip file. * * @param string $filename * @param string $mode */ public function __construct($filename, $mode = 'wb') { $this->filename = $filename; $this->resource = gzopen($filename, $mode); if ($this->resource === false) { throw new SystemException('Can not open file ' . $filename); } }
function writeInternal($str) { global $opt; // close the last file? if ($this->oSitemapFile !== false && ($this->nWrittenSize + strlen($str) > $this->nMaxFileSize || $this->nWrittenCount >= $this->nMaxUrlCount)) { gzwrite($this->oSitemapFile, '</urlset>'); gzclose($this->oSitemapFile); $this->oSitemapFile = false; } // open new XML file? if ($this->oSitemapFile === false) { $this->nSitemapIndex++; $sFilename = 'sitemap-' . $this->nSitemapIndex . '.xml.gz'; $this->oSitemapFile = gzopen($this->sPath . $sFilename, 'wb'); fwrite($this->oIndexFile, '<sitemap><loc>' . xmlentities($this->sDomain . $sFilename) . '</loc><lastmod>' . xmlentities(date('c')) . '</lastmod></sitemap>'); gzwrite($this->oSitemapFile, '<?xml version="1.0" encoding="UTF-8"?>' . "\n"); gzwrite($this->oSitemapFile, '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'); // includes end of xml-tag $this->nWrittenSize = 108; $this->nWrittenCount = 0; } // write string to XML gzwrite($this->oSitemapFile, $str); $this->nWrittenSize += strlen($str); $this->nWrittenCount++; }
public static function export_tracking() { global $wpdb; // only one export at a time if (get_option('podlove_tracking_export_all') !== false) { return; } update_option('podlove_tracking_export_all', $wpdb->get_var("SELECT COUNT(*) FROM " . \Podlove\Model\DownloadIntent::table_name())); update_option('podlove_tracking_export_progress', 0); $rowsPerQuery = 1000; $lastId = 0; $page = 0; $fp = gzopen(self::get_tracking_export_file_path(), 'w'); do { // Keeping track of the $lastId is (roughly) a bajillion times faster than paging via LIMIT. $sql = "\n\t\t\t\tSELECT\n\t\t\t\t\tid,\n\t\t\t\t\tuser_agent_id,\n\t\t\t\t\tmedia_file_id,\n\t\t\t\t\trequest_id,\n\t\t\t\t\taccessed_at,\n\t\t\t\t\tsource,\n\t\t\t\t\tcontext,\n\t\t\t\t\tgeo_area_id,\n\t\t\t\t\tlat,\n\t\t\t\t\tlng\n\t\t\t\tFROM\n\t\t\t\t\t" . \Podlove\Model\DownloadIntent::table_name() . "\n\t\t\t\t\tWHERE id > " . (int) $lastId . "\n\t\t\t\tLIMIT 0, {$rowsPerQuery}"; $rows = $wpdb->get_results($sql, ARRAY_A); foreach ($rows as $row) { gzwrite($fp, implode(",", $row) . "\n"); } $lastId = $row['id']; $page++; update_option('podlove_tracking_export_progress', $page * $rowsPerQuery); } while (count($rows) > 0); gzclose($fp); delete_option('podlove_tracking_export_all'); delete_option('podlove_tracking_export_progress'); exit; }
function backwpup_read_logheader($logfile) { $headers = array("backwpup_version" => "version", "backwpup_logtime" => "logtime", "backwpup_errors" => "errors", "backwpup_warnings" => "warnings", "backwpup_jobid" => "jobid", "backwpup_jobname" => "name", "backwpup_jobtype" => "type", "backwpup_jobruntime" => "runtime", "backwpup_backupfilesize" => "backupfilesize"); if (!is_readable($logfile)) { return false; } //Read file if (substr($logfile, -3) == ".gz") { $fp = gzopen($logfile, 'r'); $file_data = gzread($fp, 1536); // Pull only the first 1,5kiB of the file in. gzclose($fp); } else { $fp = fopen($logfile, 'r'); $file_data = fread($fp, 1536); // Pull only the first 1,5kiB of the file in. fclose($fp); } //get data form file foreach ($headers as $keyword => $field) { preg_match('/(<meta name="' . $keyword . '" content="(.*)" \\/>)/i', $file_data, $content); if (!empty($content)) { $joddata[$field] = $content[2]; } else { $joddata[$field] = ''; } } if (empty($joddata['logtime'])) { $joddata['logtime'] = filectime($logfile); } return $joddata; }
function gzip_uncompress($data) { $filename = gzip_tempnam(); if (!($fp = fopen($filename, 'wb'))) trigger_error(sprintf('%s failed', 'fopen'), E_USER_ERROR); fwrite($fp, $data, strlen($data)); if (!fclose($fp)) trigger_error(sprintf('%s failed', 'fclose'), E_USER_ERROR); if (!($fp = gzopen($filename, 'rb'))) trigger_error(sprintf('%s failed', 'gzopen'), E_USER_ERROR); $unz = ''; while ($buf = gzread($fp, 4096)) $unz .= $buf; if (!gzclose($fp)) trigger_error(sprintf("%s failed", 'gzclose'), E_USER_ERROR); unlink($filename); return $unz; }
public static function update_database() { set_time_limit(0); $outFile = self::get_upload_file_path(); // for download_url() require_once ABSPATH . 'wp-admin/includes/file.php'; $tmpFile = \download_url(self::SOURCE_URL); if (is_wp_error($tmpFile)) { die($tmpFile->get_error_message()); } $zh = gzopen($tmpFile, 'rb'); $h = fopen($outFile, 'wb'); if (!$zh) { die('Downloaded file could not be opened for reading.'); } if (!$h) { die(sprintf('Database could not be written (%s).', $outFile)); } while (!gzeof($zh)) { fwrite($h, gzread($zh, 4096)); } gzclose($zh); fclose($h); unlink($tmpFile); if (!self::is_db_valid()) { die(sprintf('Checksum does not match (%s).', $outFile)); } }
/** * @see File_Archive_Reader::next() */ function next() { if (!parent::next()) { return false; } $this->nbRead++; $this->filePos = 0; if ($this->nbRead > 1) { return false; } $dataFilename = $this->source->getDataFilename(); if ($dataFilename !== null) { $this->tmpName = null; $this->gzfile = gzopen($dataFilename, 'r'); } else { $this->tmpName = tempnam(File_Archive::getOption('tmpDirectory'), 'far'); //Generate the tmp data $dest = new File_Archive_Writer_Files(); $dest->newFile($this->tmpName); $this->source->sendData($dest); $dest->close(); $this->gzfile = gzopen($this->tmpName, 'r'); } return true; }
/** * @see Mage_Archive_Helper_File::_open() */ protected function _open($mode) { $this->_fileHandler = @gzopen($this->_filePath, $mode); if (false === $this->_fileHandler) { throw new Mage_Exception('Failed to open file ' . $this->_filePath); } }
private function _compress($file, $content, $gzip = true) { if ($gzip) { $fh = gzopen($file, 'wb'); if (!$fh) { throw new RuntimeException('Unable to open ' . $file . ' for writing.'); } gzwrite($fh, $content); gzclose($fh); $newFile = $file . '.gz'; if (rename($file, $newFile)) { self::$_tempFiles[] = $newFile; } else { throw new RuntimeException('Unable to rename ' . $file . ' to ' . $newFile . '.'); } } else { $newFile = $file . '.zip'; $zip = new ZipArchive(); $res = $zip->open($newFile, ZipArchive::CREATE); if ($res === true) { self::$_tempFiles[] = $newFile; $zip->addFromString(basename($file), $content); // In this case the original file isn't necessary unlink($file); $zip->close(); } else { throw new RuntimeException('Got error code ' . $res . ' when attempting to open ' . 'zip archive ' . $newFile . '.'); } } // Just to make sure our subsequent assertions aren't false positives $this->assertFalse(file_exists($file)); return $newFile; }
public function import() { // It might not look like it, but it is actually compatible to // uncompressed files. $gzFileHandler = gzopen($this->file, 'r'); Model\DownloadIntent::delete_all(); Model\DownloadIntentClean::delete_all(); $batchSize = 1000; $batch = array(); while (!gzeof($gzFileHandler)) { $line = gzgets($gzFileHandler); list($id, $user_agent_id, $media_file_id, $request_id, $accessed_at, $source, $context, $geo_area_id, $lat, $lng) = explode(",", $line); $batch[] = array($user_agent_id, $media_file_id, $request_id, $accessed_at, $source, $context, $geo_area_id, $lat, $lng); if (count($batch) >= $batchSize) { self::save_batch_to_db($batch); $batch = []; } } gzclose($gzFileHandler); // save last batch to db self::save_batch_to_db($batch); \Podlove\Analytics\DownloadIntentCleanup::cleanup_download_intents(); \Podlove\Cache\TemplateCache::get_instance()->setup_purge(); wp_redirect(admin_url('admin.php?page=podlove_imexport_migration_handle&status=success')); exit; }
protected function execute(InputInterface $input, OutputInterface $output) { $em = $this->getEntityManager($input->getOption('em')); $c = $this->getContainer(); if (!$c->hasParameter('kb_sitemap.base_url')) { throw new \RuntimeException("Sitemap requires base_url parameter [kb_sitemap.base_url] to be available, through config or parameters"); } $output->write('<info>Fetching resources..</info>' . PHP_EOL); $dql = <<<___SQL SELECT b.name, b.ownerName, b.updatedAt FROM KnpBundlesBundle:Bundle b ___SQL; $q = $em->createQuery($dql); $bundles = $q->getArrayResult(); $dql = <<<___SQL SELECT d.name, d.createdAt FROM KnpBundlesBundle:Developer d ___SQL; $q = $em->createQuery($dql); $users = $q->getArrayResult(); $sitemapFile = $c->getParameter('kernel.root_dir') . '/../web/sitemap.xml'; $output->write('<info>Building sitemap...</info>' . PHP_EOL); $spaceless = (bool) $input->getOption('spaceless'); $tpl = $spaceless ? 'KnpSitemapBundle::sitemap.spaceless.xml.twig' : 'KnpSitemapBundle::sitemap.xml.twig'; $sitemap = $c->get('templating')->render($tpl, compact('bundles', 'users')); $output->write("<info>Saving sitemap in [{$sitemapFile}]..</info>" . PHP_EOL); file_put_contents($sitemapFile, $sitemap); // gzip the sitemap if (function_exists('gzopen')) { $output->write("<info>Gzipping the generated sitemap [{$sitemapFile}.gz]..</info>" . PHP_EOL); $gz = gzopen($sitemapFile . '.gz', 'w9'); gzwrite($gz, $sitemap); gzclose($gz); } $output->write('<info>Done</info>' . PHP_EOL); }