Esempio n. 1
0
 /**
  * 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'));
 }
Esempio n. 2
0
 /**
  * Publish a tool
  *
  * @return     void
  */
 public function publishTask()
 {
     // Set the layout (note: all the views for this controller use the same layout)
     $this->view->setLayout('display');
     // Create a Tool object
     $obj = new \Components\Tools\Tables\Tool($this->database);
     // Do we have an alias?
     if ($alias = Request::getVar('app', '')) {
         $this->_toolid = $obj->getToolId($alias);
     }
     // Do we have a tool ID
     if (!$this->_toolid) {
         App::abort(403, Lang::txt('COM_TOOLS_ERROR_TOOL_NOT_FOUND'));
         return;
     }
     // Get the tool status
     $obj->getToolStatus($this->_toolid, $this->_option, $status, 'dev');
     // Check for a status
     if (count($status) <= 0) {
         App::abort(500, Lang::txt('COM_TOOLS_ERR_CANNOT_RETRIEVE'));
         return;
     }
     $result = true;
     Log::debug("publish(): checkpoint 1:{$result}");
     // get config
     // Create a Tool Version object
     $objV = new \Components\Tools\Tables\Version($this->database);
     $objV->getToolVersions($this->_toolid, $tools, '', 1);
     // make checks
     if (!is_numeric($status['revision'])) {
         // bad format
         $result = false;
         $this->setError(Lang::txt('COM_TOOLS_ERR_MISSING_REVISION_OR_BAD_FORMAT'));
     } else {
         if (count($tools) > 0 && $status['revision']) {
             // check for duplicate revision
             foreach ($tools as $t) {
                 if ($t->revision == $status['revision']) {
                     $result = false;
                     $this->setError(Lang::txt('COM_TOOLS_ERR_REVISION_EXISTS') . ' ' . $status['revision']);
                 }
             }
             // check that revision number is greater than in previous version
             $currentrev = $objV->getCurrentVersionProperty($status['toolname'], 'revision');
             if ($currentrev && intval($currentrev) > intval($status['revision'])) {
                 $result = false;
                 $this->setError(Lang::txt('COM_TOOLS_ERR_REVISION_GREATER'));
             }
         }
     }
     // Log checkpoint
     Log::debug("publish(): checkpoint 2:{$result}, check revision");
     // check if version is valid
     if (!\Components\Tools\Models\Tool::validateVersion($status['version'], $error_v, $this->_toolid)) {
         $result = false;
         $this->setError($error_v);
     }
     // Log checkpoint
     Log::debug("publish(): checkpoint 3:{$result}, running finalize tool");
     // Run finalizetool
     if (!$this->getError()) {
         if ($this->_finalizeTool($out)) {
             $this->setMessage(Lang::txt('COM_TOOLS_Version finalized.'));
         } else {
             $this->setError($out);
             $result = false;
         }
     }
     Log::debug("publish(): checkpoint 4:{$result}, running doi stuff");
     // Register DOI handle
     if ($result && $this->config->get('new_doi', 0)) {
         include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'doi.php';
         // Collect metadata
         $url = Request::base() . ltrim(Route::url('index.php?option=com_resources&id=' . $status['resourceid'] . '&rev=' . $status['revision']), DS);
         // Check if DOI exists for this revision
         $objDOI = new \Components\Resources\Tables\Doi($this->database);
         $bingo = $objDOI->getDoi($status['resourceid'], $status['revision'], '', 1);
         // DOI already exists for this revision
         if ($bingo) {
             $this->setError(Lang::txt('COM_TOOLS_ERR_DOI_ALREADY_EXISTS') . ': ' . $bingo);
         } else {
             // Get latest DOI label
             $latestdoi = $objDOI->getLatestDoi($status['resourceid']);
             $newlabel = $latestdoi ? intval($latestdoi) + 1 : 1;
             // Collect metadata
             $metadata = array('targetURL' => $url, 'title' => htmlspecialchars(stripslashes($status['title'])), 'version' => $status['version'], 'abstract' => htmlspecialchars(stripslashes($status['description'])));
             // Get authors
             $objA = new \Components\Tools\Tables\Author($this->database);
             $authors = $objA->getAuthorsDOI($status['resourceid']);
             // Register DOI
             $doiSuccess = $objDOI->registerDOI($authors, $this->config, $metadata, $doierr);
             // Save [new] DOI record
             if ($doiSuccess) {
                 if (!$objDOI->loadDOI($status['resourceid'], $status['revision'])) {
                     if ($objDOI->saveDOI($status['revision'], $newlabel, $status['resourceid'], $status['toolname'], 0, $doiSuccess)) {
                         $this->setMessage(Lang::txt('COM_TOOLS_SUCCESS_DOI_CREATED') . ' ' . $doiSuccess);
                     } else {
                         $this->setError(Lang::txt('COM_TOOLS_ERR_DOI_STORE_FAILED'));
                         $result = false;
                     }
                 } else {
                     $this->setError(Lang::txt('COM_TOOLS_DOI already exists: ') . $objDOI->doi);
                 }
             } else {
                 $this->setError(Lang::txt('COM_TOOLS_ERR_DOI_STORE_FAILED'));
                 $this->setError($doierr);
                 $result = false;
             }
         }
     }
     if ($result) {
         $invokedir = rtrim($this->config->get('invokescript_dir', DS . 'apps'), "\\/");
         $hzt = \Components\Tools\Models\Tool::getInstance($this->_toolid);
         $hztv_cur = $hzt->getCurrentVersion();
         $hztv_dev = $hzt->getDevelopmentVersion();
         Log::debug("publish(): checkpoint 6:{$result}, running database stuff");
         // create tool instance in the database
         $newtool = $status['toolname'] . '_r' . $status['revision'];
         // get version id
         $currentid = is_object($hztv_cur) ? $hztv_cur->id : null;
         $new = $currentid ? 0 : 1;
         $devid = $hztv_dev->id;
         $exportmap = array('@OPEN' => null, '@GROUP' => null, '@US' => 'us', '@PU' => 'pu', '@D1' => 'd1');
         $new_hztv = \Components\Tools\Models\Version::createInstance($status['toolname'], $newtool);
         $new_hztv->toolname = $status['toolname'];
         $new_hztv->instance = $newtool;
         $new_hztv->toolid = $this->_toolid;
         $new_hztv->state = 1;
         $new_hztv->title = $status['title'];
         $new_hztv->version = $status['version'];
         $new_hztv->revision = $status['revision'];
         $new_hztv->description = $status['description'];
         $new_hztv->toolaccess = $status['exec'];
         $new_hztv->codeaccess = $status['code'];
         $new_hztv->wikiaccess = $status['wiki'];
         $new_hztv->vnc_geometry = $status['vncGeometry'];
         $new_hztv->vnc_command = $invokedir . DS . $status['toolname'] . DS . 'r' . $status['revision'] . DS . 'middleware' . DS . 'invoke -T r' . $status['revision'];
         $new_hztv->mw = $status['mw'];
         $new_hztv->released = Date::toSql();
         $new_hztv->released_by = User::get('username');
         $new_hztv->license = $status['license'];
         $new_hztv->fulltxt = $status['fulltxt'];
         $new_hztv->exportControl = $exportmap[strtoupper($status['exec'])];
         $new_hztv->owner = $hztv_dev->owner;
         $new_hztv->member = $hztv_dev->member;
         $new_hztv->vnc_timeout = $hztv_dev->vnc_timeout;
         $new_hztv->hostreq = $hztv_dev->hostreq;
         $new_hztv->params = $status['params'];
         if (!$new_hztv->update()) {
             $this->setError(Lang::txt('COM_TOOLS_ERROR_UPDATING_INSTANCE'));
             $result = false;
         } else {
             $this->_setTracAccess($new_hztv->toolname, $new_hztv->codeaccess, $new_hztv->wikiaccess);
             // update tool entry
             $hzt = \Components\Tools\Models\Tool::getInstance($this->_toolid);
             $hzt->add('version', $new_hztv->instance);
             $hzt->update();
             if ($hzt->published != 1) {
                 $hzt->published = 1;
                 // save tool info
                 if (!$hzt->update()) {
                     $this->setError(Lang::txt('COM_TOOLS_ERROR_UPDATING_INSTANCE'));
                 } else {
                     $this->setMessage(Lang::txt('COM_TOOLS_NOTICE_TOOL_MARKED_PUBLISHED'));
                 }
             }
             // unpublish previous version
             if (!$new) {
                 if ($hzt->unpublishVersion($hztv_cur->instance)) {
                     $this->setMessage(Lang::txt('COM_TOOLS_NOTICE_UNPUBLISHED_PREV_VERSION_DB'));
                 } else {
                     $this->setError(Lang::txt('COM_TOOLS_ERR_FAILED_TO_UNPUBLISH_PREV_VERSION_DB'));
                 }
             }
             // get version id
             $currentid = $new_hztv->id;
             // save authors for this version
             $objA = new \Components\Tools\Tables\Author($this->database);
             if ($objA->saveAuthors($status['developers'], $currentid, $status['resourceid'], $status['revision'], $status['toolname'])) {
                 $this->setMessage(Lang::txt('COM_TOOLS_AUTHORS_SAVED'));
             } else {
                 $this->setError(Lang::txt('COM_TOOLS_ERROR_SAVING_AUTHORS', $currentid));
             }
             // transfer screenshots
             if ($devid && $currentid) {
                 include_once __DIR__ . DS . 'screenshots.php';
                 $screenshots = new Screenshots();
                 if ($screenshots->transfer($devid, $currentid, $status['resourceid'])) {
                     $this->setMessage(Lang::txt('COM_TOOLS_SCREENSHOTS_TRANSFERRED'));
                 } else {
                     $this->setError(Lang::txt('COM_TOOLS_ERROR_TRANSFERRING_SCREENSHOTS'));
                 }
             }
             include_once __DIR__ . DS . 'resource.php';
             $resource = new Resource();
             // update and publish resource page
             $resource->updatePage($status['resourceid'], $status, '1', $new);
         }
     }
     Log::debug("publish(): checkpoint 7:{$result}, gather output");
     // Set errors to view
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Set messages to view
     $this->view->messages = $this->getMessages();
     // Output HTML
     if (!($no_html = Request::getInt('no_html', 0))) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=pipeline&task=status&app=' . $alias));
         return;
     }
     $this->view->display();
 }