Example #1
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);
     }
 }
Example #2
0
 public function deleteFile($filename)
 {
     $destPath = $this->_storagePrefixDir . '/' . $filename;
     $this->_storage->delete($destPath);
 }