Beispiel #1
0
 public function testTempDirCustom()
 {
     $storage = new Omeka_Storage();
     $customDir = '/';
     $storage->setTempDir($customDir);
     $this->assertEquals($customDir, $storage->getTempDir());
 }
Beispiel #2
0
 /**
  * Perform this job.
  */
 public function perform()
 {
     // Fetch file IDs according to the passed options.
     $select = $this->_db->select()->from($this->_db->File, array('id'));
     if ('has_derivative' == $this->_options['process_type']) {
         $select->where('has_derivative_image = 1');
     } else {
         if ('has_no_derivative' == $this->_options['process_type']) {
             $select->where('has_derivative_image = 0');
         }
     }
     if (is_array($this->_options['mime_types'])) {
         $select->where('mime_type IN (?)', $this->_options['mime_types']);
     }
     $fileIds = $select->query()->fetchAll(Zend_Db::FETCH_COLUMN);
     // Iterate files and create derivatives.
     foreach ($fileIds as $fileId) {
         $file = get_record_by_id('file', $fileId);
         // Register which image derivatives to create.
         foreach ($this->_derivatives as $type => $constraint) {
             $this->_imageCreator->addDerivative($type, $constraint);
         }
         // Create derivatives.
         try {
             $imageCreated = $this->_imageCreator->create(FILES_DIR . '/' . $file->getStoragePath('original'), $file->getDerivativeFilename(), $file->mime_type);
         } catch (Exception $e) {
             _log($e);
             $imageCreated = false;
         }
         // Confirm that the file was derivable.
         if (!$imageCreated) {
             continue;
         }
         // Save the file record.
         $file->has_derivative_image = 1;
         $file->save();
         // Delete existing derivative images and replace them with the
         // temporary ones made during image creation above.
         foreach ($this->_derivatives as $type => $constraint) {
             $this->_storage->delete($file->getStoragePath($type));
             $source = FILES_DIR . "/original/{$type}_" . $file->getDerivativeFilename();
             $this->_storage->store($source, $file->getStoragePath($type));
         }
         // Release the file record to prevent memory leaks.
         release_object($file);
     }
 }
Beispiel #3
0
 /**
  * Returns whether the report can be stored in the associated Omeka_Storage object
  *
  * @param array &$errors The array of errors for why a file cannot store
  * @return bool whether the report can be stored in the associated Omeka_Storage object  
  */
 public function canStore(&$errors)
 {
     // this is a hack because Omeka_Storage_Adapter_Filesystem
     // does not correctly implement canStore when the localDir
     // has been changed. It also offers no way to remove the subDirs
     // we don't use or care about.
     // So we must directly test whether the directory we plan to write to is writeable
     $ad = $this->_storage->getAdapter();
     if ($ad instanceof Omeka_Storage_Adapter_Filesystem) {
         $opt = $ad->getOptions();
         $localDir = $opt['localDir'];
         $absPath = $localDir . '/' . $this->_storagePrefixDir;
         // this reimplements Omeka_Storage_Adapter_Filesystem::_getAbsPath
         $result = is_writable($absPath);
         if (!$result) {
             if (!$errors) {
                 $errors = array();
             }
             $errors[] = __("Make sure that %s is exists and is writeable.", $absPath);
         }
         return $result;
     }
     return $this->_storage->canStore();
 }