예제 #1
0
    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);
    }
 function doWrite( $data, $uncompressedLength = false )
 {
     if ( $uncompressedLength )
         return @gzwrite( $this->File, $data, $uncompressedLength );
     else
         return @gzwrite( $this->File, $data );
 }
예제 #3
0
 /**
  * @see Mage_Archive_Helper_File::_write()
  */
 protected function _write($data)
 {
     $result = @gzwrite($this->_fileHandler, $data);
     if (empty($result) && !empty($data)) {
         throw new Mage_Exception('Failed to write data to ' . $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;
 }
예제 #5
0
 /**
  * Writes a string to a stream, terminating it with an end-of-line
  * symbol.
  *
  * @param string $string The string to write.
  */
 public function writeLine($string)
 {
     if (!is_resource($this->_stream)) {
         throw new Opl_Stream_Exception('Output stream is not opened.');
     }
     gzwrite($this->_stream, $bytes . self::$_eol);
 }
 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;
 }
예제 #7
0
function get_content($database, $table, $fp)
{
    //      get content of data
    global $delimiter;
    $result = mysql_db_query($database, "SELECT * FROM {$table}") or die("Cannot get content of table");
    while ($row = mysql_fetch_row($result)) {
        $insert = "INSERT INTO {$table} VALUES (";
        //      command for later SQL-restore
        for ($j = 0; $j < mysql_num_fields($result); $j++) {
            //      content for later SQL-restore
            if (!isset($row[$j])) {
                $insert .= "NULL,";
            } elseif (isset($row[$j])) {
                $insert .= "'" . addslashes($row[$j]) . "',";
            } else {
                $insert .= "'',";
            }
        }
        $insert = ereg_replace(",\$", "", $insert);
        $insert .= "){$delimiter}\n";
        //      create row delimiter
        gzwrite($fp, $insert);
        //      now write the complete content into backup file
    }
    gzwrite($fp, "\n\n");
    mysql_free_result($result);
}
예제 #8
0
파일: helper.php 프로젝트: pimcore/pimcore
/**
 * 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;
    }
}
예제 #9
0
 /**
  * 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;
 }
예제 #10
0
 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);
     }
 }
예제 #11
0
/**
 * 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;
}
예제 #12
0
 /**
  * {@inheritdoc}
  */
 protected function _write($data)
 {
     $result = gzwrite($this->_fileHandler, $data);
     if (empty($result) && !empty($data)) {
         throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Failed to write data to %1', [$this->_filePath]));
     }
 }
예제 #13
0
파일: dzf2.php 프로젝트: gpuenteallott/rox
 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;
 }
 /**
  * {@inheritdoc}
  */
 public function dump($string)
 {
     if ($this->handle == null) {
         $this->openFile();
     }
     gzwrite($this->handle, $string);
 }
예제 #15
0
 /**
  * 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();
 }
예제 #16
0
function gzip_compress($data)
{
	$filename = gzip_tempnam();

	if (!($fp = gzopen($filename, 'wb')))
		trigger_error(sprintf('%s failed', 'gzopen'), E_USER_ERROR);

	gzwrite($fp, $data, strlen($data));

	if (!gzclose($fp))
		trigger_error(sprintf('%s failed', 'gzclose'), E_USER_ERROR);

	$size = filesize($filename);

	if (!($fp = fopen($filename, 'rb')))
		trigger_error(sprintf('%s failed', 'fopen'), E_USER_ERROR);

	if (!($z = fread($fp, $size)) || strlen($z) != $size)
		trigger_error(sprintf('%s failed', 'fread'), E_USER_ERROR);

	if (!fclose($fp))
		trigger_error(sprintf('%s failed', 'fclose'), E_USER_ERROR);

	unlink($filename);
	return $z;
}
예제 #17
0
 /**
  * {@inheritdoc}
  */
 protected function doWrite($message, $newline)
 {
     if (false === @gzwrite($this->stream, $message . ($newline ? PHP_EOL : ''))) {
         // should never happen
         throw new \RuntimeException('Unable to write output.');
     }
     fflush($this->stream);
 }
예제 #18
0
 function writebk($hf, $cflag, $strw)
 {
     if ($cflag) {
         gzwrite($hf, $strw);
     } else {
         fwrite($hf, $strw);
     }
 }
예제 #19
0
파일: test.php 프로젝트: ashenkar/sanga
 public function writeCompressedSample($filename, $content)
 {
     $fp = gzopen('test/samples/' . $filename, 'w9') or die("can't open: {$php_errormsg}");
     if (-1 == gzwrite($fp, $content)) {
         die("can't write: {$php_errormsg}");
     }
     gzclose($fp);
 }
예제 #20
0
function write($contents)
{
    if ($GLOBALS['gzip']) {
        gzwrite($GLOBALS['fp'], $contents);
    } else {
        fwrite($GLOBALS['fp'], $contents);
    }
}
예제 #21
0
 public function end()
 {
     $src = ob_get_clean();
     $fp = gzopen($this->fragment, 'w9');
     gzwrite($fp, $src, strlen($src));
     gzclose($fp);
     echo $src;
 }
예제 #22
0
function compress($file, $dest)
{
    $fp = fopen($file, "r");
    $data = fread($fp, filesize($file));
    fclose($fp);
    $zp = gzopen($dest, "w9");
    gzwrite($zp, $data);
    gzclose($zp);
}
예제 #23
0
 public function compressToGZ($srcName, $dstName)
 {
     $fp = fopen($srcName, "r");
     $data = fread($fp, filesize($srcName));
     fclose($fp);
     $zp = gzopen($dstName, "w9");
     gzwrite($zp, $data);
     gzclose($zp);
 }
