예제 #1
0
 /**
  * @param $id
  * @return \RokGallery_Model_Slice|bool
  */
 public function &getSingle()
 {
     /** @var $single RokGallery_Model_Slice */
     $single = RokGallery_Model_SliceTable::getSingle($this->id);
     if (!$single->published) {
         return false;
     }
     return $single;
 }
 public function preUp()
 {
     if (!$this->isInnoDBEngine(RokCommon_Doctrine::getPlatformInstance()->getSchema(), RokCommon_Doctrine::getPlatformInstance()->setTableName('rokgallery_files'))) {
         $this->run = true;
         //Clean up bad data
         //RokGallery_Model_FileTags
         $q = Doctrine_Query::create()->delete('RokGallery_Model_FileTags ft')->andWhere('ft.file_id NOT IN (SELECT f.id from RokGallery_Model_File f)');
         $q->execute();
         $q->free();
         //RokGallery_Model_FileViews
         $q = Doctrine_Query::create()->delete('RokGallery_Model_FileViews fv')->andWhere('fv.file_id NOT IN (SELECT f.id from RokGallery_Model_File f)');
         $q->execute();
         $q->free();
         //RokGallery_Model_FileLoves
         $q = Doctrine_Query::create()->delete('RokGallery_Model_FileLoves fl')->andWhere('fl.file_id NOT IN (SELECT f.id from RokGallery_Model_File f)');
         $q->execute();
         $q->free();
         //rokgallery_files_index
         $conn =& Doctrine_Manager::connection();
         $dbh =& $conn->getDbh();
         $stmt = $dbh->prepare('delete from ' . RokCommon_Doctrine::getPlatformInstance()->setTableName('rokgallery_files_index') . ' where id NOT IN (SELECT f.id from ' . RokGallery_Model_FileTable::getInstance()->getTableName() . ' f)');
         $stmt->execute();
         //RokGallery_Model_Slice
         $q = Doctrine_Query::create()->delete('RokGallery_Model_Slice s')->andWhere('s.file_id NOT IN (SELECT f.id from RokGallery_Model_File f)');
         $q->execute();
         $q->free();
         //RokGallery_Model_SliceTags
         $q = Doctrine_Query::create()->delete('RokGallery_Model_SliceTags st')->andWhere('st.slice_id NOT IN (SELECT s.id from RokGallery_Model_Slice s)');
         $q->execute();
         $q->free();
         //rokgallery_slices_index
         $stmt = $dbh->prepare('delete from ' . RokCommon_Doctrine::getPlatformInstance()->setTableName('rokgallery_slices_index') . ' where id NOT IN (SELECT s.id from ' . RokGallery_Model_SliceTable::getInstance()->getTableName() . ' s)');
         $stmt->execute();
         //RokGallery_Model_Gallery
         $q = Doctrine_Query::create()->update('RokGallery_Model_Slice')->set('gallery_id', 'NULL')->andWhere('gallery_id NOT IN (SELECT g.id from RokGallery_Model_Gallery g)');
         $q->execute();
         $q->free();
         $dbh->exec('alter table ' . RokCommon_Doctrine::getPlatformInstance()->setTableName('rokgallery_file_loves') . ' ENGINE=INNODB');
         $dbh->exec('alter table ' . RokCommon_Doctrine::getPlatformInstance()->setTableName('rokgallery_file_views') . ' ENGINE=INNODB');
         $dbh->exec('alter table ' . RokCommon_Doctrine::getPlatformInstance()->setTableName('rokgallery_file_tags') . ' ENGINE=INNODB');
         $dbh->exec('alter table ' . RokCommon_Doctrine::getPlatformInstance()->setTableName('rokgallery_files') . ' ENGINE=INNODB');
         $dbh->exec('alter table ' . RokCommon_Doctrine::getPlatformInstance()->setTableName('rokgallery_files_index') . ' ENGINE=INNODB');
         $dbh->exec('alter table ' . RokCommon_Doctrine::getPlatformInstance()->setTableName('rokgallery_filters') . ' ENGINE=INNODB');
         $dbh->exec('alter table ' . RokCommon_Doctrine::getPlatformInstance()->setTableName('rokgallery_galleries') . ' ENGINE=INNODB');
         $dbh->exec('alter table ' . RokCommon_Doctrine::getPlatformInstance()->setTableName('rokgallery_jobs') . ' ENGINE=INNODB');
         $dbh->exec('alter table ' . RokCommon_Doctrine::getPlatformInstance()->setTableName('rokgallery_profiles') . ' ENGINE=INNODB');
         $dbh->exec('alter table ' . RokCommon_Doctrine::getPlatformInstance()->setTableName('rokgallery_schema_version') . ' ENGINE=INNODB');
         $dbh->exec('alter table ' . RokCommon_Doctrine::getPlatformInstance()->setTableName('rokgallery_slice_tags') . ' ENGINE=INNODB');
         $dbh->exec('alter table ' . RokCommon_Doctrine::getPlatformInstance()->setTableName('rokgallery_slices') . ' ENGINE=INNODB');
         $dbh->exec('alter table ' . RokCommon_Doctrine::getPlatformInstance()->setTableName('rokgallery_slices_index') . ' ENGINE=INNODB');
     }
 }
