Пример #1
0
 /**
  * Cancel a tool contribution
  *
  * @return     void
  */
 public function cancelTask()
 {
     // 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);
         }
     }
     // check access rights
     if (!$this->_checkAccess($this->_toolid)) {
         App::abort(403, Lang::txt('COM_TOOLS_ALERTNOTAUTH'));
         return;
     }
     // get tool status
     $obj->getToolStatus($this->_toolid, $this->_option, $status, 'dev');
     if (!$status) {
         App::abort(404, Lang::txt('COM_TOOLS_ERR_EDIT_CANNOT_FIND'));
         return;
     }
     if ($status['state'] == \Components\Tools\Helpers\Html::getStatusNum('Abandoned')) {
         App::abort(404, Lang::txt('COM_TOOLS_ERR_ALREADY_CANCELLED'));
         return;
     }
     if ($status['published'] == 1) {
         App::abort(404, Lang::txt('COM_TOOLS_ERR_CANNOT_CANCEL_PUBLISHED_TOOL'));
         return;
     }
     // unpublish resource page
     include_once __DIR__ . DS . 'resource.php';
     $resource = new Resource();
     $resource->updatePage($status['resourceid'], $status, '4');
     // change tool status to 'abandoned' and priority to 'lowest'
     $obj->updateTool($this->_toolid, \Components\Tools\Helpers\Html::getStatusNum('Abandoned'), 5);
     // add comment to ticket
     $this->_updateTicket($this->_toolid, '', '', Lang::txt('COM_TOOLS_NOTICE_TOOL_CANCELLED'), 0, 1, 5);
     // continue output
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=pipeline'), Lang::txt('COM_TOOLS_NOTICE_TOOL_CANCELLED'));
 }
Пример #2
0
 /**
  * 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();
 }
Пример #3
0
 /**
  * Finalize a tool
  *
  * @param      string &$out Output messages container
  * @return     boolean True on success, False if errors
  */
 protected function _finalizeTool(&$out = '')
 {
     Log::debug("finalizeTool(): checkpoint 1");
     if (!$this->_toolid) {
         return false;
     }
     // We need to make sure we don't prepend with PATH_APP if we already have a root-relative path
     $tarball_path = $this->config->get('sourcecodePath', 'site/protected/source');
     if (substr($tarball_path, 0, 1) != DS) {
         $tarball_path = PATH_APP . DS . trim($this->config->get('sourcecodePath', 'site/protected/source'), DS);
     }
     Log::debug("finalizeTool(): checkpoint 2");
     // Create a Tool object
     $obj = new \Components\Tools\Tables\Tool($this->database);
     $obj->getToolStatus($this->_toolid, $this->_option, $status, 'dev');
     if (count($status) > 0) {
         // Make sure the path exist
         if (!is_dir('/tmp')) {
             if (!Filesystem::makeDirectory('/tmp')) {
                 $out .= Lang::txt('COM_TOOLS_ERR_UNABLE_TO_CREATE_PATH') . ' /tmp';
                 return false;
             }
         }
         $token = md5(uniqid());
         $fname = '/tmp/license' . $this->_toolid . '-r' . $status['revision'] . '-' . $token . '.txt';
         $handle = fopen($fname, "w");
         fwrite($handle, $status['license']);
         fclose($handle);
         chmod($fname, 0664);
         $command = '/usr/bin/sudo -u apps /usr/bin/finalizetool -hubdir ' . PATH_CORE . '/../ -title "' . $status['title'] . '" -version "' . $status['version'] . '" -license ' . $fname . ' ' . $status['toolname'];
         Log::debug("finalizeTool(): checkpoint 3: {$command}");
         if (!$this->_invokescript($command, Lang::txt('COM_TOOLS_NOTICE_VERSION_FINALIZED'))) {
             $out .= " invoke script failure";
             unlink($fname);
             return false;
         }
         unlink($fname);
         if ($this->getError()) {
             $out .= " invoke script failure";
             return false;
         }
         // get tarball
         $tar = explode("source tarball: /tmp/", $this->getMessage());
         $tar = $tar[1];
         $file_path = $tarball_path . DS . $status['toolname'];
         // Make sure the upload path exist
         if (!is_dir($file_path)) {
             if (!Filesystem::makeDirectory($file_path)) {
                 Log::debug("findalizeTool(): failed to create tarball path {$file_path}");
                 $out .= Lang::txt('COM_TOOLS_ERR_UNABLE_TO_CREATE_TAR_PATH');
                 return false;
             }
         }
         Log::debug("finalizeTool(): checkpoint 4: " . DS . 'tmp' . DS . $tar . " to " . $file_path . '/' . $tar);
         if (!@copy(DS . 'tmp' . DS . $tar, $file_path . '/' . $tar)) {
             $out .= " failed to copy {$tar} to {$file_path}";
             Log::debug("findalizeTool(): failed tarball copy");
             return false;
         } else {
             Log::debug("findalizeTool(): deleting tmp files");
             exec('sudo -u apps rm -f /tmp/' . $tar, $out, $result);
         }
         return true;
     } else {
         $out = Lang::txt('COM_TOOLS_ERR_CANNOT_RETRIEVE');
         return false;
     }
     return true;
 }