Exemplo n.º 1
0
 static function create($filename, $directory = false, $data = false, $atomic = false)
 {
     $filepath = $filename;
     if ($directory) {
         if (!file_exists($directory)) {
             eZDir::mkdir($directory, false, true);
             //                 eZDebugSetting::writeNotice( 'ezfile-create', "Created directory $directory", 'eZFile::create' );
         }
         $filepath = $directory . '/' . $filename;
     }
     // If atomic creation is needed we will use a temporary
     // file when writing the data, then rename it to the correct path.
     if ($atomic) {
         $realpath = $filepath;
         $dirname = dirname($filepath);
         if (strlen($dirname) != 0) {
             $dirname .= "/";
         }
         $filepath = $dirname . "ezfile-tmp." . md5($filepath . getmypid() . mt_rand());
     }
     $file = fopen($filepath, 'wb');
     if ($file) {
         //             eZDebugSetting::writeNotice( 'ezfile-create', "Created file $filepath", 'eZFile::create' );
         if ($data) {
             if (is_resource($data)) {
                 // block-copy source $data to new $file in 1MB chunks
                 while (!feof($data)) {
                     fwrite($file, fread($data, 1048576));
                 }
                 fclose($data);
             } else {
                 fwrite($file, $data);
             }
         }
         fclose($file);
         if ($atomic) {
             // If the renaming process fails, delete the temporary file
             eZFile::rename($filepath, $realpath, false, eZFile::CLEAN_ON_FAILURE);
         }
         return true;
     }
     //         eZDebugSetting::writeNotice( 'ezfile-create', "Failed creating file $filepath", 'eZFile::create' );
     return false;
 }
    /**
     * Creates the object from the uploaded file and displays the preview of it
     *
     * @param array $args
     * @return array
     * @throw RuntimeException if the previously uploaded file cannot be fetched
     */
    static function preview( $args )
    {
        $http = eZHTTPTool::instance();
        $handler = self::getHandler( $args );
        if ( !$handler->canUpload() )
        {
            throw new RuntimeException(
                ezpI18n::tr(
                    'extension/ezjscore/ajaxuploader',
                    'You are not allowed to upload a file.'
                )
            );
        }

        $file = $http->postVariable( 'UploadFile', false );
        $fileHandler = eZClusterFileHandler::instance();
        if ( $file === false
                || !$fileHandler->fileExists( $file )
                || !$fileHandler->fileFetch( $file ) )
        {
            throw new RuntimeException(
                ezpI18n::tr(
                    'extension/ezjscore/ajaxuploader', 'Unable to retrieve the uploaded file.'
                )
            );
        }
        else
        {
            $tmpFile = eZSys::cacheDirectory() . '/' .
                        eZINI::instance()->variable( 'FileSettings', 'TemporaryDir' ) . '/' .
                        str_replace(
                            array( '/', '\\' ), '_',
                            $http->postVariable( 'UploadOriginalFilename' )
                        );
            eZFile::rename( $file, $tmpFile, true );
            $fileHandler->fileDelete( $file );
            $fileHandler->fileDeleteLocal( $file );
        }

        $contentObject = $handler->createObject(
            $tmpFile,
            $http->postVariable( 'UploadLocation', false ),
            $http->postVariable( 'UploadName', '' )
        );
        unlink( $tmpFile );

        $tpl = eZTemplate::factory();
        $tpl->setVariable( 'object', $contentObject );
        return array(
            'meta_data' => $handler->serializeObject( $contentObject ),
            'html' => $tpl->fetch( 'design:ajaxuploader/preview.tpl' )
        );
    }
