/** * Copy all tag associations from one tag to another * * @return void */ public function pierceTask() { if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.manage', $this->_option)) { App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR')); } // Incoming $ids = Request::getVar('id', array()); $ids = !is_array($ids) ? array($ids) : $ids; $step = Request::getInt('step', 1); $step = $step ? $step : 1; // Make sure we have some IDs to work with if ($step == 1 && (!$ids || count($ids) < 1)) { return $this->cancelTask(); } $idstr = implode(',', $ids); switch ($step) { case 1: Request::setVar('hidemainmenu', 1); $tags = array(); // Loop through the IDs of the tags we want to merge foreach ($ids as $id) { // Load the tag's info $tags[] = Tag::oneOrFail(intval($id)); } // Output the HTML $this->view->set('step', 2)->set('idstr', $idstr)->set('tags', $tags)->display(); break; case 2: // Check for request forgeries Request::checkToken(); // Get the string of tag IDs we plan to merge $ind = Request::getVar('ids', '', 'post'); if ($ind) { $ids = explode(',', $ind); } else { $ids = array(); } // Incoming $tag_exist = Request::getInt('existingtag', 0, 'post'); $tag_new = Request::getVar('newtag', '', 'post'); // Are we merging tags into a totally new tag? if ($tag_new) { // Yes, we are $newtag = Tag::oneByAlias($tag_new); if (!$newtag->get('id')) { $newtag->set('raw_tag', $tag_new); } if (!$newtag->save()) { $this->setError($newtag->getError()); } $mtag = $newtag->get('id'); } else { // No, we're merging into an existing tag $mtag = $tag_exist; } foreach ($ids as $id) { if ($mtag == $id) { continue; } $oldtag = Tag::oneOrFail(intval($id)); if (!$oldtag->copyTo($mtag)) { $this->setError($oldtag->getError()); } } if ($this->getError()) { Notify::error($this->getError()); } else { Lang::txt('COM_TAGS_TAGS_COPIED'); } $this->cancelTask(); break; } }