function store($sub_dir = false, $suffix = false, $mimeData = false) { if (!$this->IsTemporary) { eZDebug::writeError("Cannot store non temporary file: " . $this->Filename, "eZHTTPFile"); return false; } $this->IsTemporary = false; $ini = eZINI::instance(); // $storage_dir = $ini->variable( "FileSettings", "VarDir" ) . '/' . $ini->variable( "FileSettings", "StorageDir" ); $storage_dir = eZSys::storageDirectory(); if ($sub_dir !== false) { $dir = $storage_dir . "/{$sub_dir}/"; } else { $dir = $storage_dir . "/"; } if ($mimeData) { $dir = $mimeData['dirpath']; } if (!$mimeData) { $dir .= $this->MimeCategory; } if (!file_exists($dir)) { if (!eZDir::mkdir($dir, false, true)) { return false; } } $suffixString = false; if ($suffix != false) { $suffixString = ".{$suffix}"; } if ($mimeData) { $dest_name = $mimeData['url']; } else { $dest_name = $dir . "/" . md5(basename($this->Filename) . microtime() . mt_rand()) . $suffixString; } if (!move_uploaded_file($this->Filename, $dest_name)) { eZDebug::writeError("Failed moving uploaded file " . $this->Filename . " to destination {$dest_name}"); unlink($dest_name); $ret = false; } else { $ret = true; $this->Filename = $dest_name; $perm = $ini->variable("FileSettings", "StorageFilePermissions"); $oldumask = umask(0); chmod($dest_name, octdec($perm)); umask($oldumask); // Write log message to storage.log $storageDir = $dir . "/"; eZLog::writeStorageLog(basename($this->Filename), $storageDir); } return $ret; }
function loadCache($reset = true, $placement = false) { eZDebug::accumulatorStart('ini', 'ini_load', 'Load cache'); if ($reset) { $this->reset(); } $cachedDir = self::CONFIG_CACHE_DIR; $inputFileTime = 0; $fileName = $this->cacheFileName($placement); $cachedFile = $cachedDir . $fileName; if ($placement) { $this->PlacementCacheFile = $cachedFile; } else { $this->CacheFile = $cachedFile; } $loadCache = false; if (file_exists($cachedFile)) { $loadCache = true; } $useCache = false; if ($loadCache) { $useCache = true; if (eZINI::isDebugEnabled()) { eZDebug::writeNotice("Loading cache '{$cachedFile}' for file '" . $this->FileName . "'", __METHOD__); } include $cachedFile; if (!isset($data) || !isset($data['rev']) || $data['rev'] != eZINI::CONFIG_CACHE_REV) { if (eZINI::isDebugEnabled()) { eZDebug::writeNotice("Old structure in cache file used, recreating '{$cachedFile}' to new structure", __METHOD__); } unset($data); $this->reset(); $useCache = false; } else { if (self::$checkFileMtime === true || self::$checkFileMtime === $this->FileName) { eZDebug::accumulatorStart('ini_check_mtime', 'ini_load', 'Check MTime'); $currentTime = time(); $cacheCreatedTime = strtotime($data['created']); $iniFile = $data['file']; $inputFiles = $data['files']; foreach ($inputFiles as $inputFile) { $fileTime = filemtime($inputFile); if ($currentTime < $fileTime) { eZDebug::writeError('Input file "' . $inputFile . '" has a timestamp higher then current time, ignoring to avoid infinite recursion!', __METHOD__); } else { if ($fileTime === false || $fileTime > $cacheCreatedTime) { unset($data); $this->reset(); $useCache = false; break; } } } eZDebug::accumulatorStop('ini_check_mtime'); } } } if ($useCache && isset($data)) { $this->Charset = $data['charset']; $this->ModifiedBlockValues = array(); if ($placement) { $this->BlockValuesPlacement = $data['val']; } else { $this->BlockValues = $data['val']; } unset($data); } else { if (!isset($inputFiles)) { eZDebug::accumulatorStart('ini_find_files', 'ini_load', 'Find INI Files'); $this->findInputFiles($inputFiles, $iniFile); eZDebug::accumulatorStop('ini_find_files'); if (count($inputFiles) === 0) { eZDebug::accumulatorStop('ini'); return false; } } eZDebug::accumulatorStart('ini_files_parse', 'ini_load', 'Parse'); $this->parse($inputFiles, $iniFile, false, $placement); eZDebug::accumulatorStop('ini_files_parse'); eZDebug::accumulatorStart('ini_files_save', 'ini_load', 'Save Cache'); $cacheSaved = $this->saveCache($cachedDir, $cachedFile, $placement ? $this->BlockValuesPlacement : $this->BlockValues, $inputFiles, $iniFile); eZDebug::accumulatorStop('ini_files_save'); if ($cacheSaved) { // Write log message to storage.log eZLog::writeStorageLog($fileName, $cachedDir); } } eZDebug::accumulatorStop('ini'); }
/** * Will load a cached version of the ini file if it exists, * if not it will parse the original file and create the cache file. * * @access protected * @internal Please use {@link eZINI::load()} or {@link eZINI::loadPlacement()} * @param bool $reset Reset ini values on instance * @param bool $placement Load cache for placment info, not the ini values themself. */ function loadCache( $reset = true, $placement = false ) { eZDebug::accumulatorStart( 'ini', 'Ini load', 'Load cache' ); if ( $reset ) $this->reset(); $cachedDir = self::CONFIG_CACHE_DIR; $fileName = $this->cacheFileName( $placement ); $cachedFile = $cachedDir . $fileName; if ( $placement ) { $this->PlacementCacheFile = $cachedFile; } else { $this->CacheFile = $cachedFile; } $data = false;// this will contain cache data if cache data is valid if ( file_exists( $cachedFile ) ) { if ( self::isDebugEnabled() ) eZDebug::writeNotice( "Loading cache '$cachedFile' for file '" . $this->FileName . "'", __METHOD__ ); include( $cachedFile ); if ( !isset( $data['rev'] ) || $data['rev'] != eZINI::CONFIG_CACHE_REV ) { if ( self::isDebugEnabled() ) eZDebug::writeNotice( "Old structure in cache file used, recreating '$cachedFile' to new structure", __METHOD__ ); $data = false; $this->reset(); } else if ( self::$checkFileMtime === true || self::$checkFileMtime === $this->FileName ) { eZDebug::accumulatorStart( 'ini_check_mtime', 'Ini load', 'Check MTime' ); $currentTime = time(); $cacheCreatedTime = strtotime( $data['created'] ); $iniFile = $data['file'];// used by findInputFiles further down $inputFiles = $data['files']; foreach ( $inputFiles as $inputFile ) { $fileTime = file_exists( $inputFile ) ? filemtime( $inputFile ) : false; if ( $fileTime === false )// Refresh cache & input files if file is gone { unset( $inputFiles ); $data = false; $this->reset(); break; } else if ( $fileTime > $currentTime ) { eZDebug::writeError( 'Input file "' . $inputFile . '" has a timestamp higher then current time, ignoring to avoid infinite recursion!', __METHOD__ ); } else if ( $fileTime > $cacheCreatedTime )// Refresh cache if file has been changed { $data = false; $this->reset(); break; } } eZDebug::accumulatorStop( 'ini_check_mtime' ); } } if ( $data )// if we have cache data on this point, use it { $this->Charset = $data['charset']; $this->ModifiedBlockValues = array(); if ( $placement ) $this->BlockValuesPlacement = $data['val']; else $this->BlockValues = $data['val']; unset( $data ); } else { if ( !isset( $inputFiles ) )// use $inputFiles from cache if defined { eZDebug::accumulatorStart( 'ini_find_files', 'Ini load', 'Find INI Files' ); $this->findInputFiles( $inputFiles, $iniFile ); eZDebug::accumulatorStop( 'ini_find_files' ); if ( count( $inputFiles ) === 0 ) { eZDebug::accumulatorStop( 'ini' ); return false; } } eZDebug::accumulatorStart( 'ini_files_parse', 'Ini load', 'Parse' ); $this->parse( $inputFiles, $iniFile, false, $placement ); eZDebug::accumulatorStop( 'ini_files_parse' ); eZDebug::accumulatorStart( 'ini_files_save', 'Ini load', 'Save Cache' ); $cacheSaved = $this->saveCache( $cachedDir, $cachedFile, $placement ? $this->BlockValuesPlacement : $this->BlockValues, $inputFiles, $iniFile ); eZDebug::accumulatorStop( 'ini_files_save' ); if ( $cacheSaved ) { // Write log message to storage.log eZLog::writeStorageLog( $fileName, $cachedDir ); } } eZDebug::accumulatorStop( 'ini' ); }
function store($atomic = false) { if ($this->open($atomic)) { $this->write("<?php\n"); $this->writeElements(); $this->write("?>\n"); $this->writeChunks(); $this->flushChunks(); $this->close(); if (!$this->ClusteringEnabled) { $perm = octdec(eZINI::instance()->variable('FileSettings', 'StorageFilePermissions')); chmod(eZDir::path(array($this->PHPDir, $this->PHPFile)), $perm); } // Write log message to storage.log eZLog::writeStorageLog($this->PHPFile, $this->PHPDir . '/'); return true; } else { eZDebug::writeError("Failed to open file '" . $this->PHPDir . '/' . $this->PHPFile . "'", 'eZPHPCreator::store'); return false; } }
/** * Delete files matching regex $fileRegex under directory $dir. * * \public * \static * \sa fileDeleteByWildcard() */ function fileDeleteByRegex($dir, $fileRegex) { eZDebugSetting::writeDebug('kernel-clustering', "fs::fileDeleteByRegex( '{$dir}', '{$fileRegex}' )", __METHOD__); eZDebug::accumulatorStart('dbfile', false, 'dbfile'); if (!file_exists($dir)) { //eZDebugSetting::writeDebug( 'kernel-clustering', "Dir '$dir' does not exist", __METHOD__ ); eZDebug::accumulatorStop('dbfile'); return; } $dirHandle = opendir($dir); if (!$dirHandle) { eZDebug::writeError("opendir( '{$dir}' ) failed."); eZDebug::accumulatorStop('dbfile'); return; } while (($file = readdir($dirHandle)) !== false) { if ($file == '.' or $file == '..') { continue; } if (preg_match("/^{$fileRegex}/", $file)) { //eZDebugSetting::writeDebug( 'kernel-clustering', "\$file = eZDir::path( array( '$dir', '$file' ) );", __METHOD__ ); $file = eZDir::path(array($dir, $file)); eZDebugSetting::writeDebug('kernel-clustering', "Removing cache file '{$file}'", __METHOD__); unlink($file); // Write log message to storage.log eZLog::writeStorageLog($file); } } closedir($dirHandle); eZDebug::accumulatorStop('dbfile'); }