Exemplo n.º 3
0
 /**
  * Stores the content of the INI object to the cache file \a $cachedFile.
  *
  * @param string $cachedDir Cache dir, usually "var/cache/ini/"
  * @param string $cachedFile Name of cache file as returned by cacheFileName()
  * @param array $data Configuration data as an associative array structure
  * @param array $inputFiles List of input files used as basis for cache (for use in load cache to check mtime)
  * @param string $iniFile Ini file path string returned by findInputFiles() for main ini file
  * @return bool
  */
 protected function saveCache($cachedDir, $cachedFile, array $data, array $inputFiles, $iniFile)
 {
     if (!file_exists($cachedDir)) {
         if (!eZDir::mkdir($cachedDir, 0777, true)) {
             eZDebug::writeError("Couldn't create cache directory {$cachedDir}, perhaps wrong permissions", __METHOD__);
             return false;
         }
     }
     // Save the data to a temp cached file
     $tmpCacheFile = $cachedFile . '_' . substr(md5(mt_rand()), 0, 8);
     $fp = @fopen($tmpCacheFile, "w");
     if ($fp === false) {
         eZDebug::writeError("Couldn't create cache file '{$cachedFile}', perhaps wrong permissions?", __METHOD__);
         return false;
     }
     // Write cache data as a php structure with some meta information for use while reading cache
     fwrite($fp, "<?php\n// This is a auto generated ini cache file, time created:" . date(DATE_RFC822) . "\n");
     fwrite($fp, "\$data = array(\n");
     fwrite($fp, "'rev' => " . eZINI::CONFIG_CACHE_REV . ",\n");
     fwrite($fp, "'created' => '" . date('c') . "',\n");
     if ($this->Codec) {
         fwrite($fp, "'charset' => \"" . $this->Codec->RequestedOutputCharsetCode . "\",\n");
     } else {
         fwrite($fp, "'charset' => \"{$this->Charset}\",\n");
     }
     fwrite($fp, "'files' => " . preg_replace("@\n[\\s]+@", '', var_export($inputFiles, true)) . ",\n");
     fwrite($fp, "'file' => '{$iniFile}',\n");
     fwrite($fp, "'val' => " . preg_replace("@\n[\\s]+@", '', var_export($data, true)) . ");");
     fwrite($fp, "\n?>");
     fclose($fp);
     // Rename cache temp file to final desitination and set permissions
     eZFile::rename($tmpCacheFile, $cachedFile);
     chmod($cachedFile, self::$filePermission);
     if (eZINI::isDebugEnabled()) {
         eZDebug::writeNotice("Wrote cache file '{$cachedFile}'", __METHOD__);
     }
     return true;
 }
Exemplo n.º 4
0
 function close()
 {
     if ($this->ClusteringEnabled) {
         $this->ClusterHandler = null;
         return;
     }
     if ($this->FileResource) {
         fclose($this->FileResource);
         if ($this->isAtomic) {
             eZFile::rename($this->tmpFilename, $this->requestedFilename);
         }
         $this->FileResource = false;
     }
 }
Exemplo n.º 5
0
 function clearMeta()
 {
     $tmpFile = $this->MetaFileName . substr(md5(mt_rand()), 0, 8);
     $content = array();
     eZFile::create($tmpFile, false, serialize($content));
     eZFile::rename($tmpFile, $this->MetaFileName);
 }
 /**
  * Move file.
  *
  * \public
  * \static
  */
 function fileMove($srcPath, $dstPath)
 {
     eZDebugSetting::writeDebug('kernel-clustering', "fs::fileMove( '{$srcPath}', '{$dstPath}' )", __METHOD__);
     eZDebug::accumulatorStart('dbfile', false, 'dbfile');
     eZFile::rename($srcPath, $dstPath, true);
     eZDebug::accumulatorStop('dbfile');
 }
Exemplo n.º 7
0
    /**
     * Fetches the file $filePath from the database to its own name
     *
     * Saving $filePath locally with its original name, or $uniqueName if given
     *
     * @param string $filePath
     * @param string $uniqueName Alternative name to save the file to
     * @return string|bool the file physical path, or false if fetch failed
     */
    public function _fetch( $filePath, $uniqueName = false )
    {
        $metaData = $this->_fetchMetadata( $filePath );
        if ( !$metaData )
        {
            // @todo Throw an exception
            eZDebug::writeError( "File '$filePath' does not exist while trying to fetch.", __METHOD__ );
            return false;
        }

        // create temporary file
        if ( strrpos( $filePath, '.' ) > 0 )
            $tmpFilePath = substr_replace( $filePath, getmypid().'tmp', strrpos( $filePath, '.' ), 0  );
        else
            $tmpFilePath = $filePath . '.' . getmypid().'tmp';
        $this->__mkdir_p( dirname( $tmpFilePath ) );

        // copy DFS file to temporary FS path
        // @todo Throw an exception
        if ( !$this->dfsbackend->copyFromDFS( $filePath, $tmpFilePath ) )
        {
            eZDebug::writeError("Failed copying DFS://$filePath to FS://$tmpFilePath ");
            return false;
        }

        // Make sure all data is written correctly
        clearstatcache();
        $tmpSize = filesize( $tmpFilePath );
        // @todo Throw an exception
        if ( $tmpSize != $metaData['size'] )
        {
            eZDebug::writeError( "Size ($tmpSize) of written data for file '$tmpFilePath' does not match expected size " . $metaData['size'], __METHOD__ );
            return false;
        }

        if ( $uniqueName !== true )
        {
            eZFile::rename( $tmpFilePath, $filePath, false, eZFile::CLEAN_ON_FAILURE | eZFile::APPEND_DEBUG_ON_FAILURE );
        }
        else
        {
            $filePath = $tmpFilePath;
        }

        return $filePath;
    }
