Exemplo n.º 1
0
 /**
  * @param RokGallery_Model_Job $job
  * @return RokGallery_Job_Processor
  * @throws RokGallery_Job_Exception
  */
 public static function &factory(RokGallery_Job &$job)
 {
     $classname = 'RokGallery_Job_Processor_' . ucfirst(str_replace(' ', '', $job->getType()));
     if (!class_exists($classname, true)) {
         throw new RokGallery_Job_Exception(rc__('ROKGALLERY_UNABLE_TO_FIND_PROCESS_FOR_JOB_TYPE_N', $job->getType()));
     }
     $ret = new $classname($job);
     return $ret;
 }
Exemplo n.º 2
0
 /**
  * @static
  * @param  $type
  * @return rokGallery_Job
  */
 public static function &create($type)
 {
     try {
         $job = new RokGallery_Job();
         $job->_create($type);
         return $job;
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 3
0
 /**
  * Delete the file and all associated rows (done by foreign keys) and files
  * $params object should be a json like
  * <code>
  * {
  *  'id': 'xxxx-x-x-x-x-x-x'
  * }
  * </code>
  *
  * @param $params
  * @return RokCommon_Ajax_Result
  */
 public function file($params)
 {
     $result = new RokCommon_Ajax_Result();
     $tx = RokGallery_Doctrine::getConnection()->transaction;
     $tx->setIsolation('READ UNCOMMITTED');
     try {
         if (count($_FILES) == 0) {
             throw new RokGallery_Job_Exception(rc__('ROKGALLERY_NO_FILES_SENT'));
         }
         $job = RokGallery_Job::get($params->id);
         if ($job === false) {
             throw new RokCommon_Ajax_Exception(rc__('ROKGALLERY_UNABLE_TO_FIND_JOB', $params->id));
         }
         if ($job->getStateName() != RokGallery_Job::STATE_PREPPING) {
             throw new RokGallery_Job_Exception(rc__('ROKGALLERY_NOT_IN_PREPPING_STATUS'));
         }
         if ($job->getType() != RokGallery_Job::TYPE_IMPORT) {
             throw new RokGallery_Job_Exception(rc__('ROKGALLERY_NOT_AN_IMPORT_JOB'));
         }
         $job_properties = $job->getProperties();
         if (empty($job_properties)) {
             $job_properties = array();
         }
         $basepath = RokGallery_Config::getOption(RokGallery_Config::OPTION_JOB_QUEUE_PATH) . DS . $job->getId();
         if (!file_exists($basepath)) {
             @mkdir($basepath);
             RokGallery_Queue_DirectoryCreate::add($basepath);
         }
         if (!(file_exists($basepath) && is_dir($basepath) && is_writable($basepath))) {
             throw new RokGallery_Job_Exception(rc__('ROKGALLERY_UNABLE_TO_CREATE_OR_WRITE_TO_TEMP_DIR', $basepath));
         }
         $tx->beginTransaction();
         foreach ($_FILES as $uploaded_file) {
             if ($uploaded_file['error'] == UPLOAD_ERR_OK) {
                 $file = new RokGallery_Job_Property_ImportFile();
                 $file->setFilename($uploaded_file['name']);
                 $file->setPath($basepath . DS . $file->getId());
                 move_uploaded_file($uploaded_file['tmp_name'], $file->getPath());
                 $job_properties[] = $file;
             }
         }
         $job->setProperties($job_properties);
         $job->save();
         $tx->commit();
     } catch (Exception $e) {
         $tx->rollback();
         throw $e;
     }
     return $result;
 }
Exemplo n.º 4
0
 /**
  * Get the full list of jobs
  * <code>
  * {
  *  'orberby': 'xxxx-x-x-x-x-x-x'
  * }
  * </code>
  * @param $params
  * @return RokCommon_Ajax_Result
  */
 public function clean($params)
 {
     $result = new RokCommon_Ajax_Result();
     try {
         $q = Doctrine_Query::create()->select('j.id')->from('RokGallery_Model_Job j')->where('j.state = ?', RokGallery_Job::STATE_COMPLETE)->orWhere('j.state = ?', RokGallery_Job::STATE_ERRORED)->orWhere('j.state = ?', RokGallery_Job::STATE_CANCELED);
         $jobs = $q->fetchArray();
         $q->free();
         foreach ($jobs as $job) {
             $real_job = RokGallery_Job::get($job['id']);
             $real_job->Delete();
         }
     } catch (Exception $e) {
         throw $e;
     }
     return $result;
 }
Exemplo n.º 5
0
 /**
  * Get the full list of jobs
  * <code>
  * {
  *   'ids': [1,2,3],
  *   'tags': ['tag1','tag2']
  * }
  * </code>
  * @param $params
  * @return RokCommon_Ajax_Result
  */
 public function removeTags($params)
 {
     $result = new RokCommon_Ajax_Result();
     try {
         try {
             RokGallery_Doctrine::getConnection()->beginTransaction();
             $properties = array();
             foreach ($params->ids as $file_id) {
                 $properties[] = new RokGallery_Job_Property_FileTags($file_id, $params->tags);
             }
             $job = RokGallery_Job::create(RokGallery_Job::TYPE_TAGREMOVAL);
             $job->setProperties($properties);
             $job->save();
             RokGallery_Doctrine::getConnection()->commit();
             // Disconnect and process job
             $this->sendDisconnectingReturn($result);
             $job->Ready();
             $job->Run('Starting Tag Removals');
             $job->process();
             die;
         } catch (Exception $e) {
             RokGallery_Doctrine::getConnection()->rollback();
             throw $e;
         }
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 6
0
 /**
  * Get the basic file info and supporting slices/tags
  * $params object should be a json like
  * <code>
  * {
  *  "id": 1
  *  "gallery": {
  *      "name": "Gallery name",
  *      "width": 100
  *      "height": 100
  *      "thumb_xsize": 50
  *      "thumb_ysize": 50
  *   }
  *  "order": [1, 2, 10, 3, 8]
  * }
  * </code>
  *
  * @param $params
  * @return RokCommon_Ajax_Result
  */
 public function update($params)
 {
     $result = new RokCommon_Ajax_Result();
     /** @var Doctrine_Transaction $tx  */
     $tx = RokGallery_Doctrine::getConnection()->transaction;
     $tx->setIsolation('REPEATABLE READ');
     try {
         $tx->beginTransaction();
         $gallery = RokGallery_Model_GalleryTable::getSingle($params->id);
         if ($gallery === false) {
             throw new RokCommon_Ajax_Exception(rc__('ROKGALLERY_UNABLE_TO_FIND_GALLERY_WITH_ID_N_TO_UPDATE', $params->id));
         }
         $oldfiletags = $gallery->filetags;
         $update_slices = false;
         foreach ($params->gallery as $field => $value) {
             if (isset($gallery->{$field})) {
                 // see if we need to update the slices
                 if ($field == 'width' || $field == 'height' || $field == 'keep_aspect' || $field == 'thumb_xsize' || $field == 'thumb_ysize' || $field == 'thumb_background' || $field == 'thumb_keep_aspect') {
                     $update_slices = true;
                 }
                 if ($value == '') {
                     $value = null;
                 }
                 $gallery->{$field} = $value;
             }
         }
         $gallery->save();
         $result->setPayload(array('gallery' => $gallery->toJsonableArray()));
         // get list of files to process
         $fileids = RokGallery_Model_FileTable::getIdsByTags($gallery->filetags);
         // get list of files to remove
         $original_fileids = RokGallery_Model_FileTable::getIdsByTags($oldfiletags);
         // get the list of file ids to remove or add
         $remove_fileids = array_diff($original_fileids, $fileids);
         $new_fileids = array_diff($fileids, $original_fileids);
         // just return if there are no files to process
         if ((empty($fileids) || $fileids === false) && (empty($remove_fileids) || $remove_fileids === false)) {
             $tx->commit();
             return $result;
         }
         /** @var RokGallery_Job_Property_GalleryFile[] $files  */
         $files = array();
         // Add any new files to the job
         if (!empty($new_fileids)) {
             foreach ($new_fileids as $new_fileid) {
                 $files[] = new RokGallery_Job_Property_GalleryFile($new_fileid);
             }
         }
         // if we need to update all slices populate them
         if ($update_slices) {
             foreach ($fileids as $fileid) {
                 $files[] = new RokGallery_Job_Property_GalleryFile($fileid);
             }
         }
         $remove_slices = array();
         // remove all non linked slices
         foreach ($gallery->Slices as $key => &$slice) {
             /** @var RokGallery_Model_Slice $slice */
             if (in_array($slice->File->id, $remove_fileids)) {
                 $remove_slices[] = $slice->id;
             }
         }
         foreach ($remove_slices as $remove_slice_id) {
             $remove_slice = RokGallery_Model_SliceTable::getSingle($remove_slice_id);
             if (RokGallery_Config::getOption(RokGallery_Config::OPTION_GALLERY_REMOVE_SLICES, false)) {
                 $remove_slice->delete();
             } else {
                 $remove_slice->unlink('Gallery');
                 $remove_slice->save();
             }
         }
         // if there are no files to process just return
         if (empty($files)) {
             $tx->commit();
             return;
         }
         $properties = array("galleryId" => $gallery->id, "files" => $files);
         $job = RokGallery_Job::create(RokGallery_Job::TYPE_UPDATEGALLERY);
         $job->propertires = serialize($properties);
         $job->setProperties($properties);
         $job->save();
         $tx->commit();
         // Disconnect and process job
         $this->sendDisconnectingReturn($result);
         $job->Ready();
         $job->Run('Starting Gallery Update');
         $job->process();
         die;
     } catch (Exception $e) {
         $tx->rollback();
         throw $e;
     }
 }
Exemplo n.º 7
0
 /**
  * Send a job a cancel command
  * $params object should be a json like
  * <code>
  * {
  *  'id': 'xxxx-x-x-x-x-x-x'
  * }
  * </code>
  *
  * @param $params
  * @return RokCommon_Ajax_Result
  */
 public function delete($params)
 {
     $result = new RokCommon_Ajax_Result();
     try {
         $job = RokGallery_Job::get($params->id);
         if ($job === false) {
             throw new RokCommon_Ajax_Exception(rc__('ROKGALLERY_UNABLE_TO_FIND_JOB_ID_N', $params->id));
         }
         $job->Delete();
     } catch (Exception $e) {
         throw $e;
     }
     return $result;
 }