コード例 #1
0
 /**
  * Up
  **/
 public function up()
 {
     if ($this->db->tableExists('#__tags')) {
         // We need to clean out duplicates first
         $query = "SELECT *, count(id) as cnt FROM `#__tags` GROUP BY `tag` HAVING cnt > 1;";
         $this->db->setQuery($query);
         if ($results = $this->db->loadObjectList()) {
             require_once PATH_CORE . DS . 'components' . DS . 'com_tags' . DS . 'models' . DS . 'cloud.php';
             $cls = '\\Components\\Tags\\Models\\Tag';
             // [!] - Backwards compatibility
             if (class_exists('TagsModelTag')) {
                 $cls = 'TagsModelTag';
             }
             foreach ($results as $result) {
                 // Get all duplicate tags
                 $query = "SELECT * FROM `#__tags` WHERE `tag`=" . $this->db->quote($result->tag) . ";";
                 $this->db->setQuery($query);
                 if ($tags = $this->db->loadObjectList()) {
                     foreach ($tags as $tag) {
                         if ($tag->id == $result->id) {
                             continue;
                         }
                         $oldtag = new $cls($tag->id);
                         if ($oldtag instanceof \Hubzero\Database\Relational) {
                             $oldtag = \Components\Tags\Models\Tag::oneOrNew($tag->id);
                         }
                         if (!$oldtag->mergeWith($result->id)) {
                             continue;
                         }
                     }
                 }
             }
         }
         if ($this->db->tableHasKey('#__tags', 'idx_tag')) {
             $query = "ALTER TABLE `#__tags` DROP INDEX `idx_tag`;";
             $this->db->setQuery($query);
             $this->db->query();
         }
         $query = "CREATE UNIQUE INDEX `idx_tag` ON `#__tags` (`tag`);";
         $this->db->setQuery($query);
         $this->db->query();
     }
 }
コード例 #2
0
ファイル: entriesv1_0.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Update an entry
  *
  * @return  void
  */
 public function updateTask()
 {
     $this->requiresAuthentication();
     $id = Request::getInt('id', 0);
     $tag = Request::getVar('tag', null);
     $raw = Request::getVar('raw_tag', null);
     $label = Request::getVar('label', null);
     $admin = Request::getInt('admin', 0);
     $subs = Request::getVar('substitutes', null);
     if (!$id) {
         throw new Exception(Lang::txt('COM_TAGS_ERROR_MISSING_DATA'), 500);
     }
     $record = Tag::oneOrNew($id);
     if ($record->isNew()) {
         $record->set('admin', $admin ? 1 : 0);
         if ($raw_tag) {
             $record->set('raw_tag', $raw_tag);
         }
         if ($tag) {
             $record->set('tag', $tag);
         }
         $record->set('label', $label);
         $record->set('substitutions', $subs);
         if (!$record->save()) {
             throw new Exception($record->getError(), 500);
         }
     }
     $this->send($record->toObject());
 }
コード例 #3
0
ファイル: entries.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Save an entry
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     $fields = Request::getVar('fields', array(), 'post');
     $subs = '';
     if (isset($fields['substitutions'])) {
         $subs = $fields['substitutions'];
         unset($fields['substitutions']);
     }
     $row = Tag::oneOrNew(intval($fields['id']))->set($fields);
     $row->set('admin', 0);
     if (isset($fields['admin']) && $fields['admin']) {
         $row->set('admin', 1);
     }
     // Store new content
     if (!$row->save()) {
         Notify::error($row->getError());
         return $this->editTask($row);
     }
     if (!$row->saveSubstitutions($subs)) {
         Notify::error($row->getError());
         return $this->editTask($row);
     }
     Notify::success(Lang::txt('COM_TAGS_TAG_SAVED'));
     // Redirect to main listing
     if ($this->getTask() == 'apply') {
         return $this->editTask($row);
     }
     $this->cancelTask();
 }
コード例 #4
0
ファイル: tags.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Show a form for editing a tag
  *
  * @param   object  $tag
  * @return  void
  */
 public function editTask($tag = NULL)
 {
     // Check that the user is authorized
     if (!$this->config->get('access-edit-tag')) {
         throw new Exception(Lang::txt('ALERTNOTAUTH'), 403);
     }
     // Load a tag object if one doesn't already exist
     if (!is_object($tag)) {
         // Incoming
         $tag = Tag::oneOrNew(intval(Request::getInt('id', 0, 'request')));
     }
     $filters = array('limit' => Request::getInt('limit', 0), 'start' => Request::getInt('limitstart', 0), 'sort' => Request::getVar('sort', ''), 'sort_Dir' => Request::getVar('sortdir', ''), 'search' => urldecode(Request::getString('search', '')));
     // Set the pathway
     $this->_buildPathway();
     // Set the page title
     $this->_buildTitle();
     $this->view->set('tag', $tag)->set('filters', $filters)->setLayout('edit')->display();
 }
コード例 #5
0
ファイル: cloud.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Set and get a specific offering
  *
  * @param   mixed   $id  Integer or string of tag to look up
  * @return  object
  */
 public function tag($id = null)
 {
     if (!$this->_cache['tags.one'] || $id !== null && (int) $this->_cache['tags.one']->get('id') != $id && (string) $this->_cache['tags.one']->get('tag') != $this->normalize($id)) {
         $this->_cache['tags.one'] = is_numeric($id) ? Tag::oneOrNew($id) : Tag::oneByTag($id);
     }
     return $this->_cache['tags.one'];
 }