Exemplo n.º 8
0
 /**
  * Renamed DFS file $oldPath to DFS file $newPath
  *
  * @param string $oldPath
  * @param string $newPath
  * @return bool
  */
 public function renameOnDFS($oldPath, $newPath)
 {
     $this->accumulatorStart();
     $oldPath = $this->makeDFSPath($oldPath);
     $newPath = $this->makeDFSPath($newPath);
     $ret = eZFile::rename($oldPath, $newPath, true);
     if ($ret) {
         eZClusterFileHandler::cleanupEmptyDirectories($oldPath);
     }
     $this->accumulatorStop();
     return $ret;
 }
Exemplo n.º 9
0
 static function rotateLog($fileName)
 {
     $maxLogrotateFiles = eZDebug::maxLogrotateFiles();
     for ($i = $maxLogrotateFiles; $i > 0; --$i) {
         $logRotateName = $fileName . '.' . $i;
         if (@file_exists($logRotateName)) {
             if ($i == $maxLogrotateFiles) {
                 @unlink($logRotateName);
                 //                     print( "@unlink( $logRotateName )<br/>" );
             } else {
                 $newLogRotateName = $fileName . '.' . ($i + 1);
                 //include_once( 'lib/ezfile/classes/ezfile.php' );
                 eZFile::rename($logRotateName, $newLogRotateName);
                 //                     print( "@rename( $logRotateName, $newLogRotateName )<br/>" );
             }
         }
     }
     if (@file_exists($fileName)) {
         $newLogRotateName = $fileName . '.' . 1;
         //include_once( 'lib/ezfile/classes/ezfile.php' );
         eZFile::rename($fileName, $newLogRotateName);
         //             print( "@rename( $fileName, $newLogRotateName )<br/>" );
         return true;
     }
     return false;
 }
Exemplo n.º 10
0
 function move($source, $destination)
 {
     append_to_log("Source: {$source}   Destination: {$destination}");
     // Make real path to source and destination.
     $realSource = $_SERVER["DOCUMENT_ROOT"] . $source;
     $realDestination = $_SERVER["DOCUMENT_ROOT"] . $destination;
     append_to_log("RealSource: {$realSource}   RealDestination: {$realDestination}");
     $status = eZFile::rename($realSource, $realDestination);
     if ($status) {
         append_to_log("move was OK");
         return eZWebDAVServer::OK_CREATED;
     } else {
         append_to_log("move FAILED");
         return eZWebDAVServer::FAILED_CONFLICT;
     }
 }
Exemplo n.º 11
0
     } else {
         if (count($serverlist) > 1) {
             // retrying other server
             $active_server = nextConnection($active_server, $serverlist, $i + 1);
             $smtp = getConnection($active_server, $serverlist);
             $try = 1;
             while (!$smtp->send($from, $to, $email) && $try <= $maxRetry) {
                 $active_server = nextConnection($active_server, $serverlist, $i + 1);
                 $smtp = getConnection($active_server, $serverlist);
                 $try++;
             }
             if ($try == $maxRetry) {
                 eZFile::rename($mailFiles[$i - 1], $mailFiles[$i] . ".notsend");
             }
         } else {
             eZFile::rename($mailFiles[$i - 1], $mailFiles[$i] . ".notsend");
         }
     }
 }
 if ($robinCounter >= $packageSize && count($serverlist) != 1) {
     $time_end = microtime_float2();
     $time = $time_end - $time_start;
     $cli->output("Sent " . $robinCounter . " emails in " . number_format($time, 3) . " seconds with " . $serverlist[$active_server]['host']);
     $cli->output("Average speed: " . number_format((double) 60.0 * (double) $robinCounter / (double) $time, 3) . " emails/minute");
     $robinCounter = 0;
     $active_server = nextConnection($active_server, $serverlist, $i + 1);
     $time_start = microtime_float2();
 }
 if (eZMail::validate($from) && eZMail::validate($to)) {
     $robinCounter++;
 }
