public function setUp() { try { if (file_exists('/tmp/lucene')) { ezcBaseFile::removeRecursive('/tmp/lucene'); } mkdir('/tmp/lucene'); $this->backend = new ezcSearchZendLuceneHandler("/tmp/lucene"); } catch (ezcSearchCanNotConnectException $e) { self::markTestSkipped('Couldn\'t open Zend Lucene.'); } $this->testFilesDir = dirname(__FILE__) . '/../testfiles/'; }
protected function setUp() { // truncates the ezsi_file table $db = eZDB::instance(); $sql = 'TRUNCATE TABLE ' . self::SI_BLOCK_TABLE_NAME; if (!$db->query($sql)) { return false; } // removes files in the si-block directory if (is_dir(realpath(self::SI_BLOCK_STORAGE_DIR))) { try { ezcBaseFile::removeRecursive(self::SI_BLOCK_STORAGE_DIR); } catch (Exception $e) { echo 'Got Exception message : ' . $e->getMessage() . "\n"; return false; } } }
/** * Clears all static cache for a site * Removers all static cache, but not the static cache directory itself. * * Currently, this function only supports 'combined_host_url' * */ static function clearStaticCache() { $ini = eZINI::instance('staticcache.ini'); $storageDir = $ini->variable('CacheSettings', 'StaticStorageDir'); // Check that we have combined_host_url hostmatching $siteIni = eZINI::instance(); $matchType = $siteIni->variable('SiteAccessSettings', 'MatchOrder'); if ($matchType !== 'combined_host_url') { throw new Exception('combined_host_url required for this workflow'); } global $eZCurrentAccess; $siteAccess = $eZCurrentAccess['name']; //Get hostname part from siteaccess name (exclude for instance _eng or _admin) if (strpos($siteAccess, '_') === false) { $hostName = $siteAccess; } else { $hostName = substr($siteAccess, 0, strpos($siteAccess, '_')); } $staticCacheDir = eZDir::path(array($storageDir, $hostName)); // Sanity checking, make sure we don't remove everyones static cache. if ($staticCacheDir == $storageDir) { throw new Exception("Failed to find correct static cache directory : {$staticCacheDir} \n"); } $dirs = scandir($staticCacheDir); foreach ($dirs as $dir) { if ($dir !== '.' && $dir !== '..') { $fullPath = eZDir::path(array($staticCacheDir, $dir)); if (is_dir($fullPath)) { ezcBaseFile::removeRecursive($fullPath); } else { if (!unlink($fullPath)) { throw new ezsfFileCouldNotRemoveException($fullPath); } } } } }
/** * Deletes everything below a path. * * Deletes the resource identified by $path recursively. Returns an * instance of {@link ezcWebdavErrorResponse} if the deletion failed, and * null on success. * * @param string $path * @return ezcWebdavErrorResponse */ protected function performDelete($path) { $errors = $this->checkDeleteRecursive($this->root . $path); // If an error will occur return the proper status. We return // multistatus in any case. if (count($errors)) { return new ezcWebdavMultistatusResponse($errors); } // Just delete otherwise if (is_file($this->root . $path)) { unlink($this->root . $path); } else { ezcBaseFile::removeRecursive($this->root . $path); } // Finally empty property storage for removed node $storagePath = $this->getPropertyStoragePath($path); if (is_file($storagePath)) { unlink($storagePath); } return null; }
/** * Resets the whole storage. * * Deletes all data in the storage including {@link ezcCacheStackMetaData} * that was stored using {@link storeMetaData()}. */ public function reset() { $files = glob("{$this->properties['location']}*"); foreach ($files as $file) { if (is_dir($file)) { ezcBaseFile::removeRecursive($file); } else { if (@unlink($file) === false) { throw new ezcBaseFilePermissionException($file, ezcBaseFileException::REMOVE, 'Could not unlink cache file.'); } } } }
public function testRecursiveNotWritableParent() { self::assertEquals(15, count(ezcBaseFile::findRecursive($this->tempDir))); try { ezcBaseFile::removeRecursive($this->tempDir . '/dir7/dir1'); } catch (ezcBaseFilePermissionException $e) { self::assertEquals("The file '{$this->tempDir}/dir7' can not be opened for writing.", $e->getMessage()); } self::assertEquals(15, count(ezcBaseFile::findRecursive($this->tempDir))); }
ezcBaseFile::removeRecursive('var/tmpfiles/backupfiles'); if (!file_exists('var/tmpfiles/backupfiles')) { mkdir('var/tmpfiles/backupfiles'); mkdir('var/tmpfiles/backupfiles/design'); } $zip->extractTo('var/tmpfiles/update'); $zip->close(); $foldersSwitch = array('doc', 'ezcomponents', 'lib', 'modules', 'pos', 'translations', 'design/backendtheme', 'design/defaulttheme'); echo "Switching folders\n"; foreach ($foldersSwitch as $folder) { rename($folder, 'var/tmpfiles/backupfiles/' . $folder . '_' . $date); rename('var/tmpfiles/update/livehelperchat-master/lhc_web/' . $folder, $folder); } unlink('var/tmpfiles/master.zip'); echo "Your old folders can be found - var/tmpfiles/backupfiles\n"; ezcBaseFile::removeRecursive('var/tmpfiles/update'); $jsonObject = json_decode(erLhcoreClassModelChatOnlineUser::executeRequest('https://raw.githubusercontent.com/LiveHelperChat/livehelperchat/master/lhc_web/doc/update_db/structure.json'), true); echo "----------------\nUpdating database\n----------------\n"; if (is_array($jsonObject)) { $errorMessages = erLhcoreClassUpdate::doTablesUpdate($jsonObject); if (empty($errorMessages)) { $CacheManager = erConfigClassLhCacheConfig::getInstance(); $CacheManager->expireCache(); echo "UPDATE DONE\n"; } else { echo "ERROR:\n" . implode("\n", $errorMessages); } } } else { echo "Could not download archive!!!"; }
public function doSourcefileArchive() { $result = new ezcMvcResult(); $nonExistingFiles = array(); $hash = $this->hash; if ( $queueItem = mmMergeOperation::fetchByHash( $hash ) ) { $status = 'ok'; $message = ''; $removed = array(); $command = $queueItem->commandObject; if ( $command->conversionType == 'tvshow' ) { $files = array_merge( $command->VideoFiles, $command->SubtitleFiles ); foreach( $files as $file ) { $extension = pathinfo( $file['pathname'], PATHINFO_EXTENSION ); if ( ( $extension == 'mkv' or $extension == 'avi' ) && file_exists( $file['pathname']) && filesize( $file['pathname'] ) == 0 ) { $result->variables['status'] = 'ko'; $result->variables['message'] = 'already_archived'; return $result; } if ( !file_exists( $file['pathname'] ) ) { $nonExistingFiles[] = $file; } else { if ( !isset( $dummyFile ) ) $dummyFile = $file['pathname']; $removed[] = $file['pathname']; unlink( $file['pathname'] ); } } touch( $dummyFile ); } else { $mainFile = $command->VideoFiles[0]['pathname']; if ( file_exists( $mainFile ) ) { $directory = dirname( $mainFile ); $files[] = glob( "$directory/*" ); try { ezcBaseFile::removeRecursive( $directory ); $removed = $files; } catch( ezcBaseFilePermissionException $e ) { $status = 'ko'; $message = $e->getMessage(); } } } if ( !empty( $nonExistingFiles ) ) $result->variables['messages'] = 'Some files were not found, see [not_found_files]'; if ( $status === 'ok' ) { $queueItem->status = mmMergeOperation::STATUS_ARCHIVED; ezcPersistentSessionInstance::get()->update( $queueItem ); } $result->variables['status'] = $status; $result->variables['removed_files'] = $removed; $result->variables['not_found_files'] = $nonExistingFiles; $result->variables['message'] = $message; } else { // @todo Handle with exception $result->variables['status'] = 'ko'; $result->variables['message'] = "No operation with hash $hash"; } return $result; }
public function testRecursive5() { self::assertEquals(12, count(ezcBaseFile::findRecursive($this->tempDir))); try { ezcBaseFile::removeRecursive($this->tempDir . '/dir6'); } catch (ezcBaseFilePermissionException $e) { self::assertEquals("The file '{$this->tempDir}/dir6/file1.txt' can not be removed.", $e->getMessage()); } self::assertEquals(12, count(ezcBaseFile::findRecursive($this->tempDir))); }
<?php require 'tutorial_autoload.php'; ezcBaseFile::removeRecursive('/dat/dev/ezcomponents/trash');
public function testRecursive5() { self::assertEquals(12, count(ezcBaseFile::findRecursive($this->tempDir))); try { ezcBaseFile::removeRecursive($this->tempDir . '/dir6'); } catch (ezcBaseFilePermissionException $e) { // Make no asumption on which file is tryed to be removed first self::assertEquals(1, preg_match("(The file '{$this->tempDir}/dir6/file[12].txt' can not be removed.)", $e->getMessage())); } self::assertEquals(12, count(ezcBaseFile::findRecursive($this->tempDir))); }