예제 #24
0
 function gzip($infile, $outfile, $param = 5)
 {
     $fp = fopen($infile, "r");
     $data = fread($fp, filesize($infile));
     fclose($fp);
     $zp = gzopen($outfile, "w" . $param);
     gzwrite($zp, $data);
     gzclose($zp);
 }
예제 #25
0
 private function buildGZFile($xmlFile, $xml)
 {
     if (function_exists('gzopen') && function_exists('gzwrite') && function_exists('gzclose')) {
         $gz = gzopen($xmlFile . '.gz', 'w');
         gzwrite($gz, $xml);
         gzclose($gz);
     }
     return;
 }
 function process($tmp_filename)
 {
     $output_file = $tmp_filename . '.gz';
     $file = gzopen($output_file, "wb");
     gzwrite($file, file_get_contents($tmp_filename));
     gzclose($file);
     unlink($tmp_filename);
     return $output_file;
 }
예제 #27
0
function GetDataTables()
{
    global $db, $argv;
    $sql = 'SELECT house from tblRealm where region=\'US\' and slug=\'medivh\'';
    $stmt = $db->prepare($sql);
    $stmt->execute();
    $house = 0;
    $stmt->bind_result($house);
    $stmt->fetch();
    $stmt->close();
    $sql = 'SELECT id from tblRealm where house = ?';
    $stmt = $db->prepare($sql);
    $stmt->bind_param('i', $house);
    $stmt->execute();
    $result = $stmt->get_result();
    $realms = DBMapArray($result, null);
    $stmt->close();
    $sql = sprintf('SELECT id from tblSeller where realm in (%s) order by lastseen desc limit 20', implode(',', $realms));
    $stmt = $db->prepare($sql);
    $stmt->execute();
    $result = $stmt->get_result();
    $sellers = DBMapArray($result, null);
    $stmt->close();
    $tables = ['tblAuction' => 'house=' . $house, 'tblAuctionExtra' => 'house=' . $house, 'tblAuctionPet' => 'house=' . $house, 'tblAuctionRare' => 'house=' . $house, 'tblBonusSet' => '1=1', 'tblHouseCheck' => '1=1', 'tblItemBonusesSeen' => '1=1', 'tblItemExpired' => 'house=' . $house, 'tblItemGlobal' => '1=1', 'tblItemHistoryDaily' => 'house=' . $house, 'tblItemHistoryHourly' => 'house=' . $house, 'tblItemHistoryMonthly' => 'item in (select id from tblDBCItem where auctionable=1) and house=' . $house, 'tblItemLevelsSeen' => '1=1', 'tblItemSummary' => 'house=' . $house, 'tblPet' => '1=1', 'tblPetHistoryHourly' => 'house=' . $house, 'tblPetSummary' => 'house=' . $house, 'tblRealm' => '1=1', 'tblRealmGuidHouse' => '1=1', 'tblSeller' => 'realm in (' . implode(',', $realms) . ')', 'tblSellerHistoryHourly' => 'seller in (' . implode(',', $sellers) . ')', 'tblSellerItemHistory' => 'seller in (' . implode(',', $sellers) . ')', 'tblSnapshot' => 'house=' . $house, 'tblWowToken' => '1=1'];
    if (count($argv) > 1) {
        $toRemove = array_diff(array_keys($tables), array_slice($argv, 1));
        foreach ($toRemove as $tblName) {
            unset($tables[$tblName]);
        }
    }
    if (count($tables) == 0) {
        echo "No tables marked for export.\n";
        exit(1);
    }
    $sqlFile = __DIR__ . '/../testdata.sql.gz';
    if (!(touch($sqlFile) && ($sqlFile = realpath($sqlFile)))) {
        echo "Could not create testdata.sql\n";
        exit(1);
    }
    $sqlResource = gzopen($sqlFile, 'w');
    $tmpFile = tempnam('/tmp', 'testdata');
    $cmd = 'mysqldump --verbose --allow-keywords --skip-opt --quick --create-options --add-drop-table --add-locks --extended-insert --no-autocommit --result-file=%s --user='******' --password='******' --where=%s ' . escapeshellarg(DATABASE_SCHEMA) . " %s\n";
    foreach ($tables as $table => $where) {
        file_put_contents($tmpFile, '');
        $trash = [];
        $ret = 0;
        exec(sprintf($cmd, escapeshellarg($tmpFile), escapeshellarg($where), escapeshellarg($table)), $trash, $ret);
        if ($ret != 0) {
            echo 'Error: ' . implode("\n", $trash);
            break;
        }
        gzwrite($sqlResource, file_get_contents($tmpFile));
    }
    gzclose($sqlResource);
    unlink($tmpFile);
}
예제 #28
0
파일: backupdb.php 프로젝트: Nidrax/ppm-1.6
function clear_overflow($fp, &$contents)
{
    global $mybb;
    if (function_exists('gzopen')) {
        gzwrite($fp, $contents);
    } else {
        fwrite($fp, $contents);
    }
    $contents = '';
}
예제 #29
0
 function write($str)
 {
     if ($this->f) {
         gzwrite($this->f, $str);
         fflush($this->f);
     } else {
         echo $str;
         ob_flush();
     }
 }
예제 #30
0
 public function write($file, $data)
 {
     $open = gzopen($file, 'w');
     if (empty($open)) {
         throw new FileNotFoundException('Error', 'fileNotFound', $file);
     }
     $return = gzwrite($open, $data, strlen($data));
     gzclose($open);
     return $return;
 }