Exemplo n.º 12
0
 private function rotateLog($fileName)
 {
     for ($i = $this->maxLogRotateFiles; $i > 0; --$i) {
         $logRotateName = $fileName . '.' . $i;
         if (@file_exists($logRotateName)) {
             if ($i == $this->maxLogRotateFiles) {
                 @unlink($logRotateName);
             } else {
                 $newLogRotateName = $fileName . '.' . ($i + 1);
                 eZFile::rename($logRotateName, $newLogRotateName);
             }
         }
     }
     if (@file_exists($fileName)) {
         $newLogRotateName = $fileName . '.' . 1;
         eZFile::rename($fileName, $newLogRotateName);
         return true;
     }
     return false;
 }
$appsDir = glob($oldAppsDir . '/*', GLOB_ONLYDIR);
foreach($appsDir as $appDir) {
    $parts = explode('/', rtrim($appDir, '/'));
    $appIdentifier = array_pop($parts);
    
    $icons = glob($appDir . '/ico*');
    foreach($icons as $icon) {
        $iconName = basename($icon);
        if (in_array($iconName, $iconsToMove)) {
            moveIfNeeded($icon, eZDir::path(array($newAppsDir, $appIdentifier, $iconName)));
        }
    }
}

if ($remove) {
    foreach(array_unique($fileToRemove) as $file) {
        eZFile::rename($file, 'var/image_refactor_save/' . ltrim($file, '/'), true, eZFile::APPEND_DEBUG_ON_FAILURE);

        $oldFolder = trim(dirname($file));
        $parts = explode('/', $oldFolder);
        $files = glob($oldFolder . '/*');

        if (count($parts) >= 5 && count($files) == 0) {
            $cli->notice('Remove ' . $oldFolder);
            rmdir($oldFolder);
        }
    }
}

$script->shutdown();
Exemplo n.º 14
0
 /**
  * Ends the cache generation started by startCacheGeneration().
  *
  * If $rename is set to true (default), the .generating file is renamed and
  * overwrites the real file.
  * If set to false, the .generating file is removed, and the real file made
  * available.
  *
  * True should be used when actual data is stored in the standard file and
  * not the .generating one, for instance when using image alias generation.
  *
  * @param bool $rename Rename (true) or delete (false) the generating file
  *
  * @return bool
  **/
 public function endCacheGeneration($rename = true)
 {
     eZDebug::accumulatorStart('dbfile', false, 'dbfile');
     $ret = false;
     eZDebugSetting::writeDebug("kernel-clustering", $this->realFilePath, __METHOD__);
     // rename the file to its final name
     if ($rename === true) {
         if (eZFile::rename($this->filePath, $this->realFilePath)) {
             $this->filePath = $this->realFilePath;
             $this->realFilePath = null;
             $this->remainingCacheGenerationTime = false;
             $ret = true;
         } else {
             eZLog::write("eZFS2FileHandler::endCacheGeneration: Failed renaming '{$this->filePath}' to '{$this->realFilePath}'", 'cluster.log');
         }
     } else {
         unlink($this->filePath);
         $this->filePath = $this->realFilePath;
         $this->realFilePath = null;
     }
     eZDebug::accumulatorStop('dbfile');
     return $ret;
 }
