Beispiel #1
0
 public function generate()
 {
     set_error_handler(array($this, 'errorHandler'), E_WARNING);
     try {
         $this->_reportFile->status = Reports_File::STATUS_IN_PROGRESS;
         $this->_reportFile->save();
         $this->_report = $this->_reportFile->getReport();
         $this->_params = reports_convert_search_filters(unserialize($this->_report->query));
         // Creates a random filename based on the type of report.
         $filter = new Omeka_Filter_Filename();
         $filename = $filter->renameFile('report.' . $this->getExtension());
         // Generates the report (passes to subclass)
         $tempFilePath = tempnam($this->_storage->getTempDir(), 'reports');
         $tempFilePath = $this->generateReport($tempFilePath);
         // Store the report
         $destPath = $this->_storagePrefixDir . '/' . $filename;
         $this->_storage->store($tempFilePath, $destPath);
         $this->_reportFile->status = Reports_File::STATUS_COMPLETED;
         $this->_reportFile->filename = $filename;
     } catch (Exception $e) {
         $this->_reportFile->status = Reports_File::STATUS_ERROR;
         $this->_addStatusMessage('storagePrefixDir: ' . $this->_storagePrefixDir . ' filename: ' . $filename . ' error:' . $e->getMessage(), 'Error');
         _log($e, Zend_Log::ERR);
     }
     $this->_reportFile->save();
 }
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
 /**
  * Test using the magic calling for adapter methods with no adapter.
  *
  * @expectedException Omeka_Storage_Exception
  */
 public function testStoreWithNoAdapter()
 {
     $storage = new Omeka_Storage();
     $storage->store('path', 'destination');
 }