/** * Preview the resource * * @return void */ public function previewTask() { // Incoming $alias = Request::getVar('app', ''); $version = Request::getVar('editversion', 'dev'); $rid = Request::getInt('rid', 0); // Load the tool $obj = new \Components\Tools\Tables\Tool($this->database); $this->_toolid = $obj->getToolId($alias); if (!$this->_toolid) { // not a tool resource page App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=pipeline')); return; } // Make sure user is authorized to go further if (!$this->_checkAccess($this->_toolid)) { App::abort(403, Lang::txt('COM_TOOLS_ALERTNOTAUTH')); return; } // Get tool version (dev or current) information $obj->getToolStatus($this->_toolid, $this->_option, $status, $version); // Instantiate our tag object $tagcloud = new \Components\Resources\Helpers\Tags($rid); $tags = Request::getVar('tags', '', 'post'); $tagfa = Request::getVar('tagfa', '', 'post'); // Process new tags $newtags = ''; if ($tagfa) { $newtags = $tagfa . ', '; } if ($tags) { $newtags .= $tags; } $tagcloud->setTags($newtags, User::get('id')); // Get some needed libraries include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'html.php'; // Load the resource object $resource = new \Components\Resources\Tables\Resource($this->database); $resource->loadAlias($alias); if (!User::isGuest()) { $xgroups = \Hubzero\User\Helper::getGroups(User::get('id'), 'all'); // Get the groups the user has access to $usersgroups = $this->_getUsersGroups($xgroups); } else { $usersgroups = array(); } // Get updated version $objV = new \Components\Tools\Tables\Version($this->database); $thistool = $objV->getVersionInfo('', $version, $resource->alias, ''); $thistool = $thistool ? $thistool[0] : ''; // Replace resource info with requested version $objV->compileResource($thistool, '', $resource, 'dev', $this->rconfig); // get language library $lang = Lang::getRoot(); if (!$lang->load(strtolower('com_resources'), JPATH_BASE)) { $this->setError(Lang::txt('COM_TOOLS_ERROR_LOADING_LANGUAGE')); } // Set the document title $this->view->title = Lang::txt(strtoupper($this->_option)) . ': ' . Lang::txt('COM_TOOLS_PREVIEW_TOOL_PAGE') . ' (' . $resource->alias . ')'; Document::setTitle($this->view->title); // Set the document pathway (breadcrumbs) if (Pathway::count() <= 0) { Pathway::append(Lang::txt(strtoupper($this->_name)), 'index.php?option=' . $this->_option); } if (Pathway::count() <= 1) { Pathway::append(Lang::txt('COM_TOOLS_STATUS_FOR', $thistool->toolname), 'index.php?option=' . $this->_option . '&controller=pipeline&task=status&app=' . $alias); Pathway::append(Lang::txt('COM_TOOLS_EDIT_TOOL_PAGE'), 'index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&app=' . $alias . '&task=start&step=1'); } $this->view->toolid = $this->_toolid; $this->view->step = 5; $this->view->version = $version; $this->view->resource = $resource; $this->view->config = $this->rconfig; $this->view->usersgroups = $usersgroups; $this->view->status = $status; // Pass error messages to the view foreach ($this->getErrors() as $error) { $this->view->setError($error); } // Output HTML $this->view->display(); }
/** * Update a tool version * * @return void */ public function updateTask() { // get vars if (!$this->_toolid) { $this->_toolid = Request::getInt('toolid', 0); } // Create a Tool object $obj = new \Components\Tools\Tables\Tool($this->database); // do we have an alias? if ($this->_toolid == 0) { if ($alias = Request::getVar('app', '')) { $this->_toolid = $obj->getToolId($alias); } } if (!$this->_error) { $this->_error = Request::getVar('error', ''); } $error = ''; //$id = $this->_toolid; // make sure user is authorized to go further if (!$this->_checkAccess($this->_toolid)) { App::abort(403, Lang::txt('COM_TOOLS_ALERTNOTAUTH')); return; } $newstate = Request::getVar('newstate', ''); $priority = Request::getVar('priority', 3); $comment = Request::getVar('comment', ''); $access = Request::getInt('access', 0); $newversion = Request::getVar('newversion', ''); $editversion = Request::getVar('editversion', 'dev'); $hzt = \Components\Tools\Models\Tool::getInstance($this->_toolid); $hztv = $hzt->getRevision($editversion); $oldstatus = $hztv ? $hztv->toArray() : array(); $oldstatus['toolstate'] = $hzt->state; if ($newstate && !intval($newstate)) { $newstate = \Components\Tools\Helpers\Html::getStatusNum($newstate); } if (intval($newstate) && $newstate != $oldstatus['toolstate']) { Log::debug(__FUNCTION__ . "() state changing"); if ($newstate == \Components\Tools\Helpers\Html::getStatusNum('Approved') && \Components\Tools\Models\Tool::validateVersion($oldstatus['version'], $error, $hzt->id)) { $this->_error = $error; Log::debug(__FUNCTION__ . "() state changing to approved, action confirm"); $this->_action = 'confirm'; $this->_task = Lang::txt('COM_TOOLS_CONTRIBTOOL_APPROVE_TOOL'); $this->versionsTask(); return; } else { if ($newstate == \Components\Tools\Helpers\Html::getStatusNum('Approved')) { $this->_error = $error; Log::debug(__FUNCTION__ . "() state changing to approved, action new"); $this->_action = 'new'; $this->_task = Lang::txt('COM_TOOLS_CONTRIBTOOL_APPROVE_TOOL'); $this->versionsTask(); return; } else { if ($newstate == \Components\Tools\Helpers\Html::getStatusNum('Published')) { Log::debug(__FUNCTION__ . "() state changing to published"); $hzt->published = '1'; } } } $this->_error = $error; // update dev screenshots of a published tool changes status if ($oldstatus['state'] == \Components\Tools\Helpers\Html::getStatusNum('Published')) { // Create a Tool Version object $objV = new \Components\Tools\Tables\Version($this->database); Log::debug(__FUNCTION__ . "() state changing away from published"); // Get version ids $rid = \Components\Tools\Models\Tool::getResourceId($hzt->toolname, $hzt->id); $to = $objV->getVersionIdFromResource($rid, 'dev'); $from = $objV->getVersionIdFromResource($rid, 'current'); $dev_hztv = $hzt->getRevision('dev'); $current_hztv = $hzt->getRevision('current'); Log::debug("update: to={$to} from={$from} dev=" . $dev_hztv->id . " current=" . $current_hztv->id); if ($to && $from) { require_once __DIR__ . DS . 'screenshots.php'; $ss = new Screenshots(); $ss->transfer($from, $to, $rid); } } // If the tool was cancelled ... if ($oldstatus['state'] == \Components\Tools\Helpers\Html::getStatusNum('Abandoned')) { include_once __DIR__ . DS . 'resource.php'; $r = new \Components\Resources\Tables\Resource($this->database); $r->loadAlias($hzt->toolname); if ($r && $r->id) { $rstatus = 2; if ($newstate == \Components\Tools\Helpers\Html::getStatusNum('Published')) { $rstatus = 1; } $resource = new Resource(); $resource->updatePage($r->id, $oldstatus, $rstatus); } } Log::debug(__FUNCTION__ . "() state changing to {$newstate}"); $hzt->state = $newstate; $hzt->state_changed = Date::toSql(); } // if priority changes if (intval($priority) && $priority != $oldstatus['priority']) { $hzt->priority = $priority; } // save tool info $hzt->update(); $hztv->update(); //@FIXME: look // get tool status after updates $status = $hztv->toArray(); $status['toolstate'] = $hzt->state; // update history ticket Log::debug(__FUNCTION__ . "() before newUpdateTicket test"); if ($oldstatus != $status || !empty($comment)) { Log::debug(__FUNCTION__ . "() before newUpdateTicket"); $this->_newUpdateTicket($hzt->id, $hzt->ticketid, $oldstatus, $status, $comment, $access, 1); Log::debug(__FUNCTION__ . "() after newUpdateTicket"); } $this->_msg = Lang::txt('COM_TOOLS_NOTICE_STATUS_CHANGED'); $this->statusTask(); }