Exemplo n.º 15
0
 static function create($filename, $directory = false, $data = false, $atomic = false)
 {
     $filepath = $filename;
     if ($directory) {
         if (!file_exists($directory)) {
             eZDir::mkdir($directory, false, true);
             //                 eZDebugSetting::writeNotice( 'ezfile-create', "Created directory $directory", 'eZFile::create' );
         }
         $filepath = $directory . '/' . $filename;
     }
     // If atomic creation is needed we will use a temporary
     // file when writing the data, then rename it to the correct path.
     if ($atomic) {
         $realpath = $filepath;
         $dirname = dirname($filepath);
         if (strlen($dirname) != 0) {
             $dirname .= "/";
         }
         $filepath = $dirname . "ezfile-tmp." . md5($filepath . getmypid() . mt_rand());
     }
     $file = fopen($filepath, 'wb');
     if ($file) {
         //             eZDebugSetting::writeNotice( 'ezfile-create', "Created file $filepath", 'eZFile::create' );
         if ($data) {
             fwrite($file, $data);
         }
         fclose($file);
         if ($atomic) {
             eZFile::rename($filepath, $realpath);
         }
         return true;
     }
     //         eZDebugSetting::writeNotice( 'ezfile-create', "Failed creating file $filepath", 'eZFile::create' );
     return false;
 }
Exemplo n.º 16
0
 /**
  * Fetches the file $filePath from the database, saving it locally with its
  * original name, or $uniqueName if given
  *
  * @param string $filePath
  * @param string $uniqueName
  * @return the file physical path, or false if fetch failed
  */
 function _fetch($filePath, $uniqueName = false)
 {
     $metaData = $this->_fetchMetadata($filePath);
     if (!$metaData) {
         eZDebug::writeError("File '{$filePath}' does not exist while trying to fetch.", __METHOD__);
         return false;
     }
     $contentLength = $metaData['size'];
     $sql = "SELECT filedata, offset FROM " . TABLE_DATA . " WHERE name_hash=" . $this->_md5($filePath) . " ORDER BY offset";
     if (!($res = $this->_query($sql, "_fetch({$filePath})"))) {
         eZDebug::writeError("Failed to fetch file data for file '{$filePath}'.", __METHOD__);
         return false;
     }
     if (!mysql_num_rows($res)) {
         eZDebug::writeError("No rows in file '{$filePath}' being fetched.", __METHOD__);
         mysql_free_result($res);
         return false;
     }
     // create temporary file
     if (strrpos($filePath, '.') > 0) {
         $tmpFilePath = substr_replace($filePath, getmypid() . 'tmp', strrpos($filePath, '.'), 0);
     } else {
         $tmpFilePath = $filePath . '.' . getmypid() . 'tmp';
     }
     $this->__mkdir_p(dirname($tmpFilePath));
     if (!($fp = fopen($tmpFilePath, 'wb'))) {
         eZDebug::writeError("Cannot write to '{$tmpFilePath}' while fetching file.", __METHOD__);
         return false;
     }
     $offset = 0;
     while ($row = mysql_fetch_row($res)) {
         $expectedOffset = $row[1];
         if ($expectedOffset != $offset) {
             eZDebug::writeError("The fetched offset value '{$expectedOffset}' does not match the computed one for the file '{$filePath}', aborting fetch.", __METHOD__);
             fclose($fp);
             @unlink($filePath);
             return false;
         }
         fwrite($fp, $row[0]);
         $offset += strlen($row[0]);
     }
     if ($offset != $contentLength) {
         eZDebug::writeError("The size of the fetched data '{$offset}' does not match the expected size '{$contentLength}' for the file '{$filePath}', aborting fetch.", __METHOD__);
         fclose($fp);
         @unlink($filePath);
         return false;
     }
     fclose($fp);
     // Make sure all data is written correctly
     clearstatcache();
     $tmpSize = filesize($tmpFilePath);
     if ($tmpSize != $metaData['size']) {
         eZDebug::writeError("Size ({$tmpSize}) of written data for file '{$tmpFilePath}' does not match expected size " . $metaData['size'], __METHOD__);
         return false;
     }
     if (!$uniqueName === true) {
         eZFile::rename($tmpFilePath, $filePath, false, eZFile::CLEAN_ON_FAILURE | eZFile::APPEND_DEBUG_ON_FAILURE);
     } else {
         $filePath = $tmpFilePath;
     }
     mysql_free_result($res);
     return $filePath;
 }
