コード例 #1
0
ファイル: FilesystemTest.php プロジェクト: emhoracek/Omeka
 /**
  * @dataProvider localDirs
  */
 public function testMove($localDir, $throwsException)
 {
     if (!$localDir) {
         $localDir = self::$tempDir;
     }
     $storage = new Omeka_Storage_Adapter_Filesystem(array('localDir' => $localDir));
     $testFile = tempnam(self::$tempDir, 'omeka_storage_filesystem_test');
     try {
         $storage->move(basename($testFile), 'foo.txt');
         $this->assertTrue(file_exists("{$localDir}/foo.txt"));
         if ($throwsException) {
             $this->fail();
         }
     } catch (Omeka_Storage_Exception $e) {
         if (!$throwsException) {
             $this->fail($e->getMessage());
         }
     }
 }
コード例 #2
0
 /**
  * Moves/renames a file and its derivatives inside archive/files subfolders.
  *
  * New folders are created if needed. Old folders are removed if empty.
  * No update of the database is done.
  *
  * @param string $currentArchiveFilename
  *   Name of the current archive file to move.
  * @param string $newArchiveFilename
  *   Name of the new archive file, with archive folder if any (usually
  *   "collection/dc:identifier/").
  * @param optional string $derivativeExtension
  *   Extension of the derivative files to move, because it can be different
  *   from the new archive filename and it can't be determined here.
  *
  * @return boolean
  *   true if files are moved, else false.
  */
 protected function _moveFilesInArchiveSubfolders($currentArchiveFilename, $newArchiveFilename, $derivativeExtension = '')
 {
     // A quick check to avoid some errors.
     if (trim($currentArchiveFilename) == '' || trim($newArchiveFilename) == '') {
         return false;
     }
     // Move file only if it is not in the right place.
     // If the main file is at the right place, this is always the case for
     // the derivatives.
     if ($currentArchiveFilename == $newArchiveFilename) {
         return true;
     }
     $currentArchiveFolder = dirname($currentArchiveFilename);
     $newArchiveFolder = dirname($newArchiveFilename);
     // Move the main original file using Omeka API.
     $result = $this->_createArchiveFolders($newArchiveFolder, $this->_getFullArchivePath('original'));
     $operation = new Omeka_Storage_Adapter_Filesystem(array('localDir' => $this->_getFullArchivePath('original')));
     $operation->move($currentArchiveFilename, $newArchiveFilename);
     // If any, move derivative files using Omeka API.
     if ($derivativeExtension != '') {
         foreach ($this->_getFullArchivePaths() as $derivativeType => $path) {
             // Original is managed above.
             if ($derivativeType == 'original') {
                 continue;
             }
             // We create a folder in any case, even if there isn't any file
             // inside, in order to be fully compatible with any plugin that
             // manages base filename only.
             $result = $this->_createArchiveFolders($newArchiveFolder, $path);
             // Determine the current and new derivative filename, standard
             // or not.
             $currentDerivativeFilename = $this->_getDerivativeFilename($currentArchiveFilename, $derivativeExtension, $derivativeType);
             $newDerivativeFilename = $this->_getDerivativeFilename($newArchiveFilename, $derivativeExtension, $derivativeType);
             // Check if the derivative file exists or not to avoid some
             // errors when moving.
             if (file_exists($path . DIRECTORY_SEPARATOR . $currentDerivativeFilename)) {
                 $operation = new Omeka_Storage_Adapter_Filesystem(array('localDir' => $path));
                 $operation->move($currentDerivativeFilename, $newDerivativeFilename);
             }
         }
     }
     // Remove all old empty folders.
     if ($currentArchiveFolder != $newArchiveFolder) {
         $this->_removeArchiveFolders($currentArchiveFolder);
     }
     return true;
 }
コード例 #3
0
ファイル: TempFilesystem.php プロジェクト: lchen01/STEdwards
 /**
  * Move a file between two "storage" locations.
  *
  * @param string $source Original stored path.
  * @param string $dest Destination stored path.
  */
 public function move($source, $dest)
 {
     $this->_mkdir($dest);
     return parent::move($source, $dest);
 }