示例#1
0
 public function testDelete()
 {
     $tempDir = self::$tempDir;
     $storage = new Omeka_Storage_Adapter_Filesystem(array('localDir' => $tempDir));
     $testFile = tempnam($tempDir, 'omeka_storage_filesystem_test');
     $storage->delete(basename($testFile));
     $this->assertFalse(file_exists($testFile));
     try {
         $storage->delete(basename($testFile));
     } catch (Omeka_Storage_Exception $e) {
         $this->fail('An exception was thrown for trying to delete a missing file');
     }
 }
 /**
  * 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
 /**
  * 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);
 }