Exemplo n.º 17
0
 /**
  * @group ezfile
  * @group ezfilerename
  */
 public function testRenameFailsWithFlags()
 {
     self::assertFalse(@eZFile::rename($this->file, "/non/existing/dir/file.txt", false, eZFile::CLEAN_ON_FAILURE | eZFile::APPEND_DEBUG_ON_FAILURE));
     self::assertFalse(file_exists($this->file));
     // Note: can't test that debug has been properly called here...
 }
Exemplo n.º 18
0
 static function doRename( $destinationFilename, $sourceFilename )
 {
     return eZFile::rename( $sourceFilename, $destinationFilename );
 }
Exemplo n.º 19
0
 /**
  * Fetches the file $filePath from the database to its own name
  *
  * Saving $filePath locally with its original name, or $uniqueName if given
  *
  * @param string $filePath
  * @param bool|string $uniqueName Alternative name to save the file to
  * @return string|bool the file physical path, or false if fetch failed
  */
 public function _fetch($filePath, $uniqueName = false)
 {
     $metaData = $this->_fetchMetadata($filePath);
     if (!$metaData) {
         // @todo Throw an exception
         eZDebug::writeError("File '{$filePath}' does not exist while trying to fetch.", __METHOD__);
         return false;
     }
     $dfsFileSize = $this->dfsbackend->getDfsFileSize($filePath);
     $loopCount = 0;
     $localFileSize = 0;
     do {
         // create temporary file
         $tmpid = getmypid() . '-' . mt_rand() . 'tmp';
         if (strrpos($filePath, '.') > 0) {
             $tmpFilePath = substr_replace($filePath, $tmpid, strrpos($filePath, '.'), 0);
         } else {
             $tmpFilePath = $filePath . '.' . $tmpid;
         }
         $this->__mkdir_p(dirname($tmpFilePath));
         eZDebugSetting::writeDebug('kernel-clustering', "copying DFS://{$filePath} to FS://{$tmpFilePath} on try: {$loopCount} ");
         // copy DFS file to temporary FS path
         // @todo Throw an exception
         if (!$this->dfsbackend->copyFromDFS($filePath, $tmpFilePath)) {
             eZDebug::writeError("Failed copying DFS://{$filePath} to FS://{$tmpFilePath} ");
             usleep(self::TIME_UNTIL_RETRY);
             ++$loopCount;
             continue;
         }
         if ($uniqueName !== true) {
             eZFile::rename($tmpFilePath, $filePath, false, eZFile::CLEAN_ON_FAILURE | eZFile::APPEND_DEBUG_ON_FAILURE);
         }
         $filePath = $uniqueName ? $tmpFilePath : $filePath;
         // If all data has been written correctly, return the filepath.
         // Otherwise let the loop continue
         clearstatcache(true, $filePath);
         $localFileSize = filesize($filePath);
         if ($dfsFileSize == $localFileSize) {
             return $filePath;
         }
         usleep(self::TIME_UNTIL_RETRY);
         ++$loopCount;
     } while ($dfsFileSize > $localFileSize && $loopCount < $this->maxCopyTries);
     // Copy from DFS has failed :-(
     eZDebug::writeError("Size ({$localFileSize}) of written data for file '{$tmpFilePath}' does not match expected size {$metaData['size']}", __METHOD__);
     unlink($tmpFilePath);
     return false;
 }
Exemplo n.º 20
0
    static function renameDir( $dir )
    {
        // just rename. Actual removing will be performed by cronjob.

        // This directory renaming is only performed on the local filesystem
        // to ensure purging of really old data. If the DB file handler is in
        // use it will check the modified_subnode field of the tree structure
        // to determin expiry when the cache-block entry is accessed.
        if ( file_exists( $dir ) )
        {
            if ( is_dir( $dir ) )
            {
                $expiryCacheDir = eZTemplateCacheFunction::expiryTemplateBlockCacheDir();

                $uniqid = md5( uniqid( 'ezpsubtreecache'. getmypid(), true ) );
                $expiryCacheDir .= '/' . $uniqid[0] . '/' . $uniqid[1] . '/' . $uniqid[2] . '/' . $uniqid;

                if ( !file_exists( $expiryCacheDir ) )
                {
                    eZDir::mkdir( $expiryCacheDir, false, true );
                }
                eZFile::rename( $dir, $expiryCacheDir, false, eZFile::APPEND_DEBUG_ON_FAILURE );
            }
            else
            {
                eZDebug::writeWarning( "$dir should be a directory. Template-block caches for 'subtree_expiry' are not removed.", __METHOD__ );
            }
        }
    }