예제 #3
0
 public function postDelete(Doctrine_Event $event)
 {
     //Make sure all linked tables are clean
     //RokGallery_Model_SliceTags
     $q = Doctrine_Query::create()->delete('RokGallery_Model_SliceTags st')->andWhere('st.slice_id NOT IN (SELECT s.id from RokGallery_Model_Slice s)');
     $q->execute();
     $q->free();
     //rokgallery_slices_index
     $conn =& Doctrine_Manager::connection();
     $dbh =& $conn->getDbh();
     $stmt = $dbh->prepare('delete from ' . RokCommon_Doctrine::getPlatformInstance()->setTableName('rokgallery_slices_index') . ' where id NOT IN (SELECT s.id from ' . RokGallery_Model_SliceTable::getInstance()->getTableName() . ' s)');
     $stmt->execute();
 }
예제 #4
0
 /**
  * $params object should be a json like
  * <code>
  * {
  *      "id": 1   // this is the slice ID displayed
  * }
  * @throws Exception|RokCommon_Ajax_Exception
  * @param $params
  * @return RokCommon_Ajax_Result
  */
 public function remove($params)
 {
     try {
         $result = new RokCommon_Ajax_Result();
         $slice = RokGallery_Model_SliceTable::getSingle($params->id);
         if ($slice === false) {
             throw new RokCommon_Ajax_Exception('No Slice Found');
         }
         if (RokCommon_Session::get(self::CONTEXT_ROOT . $slice->file_id, false)) {
             $slice->decrementLoves();
             RokCommon_Session::clear(self::CONTEXT_ROOT . $slice->file_id);
         }
         $result->setPayload(array('loves' => $slice->File->Loves->count, 'new_action' => 'love', 'text' => rc__(RokGallery_Config::getOption(RokGallery_Config::OPTION_LOVE_TEXT))));
     } catch (Exception $e) {
         throw $e;
     }
     return $result;
 }
예제 #5
0
 /**
  * Add an array of tags to a {@link RokGallery_Model_Slice} object
  * $params object should be a json like
  * <code>
  * {
  *  'id': 1,
  *  'tags':['tag1','tag2']
  * }
  * </code>
  *
  * @throws RokCommon_Ajax_Exception
  * @param  $params
  * @return RokCommon_Ajax_Result
  */
 public function addTags($params)
 {
     $result = new RokCommon_Ajax_Result();
     try {
         $slice = RokGallery_Model_SliceTable::getSingle($params->id);
         if ($slice === false) {
             throw new RokCommon_Ajax_Exception(rc__('ROKGALLERY_UNABLE_TO_FIND_SLICE_N', $params->id));
         }
         foreach ($params->tags as $tag) {
             $found = false;
             foreach ($slice->Tags as $current_tag) {
                 if (strtolower($tag) == $current_tag['tag']) {
                     $found = true;
                     break;
                 }
             }
             if (!$found) {
                 $next = $slice->Tags->count();
                 $slice->Tags[$next]['tag'] = $tag;
             }
         }
         $slice->save();
     } catch (Exception $e) {
         throw $e;
     }
     return $result;
 }
예제 #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;
     }
 }