示例#1
0
 /**
  */
 public function process()
 {
     try {
         /** @var $properties RokGallery_Job_Property_ImportFile[] */
         $properties = $this->_job->getProperties();
         $total_files = count($properties['files']);
         foreach ($properties['files'] as $key => &$file) {
             // keep bumping the time as log as a file doesnt take 30 seconds or more
             /** @var RokGallery_Job_Property_ImportFile $file  */
             if (!$this->_checkState($properties, rc__('ROKGALLERY_CREATE_UPDATE'))) {
                 return;
             }
             if ($file->isCompleted()) {
                 continue;
             }
             RokGallery_Doctrine::getConnection()->beginTransaction();
             $gallery = RokGallery_Model_GalleryTable::getSingle($properties['galleryId']);
             if ($gallery === false) {
                 throw new RokGallery_Job_Exception(rc__('ROKGALLERY_NOT_A_VALID_GALLERY'));
             }
             $full_file = RokGallery_Model_FileTable::getSingle($file->getId());
             if ($full_file === false) {
                 $file->setStatus(rc__('ROKGALLERY_UNABLE_TO_FIND_FILE'));
                 $file->setError(true);
                 RokGallery_Doctrine::getConnection()->commit();
                 continue;
             }
             if ($gallery && $full_file) {
                 $full_file->updateSlicesForGallery($gallery);
             }
             $file->setCompleted();
             $percent = (int) (($key + 1) / $total_files * 100);
             $this->_job->setProperties($properties);
             $this->_job->save(rc__('ROKGALLERY_UPDATED_GALLERY_SLICE_FOR_FILE_N', $full_file->title), $percent);
             RokGallery_Doctrine::getConnection()->commit();
         }
         $this->_job->Complete(rc__('ROKGALLERY_GALLERY_UPDATE_COMPLETE'));
         if (RokGallery_Config::getOption(RokGallery_Config::OPTION_AUTO_CLEAR_SUCCESSFUL_JOBS, false)) {
             sleep(5);
             $this->_job->Delete();
         }
         return;
     } catch (Exception $e) {
         RokGallery_Doctrine::getConnection()->rollback();
         $this->_job->Error($e->getMessage());
         return;
     }
 }
示例#2
0
 /**
  */
 public function process()
 {
     try {
         /** @var $properties RokGallery_Job_Property_FileTags[] */
         $properties = $this->_job->getProperties();
         $total_files = count($properties);
         foreach ($properties as $key => &$tagAddition) {
             // keep bumping the time as log as a file doesnt take 30 seconds or more
             if (!$this->_checkState($properties, rc__('ROKGALLERY_CREATE_UPDATE'))) {
                 return;
             }
             if ($tagAddition->isCompleted()) {
                 continue;
             }
             RokGallery_Doctrine::getConnection()->beginTransaction();
             $file = RokGallery_Model_FileTable::getSingle($tagAddition->getFileId());
             if (!$file) {
                 $tagAddition->setStatus(rc__('ROKGALLERY_UNABLE_TO_FIND_FILE'));
                 $tagAddition->setError(true);
                 RokGallery_Doctrine::getConnection()->commit();
                 continue;
             }
             RokGallery_Model_FileTable::addTagsToFile($file, $tagAddition->getTags());
             $tagAddition->setCompleted();
             $percent = (int) (($key + 1) / $total_files * 100);
             $this->_job->setProperties($properties);
             $this->_job->save(rc__('ROKGALLERY_ADDED_TAGS_TO_FILE_N', $file->title), $percent);
             RokGallery_Doctrine::getConnection()->commit();
         }
         $this->_job->Complete(rc__('ROKGALLERY_TAG_ADDITION_COMPLETE'));
         if (RokGallery_Config::getOption(RokGallery_Config::OPTION_AUTO_CLEAR_SUCCESSFUL_JOBS, false)) {
             sleep(5);
             $this->_job->Delete();
         }
         return;
     } catch (Exception $e) {
         RokGallery_Doctrine::getConnection()->rollback();
         $this->_job->Error($e->getMessage());
         return;
     }
 }
示例#3
0
 /**
  * Removes an array of tags to a {@link RokGallery_Model_File} object
  * $params object should be a json like
  * <code>
  * {
  *  'id': 1,
  *  'tags':['tag1','tag2']
  * }
  * </code>
  *
  * @param  $params
  * @return RokCommon_Ajax_Result
  */
 public function removeTags($params)
 {
     $result = new RokCommon_Ajax_Result();
     try {
         RokGallery_Doctrine::getConnection()->beginTransaction();
         $file = RokGallery_Model_FileTable::getSingle($params->id);
         if ($file === false) {
             throw new RokCommon_Ajax_Exception(rc__('ROKGALLERY_UNABLE_TO_FIND_FILE'));
         }
         RokGallery_Model_FileTable::removeTagsFromFile($file, $params->tags);
         RokGallery_Doctrine::getConnection()->commit();
         $file->imageurl;
         $file->Tags;
         foreach ($file->Slices as &$slice) {
             $slice->populateFilterInfo();
             $slice->manipulations = RokGallery_Manipulation_Helper::prepSerializedForJson($slice->manipulations);
             $slice->clearRelated('File');
             $slice->Tags;
             $slice->FileTags;
             $slice->Gallery;
         }
         $result->setPayload(array('file' => $file->toJsonableArray()));
     } catch (Exception $e) {
         RokGallery_Doctrine::getConnection()->rollback();
         throw $e;
     }
     return $result;
 }
示例#4
0
 /**
  * Update the slice
  * $params object should be a json like
  * <code>
  * {
  *  'id': 1
  *  'slice':{'title':'new title','description':'new description'}
  * }
  * </code>
  *
  * @param $params
  * @return RokCommon_Ajax_Result
  */
 public function create($params)
 {
     $result = new RokCommon_Ajax_Result();
     try {
         $file = RokGallery_Model_FileTable::getSingle($params->fileId);
         /** @var $slice RokGallery_Model_Slice */
         $slice =& RokGallery_Model_Slice::createNew($file);
         if ($slice === false) {
             throw new RokCommon_Ajax_Exception(rc__('ROKGALLERY_UNABLE_TO_FIND_SLICE_N', $params->id));
         }
         foreach ($params->slice as $field => $value) {
             // change the manipulation format if passed
             if ($field == 'manipulations') {
                 $value = RokGallery_Manipulation_Helper::unserializeFromJson($value);
             }
             // Add any tags if they are passed
             if ($field == 'Tags') {
                 if (!empty($value) && is_array($value)) {
                     foreach ($value as $tag) {
                         $slice->addTag($tag);
                     }
                 }
                 continue;
             }
             $slice->{$field} = $value;
         }
         $slice->save();
         $slice->populateFilterInfo();
         $slice->manipulations = RokGallery_Manipulation_Helper::prepSerializedForJson($slice->manipulations);
         $slice->Tags;
         $slice->FileTags;
         $slice->File;
         $result->setPayload(array('slice' => $slice->toJsonableArray()));
     } catch (Exception $e) {
         throw $e;
     }
     return $result;
 }