Exemplo n.º 21
0
    /**
     * Stores the cache file $file with contents $content.
     * Takes care of setting proper permissions on the new file.
     *
     * @param string $file
     * @param string $content
     */
    static function storeCachedFile( $file, $content )
    {
        $dir = dirname( $file );
        if ( !is_dir( $dir ) )
        {
            eZDir::mkdir( $dir, false, true );
        }

        $oldumask = umask( 0 );

        $tmpFileName = $file . '.' . md5( $file. uniqid( "ezp". getmypid(), true ) );

        // Remove files, this might be necessary for Windows
        @unlink( $tmpFileName );

        // Write the new cache file with the data attached
        $fp = fopen( $tmpFileName, 'w' );
        if ( $fp )
        {
            $comment = ( eZINI::instance( 'staticcache.ini' )->variable( 'CacheSettings', 'AppendGeneratedTime' ) === 'true' ) ? "<!-- Generated: " . date( 'Y-m-d H:i:s' ). " -->\n\n" : null;

            fwrite( $fp, $content . $comment );
            fclose( $fp );
            eZFile::rename( $tmpFileName, $file, false, eZFile::CLEAN_ON_FAILURE | eZFile::APPEND_DEBUG_ON_FAILURE );

            $perm = eZINI::instance()->variable( 'FileSettings', 'StorageFilePermissions' );
            chmod( $file, octdec( $perm ) );
        }

        umask( $oldumask );
    }
Exemplo n.º 22
0
 static function rotateLog($fileName)
 {
     $maxLogrotateFiles = eZDebug::maxLogrotateFiles();
     if ($maxLogrotateFiles == 0) {
         return;
     }
     for ($i = $maxLogrotateFiles; $i > 0; --$i) {
         $logRotateName = $fileName . '.' . $i;
         if (file_exists($logRotateName)) {
             if ($i == $maxLogrotateFiles) {
                 @unlink($logRotateName);
             } else {
                 $newLogRotateName = $fileName . '.' . ($i + 1);
                 eZFile::rename($logRotateName, $newLogRotateName);
             }
         }
     }
     if (file_exists($fileName)) {
         $newLogRotateName = $fileName . '.' . 1;
         eZFile::rename($fileName, $newLogRotateName);
         return true;
     }
     return false;
 }
Exemplo n.º 23
0
    /**
     * Ends the cache generation started by startCacheGeneration().
     *
     * If $rename is set to true (default), the .generating file is renamed and
     * overwrites the real file.
     * If set to false, the .generating file is removed, and the real file made
     * available.
     *
     * True should be used when actual data is stored in the standard file and
     * not the .generating one, for instance when using image alias generation.
     *
     * @param bool $rename Rename (true) or delete (false) the generating file
     *
     * @return bool
     */
    public function endCacheGeneration( $rename = true)
    {
        if ( $this->realFilePath === null )
        {
            $this->loadMetaData();
            eZDebugSetting::writeDebug( 'kernel-clustering', "$this->filePath is not generating", "fs2::endCacheGeneration( '{$this->filePath}' )" );
            return false;
        }

        eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );

        $ret = false;
        eZDebugSetting::writeDebug( "kernel-clustering", $this->realFilePath, __METHOD__ );

        // rename the file to its final name
        if ( $rename === true )
        {
            if ( eZFile::rename( $this->filePath, $this->realFilePath, false, eZFile::CLEAN_ON_FAILURE ) )
            {
                $this->filePath = $this->realFilePath;
                $this->realFilePath = null;
                eZClusterFileHandler::removeGeneratingFile( $this );
                $this->remainingCacheGenerationTime = false;
                $ret = true;
                $this->loadMetaData();
            }
            else
            {
                eZLog::write( "eZFS2FileHandler::endCacheGeneration: Failed renaming '$this->filePath' to '$this->realFilePath'", 'cluster.log' );
            }
        }
        else
        {
            unlink( $this->filePath );
            $this->filePath = $this->realFilePath;
            $this->realFilePath = null;
            $this->loadMetaData();
        }

        eZDebug::accumulatorStop( 'dbfile' );

        return $ret;
    }