public function docopy() { // check for request forgeries YRequest::checkToken() or jexit('Invalid Token'); // init vars $cid = YRequest::getArray('cid', array(), 'int'); if (count($cid) < 1) { JError::raiseError(500, JText::_('Select a category to copy')); } try { // get category table $table = YTable::getInstance('category'); // copy categories $parents = array(); foreach ($cid as $id) { // get category $category = $table->get($id); // copy category $category->id = 0; // set id to 0, to force new category $category->name .= ' (' . JText::_('Copy') . ')'; // set copied name $category->alias = CategoryHelper::getUniqueAlias($id, $category->alias . '-copy'); // set copied alias $category->published = 0; // unpublish category // track parent for ordering update $parents[] = $category->parent; // save copied category data $table->save($category); } // update category ordering $table->updateorder($this->application->id, $parents); // set redirect message $msg = JText::_('Category Copied'); } catch (YException $e) { // raise notice on exception JError::raiseNotice(0, JText::_('Error Copying Category') . ' (' . $e . ')'); $msg = null; } $this->setRedirect($this->baseurl, $msg); }