/** * 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(); }
/** * Save an entry * * @return void */ public function saveTask() { $exportmap = array('@OPEN' => null, '@GROUP' => null, '@US' => 'us', '@us' => 'us', '@PU' => 'pu', '@pu' => 'pu', '@D1' => 'd1', '@d1' => 'd1'); // set vars $tool = Request::getVar('tool', array(), 'post'); $tool = array_map('trim', $tool); // Sanitize the input a bit $noHtmlFilter = \JFilterInput::getInstance(); foreach ($tool as $i => $var) { $tool[$i] = $noHtmlFilter->clean($var); } $today = Date::toSql(); $group_prefix = $this->config->get('group_prefix', 'app-'); $dev_suffix = $this->config->get('dev_suffix', '_dev'); // pass data from forms $id = Request::getInt('toolid', 0); $this->_action = Request::getVar('action', ''); $comment = Request::getVar('comment', ''); $editversion = Request::getVar('editversion', 'dev', 'post'); //$toolname = strtolower($tool['toolname']); $oldstatus = array(); // Create a Tool Version object $objV = new \Components\Tools\Tables\Version($this->database); // Create a Tool object $obj = new \Components\Tools\Tables\Tool($this->database); if ($id) { // make sure user is authorized to go further if (!$this->_checkAccess($id)) { App::abort(403, Lang::txt('COM_TOOLS_ALERTNOTAUTH')); return; } } if (!\Components\Tools\Models\Tool::validate($tool, $err, $id)) { // display form with errors //$title = Lang::txt(strtoupper($this->_option)).': '.Lang::txt('COM_TOOLS_EDIT_TOOL'); //Document::setTitle($title); if (is_array($err)) { foreach ($err as $error) { $this->setError($error); } } else { $this->setError($err); } if ($id) { // get tool status $obj->getToolStatus($id, $this->_option, $fstatus, $editversion); $tool['developers'] = $fstatus['developers']; $tool['membergroups'] = $fstatus['membergroups']; $tool['published'] = $fstatus['published']; } $this->editTask($tool); return; } $tool['vncGeometry'] = $tool['vncGeometryX'] . 'x' . $tool['vncGeometryY']; $tool['toolname'] = strtolower($tool['toolname']); $tool['developers'] = array_map('trim', explode(',', $tool['developers'])); $tool['membergroups'] = array_map('trim', explode(',', $tool['membergroups'])); $tool['hostreq'] = array_map('trim', explode(',', $tool['hostreq'])); // save tool info if (!$id) { $hzt = \Components\Tools\Models\Tool::createInstance($tool['toolname']); $hzt->toolname = $tool['toolname']; $hzt->title = $tool['title']; $hzt->published = 0; $hzt->state = 1; $hzt->priority = 3; $hzt->registered = $today; $hzt->state_changed = $today; $hzt->registered_by = User::get('username'); } else { $hzt = \Components\Tools\Models\Tool::getInstance($id); } // get tool id for newly registered tool $this->_toolid = $hzt->id; // save version info $hztv = $hzt->getRevision($editversion); if ($hztv) { $oldstatus = $hztv->toArray(); $oldstatus['toolstate'] = $hzt->state; $oldstatus['membergroups'] = $tool['membergroups']; if ($id) { $oldstatus['developers'] = $obj->getToolDevelopers($id); } } // NEW: save github repo as param $params = ''; $version = $objV->getVersionInfo($this->_toolid, 'dev'); if ($version && !empty($version[0])) { $txt = new \Hubzero\Config\Registry($version[0]->params); } else { $txt = new \Hubzero\Config\Registry(''); } $txt->set('github', $tool['github']); $ptype = empty($tool['publishType']) || $tool['publishType'] == 'standard' ? 'standard' : 'weber='; $txt->set('publishType', $ptype); $params = $txt->toString(); if ($editversion == 'dev') { if ($hztv === false) { Log::debug(__FUNCTION__ . "() HZTV createInstance dev_suffix={$dev_suffix}"); $hztv = \Components\Tools\Models\Version::createInstance($tool['toolname'], $tool['toolname'] . $dev_suffix); $oldstatus = $hztv->toArray(); $oldstatus['toolstate'] = $hzt->state; $oldstatus['membergroups'] = $tool['membergroups']; } if ($id) { $oldstatus['developers'] = $obj->getToolDevelopers($id); } $invokedir = $this->config->get('invokescript_dir', DS . 'apps'); $invokedir = rtrim($invokedir, DS); $hztv->toolid = $this->_toolid; $hztv->toolname = $tool['toolname']; $hztv->title = $tool['title']; $hztv->version = $tool['version']; $hztv->description = $tool['description']; $hztv->toolaccess = $tool['exec']; $hztv->codeaccess = $tool['code']; $hztv->wikiaccess = $tool['wiki']; $hztv->vnc_command = $invokedir . DS . $tool['toolname'] . DS . 'dev' . DS . 'middleware' . DS . 'invoke -T dev'; $hztv->vnc_geometry = $tool['vncGeometry']; $hztv->exportControl = $exportmap[$tool['exec']]; $hztv->state = 3; $hztv->instance = $tool['toolname'] . $dev_suffix; $hztv->mw = $this->config->get('default_mw', 'narwhal'); $hztv->hostreq = $tool['hostreq']; $hztv->params = $params; $hzt->add('version', $hztv->instance); } else { if ($hztv) { $hztv->toolid = $this->_toolid; $hztv->toolname = $tool['toolname']; $hztv->title = $tool['title']; $hztv->version = $tool['version']; $hztv->description = $tool['description']; $hztv->toolaccess = $tool['exec']; $hztv->codeaccess = $tool['code']; $hztv->wikiaccess = $tool['wiki']; $hztv->vnc_geometry = $tool['vncGeometry']; $hztv->exportControl = $exportmap[$tool['exec']]; $hztv->hostreq = $tool['hostreq']; $hzt->add('version', $hztv->instance); } } $this->_setTracAccess($tool['toolname'], $hztv->codeaccess, $hztv->wikiaccess); if ($this->_error) { App::abort(500, $this->_error); return; } // create/update developers group $gid = $hztv->getDevelopmentGroup(); if (empty($gid)) { $hzg = new \Hubzero\User\Group(); $hzg->cn = $group_prefix . strtolower($tool['toolname']); $hzg->create(); $hzg->set('type', 2); $hzg->set('description', Lang::txt('COM_TOOLS_DELEVOPMENT_GROUP', $tool['title'])); $hzg->set('created', Date::toSql()); $hzg->set('created_by', User::get('id')); } else { $hzg = \Hubzero\User\Group::getInstance($gid); } $hzg->set('members', $tool['developers']); $hztrac = \Hubzero\Trac\Project::find_or_create('app:' . $tool['toolname']); $hztrac->add_group_permission('apps', array('WIKI_ADMIN', 'MILESTONE_ADMIN', 'BROWSER_VIEW', 'LOG_VIEW', 'FILE_VIEW', 'CHANGESET_VIEW', 'ROADMAP_VIEW', 'TIMELINE_VIEW', 'SEARCH_VIEW')); $hztrac->add_group_permission($hzg->cn, array('WIKI_ADMIN', 'MILESTONE_ADMIN', 'BROWSER_VIEW', 'LOG_VIEW', 'FILE_VIEW', 'CHANGESET_VIEW', 'ROADMAP_VIEW', 'TIMELINE_VIEW', 'SEARCH_VIEW')); $hztv->set('owner', $hzg->cn); $hztv->add('owner', 'apps'); $hztv->set('member', $tool['membergroups']); // Add repo for new tools $auto_addrepo = $this->config->get('auto_addrepo', 1); if (!$id && $auto_addrepo) { $hzt->update(); // Make sure tool exists in database or gensvn won't configure apachce access to it $hztv->update(); // Make sure tool exists in database or gensvn won't configure apachce access to it // Run add repo $this->_addRepo($output, array('toolname' => $tool['toolname'], 'title' => $tool['title'], 'description' => $tool['description'])); if ($output['class'] != 'error') { $hzt->state = 2; $hzt->update(); } } // get ticket information if (empty($hzt->ticketid)) { $hzt->ticketid = $this->_createTicket($this->_toolid, $tool); } // create resource page $rid = \Components\Tools\Models\Tool::getResourceId($hzt->toolname, $hzt->id); if (empty($rid)) { include_once __DIR__ . DS . 'resource.php'; $resource = new Resource(); $rid = $resource->createPage($this->_toolid, $tool); // save authors by default //$objA = new \Components\Tools\Tables\Author($this->database); //if (!$id) { $objA->saveAuthors($tool['developers'], 'dev', $rid, '', $tool['toolname']); } if (!$id) { require_once __DIR__ . DS . 'authors.php'; $controller = new Authors(); $controller->saveTask(0, $rid, $tool['developers']); //$this->author_save(0, $rid, $tool['developers']); } } // display status page //$this->_task = 'status'; //$this->_msg = $id ? Lang::txt('COM_TOOLS_NOTICE_TOOL_INFO_CHANGED'): Lang::txt('COM_TOOLS_NOTICE_TOOL_INFO_REGISTERED'); $hzg->update(); $hzt->update(); $hztv->update(); // @FIXME: look $status = $hztv->toArray(); $status['toolstate'] = $hzt->state; $status['membergroups'] = $tool['membergroups']; $status['toolname'] = $tool['toolname']; if ($id) { $status['developers'] = $obj->getToolDevelopers($id); } // update history ticket if ($id && $oldstatus != $status && $editversion != 'current') { $this->_newUpdateTicket($hzt->id, $hzt->ticketid, $oldstatus, $status, $comment, 0, 1); } App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=status&app=' . $hzt->toolname), $id ? Lang::txt('COM_TOOLS_NOTICE_TOOL_INFO_CHANGED') : Lang::txt('COM_TOOLS_NOTICE_TOOL_INFO_REGISTERED')); }