Exemplo n.º 1
0
 /**
  * Serve file (usually via public link)
  *
  * @param   string   $type
  * @param   integer  $projectid
  * @param   string   $query
  * @return  void
  */
 public function serve($type = '', $projectid = 0, $query = '')
 {
     $this->_area = $this->onProjectAreas();
     if ($type != $this->_area['name']) {
         return false;
     }
     $data = json_decode($query);
     if (!isset($data->file) || !$projectid) {
         return false;
     }
     $file = $data->file;
     $disp = isset($data->disp) ? $data->disp : 'inline';
     $limited = isset($data->limited) ? $data->limited : 0;
     $hash = isset($data->hash) ? $data->hash : 0;
     $repoName = isset($data->repo) ? $data->repo : 'local';
     // Instantiate a project
     $model = new \Components\Projects\Models\Project($projectid);
     if (!$model->exists() || $limited == 1 && !$model->access('member')) {
         // Throw error
         App::abort(403, Lang::txt('COM_PROJECTS_ERROR_ACTION_NOT_AUTHORIZED'));
     }
     // Load repo
     $repo = new \Components\Projects\Models\Repo($model, $repoName);
     $deleteTemp = false;
     if ($hash) {
         $tempPath = sys_get_temp_dir();
         $tempName = 'temp-' . \Components\Projects\Helpers\Html::generateCode(4, 4, 0, 1, 0) . basename($file);
         $serve = $tempPath . DS . $tempName;
         // Get file content
         $repo->call('content', $params = array('fileName' => $file, 'hash' => $hash, 'target' => $serve));
         $deleteTemp = true;
     } else {
         $serve = $repo->get('path') . DS . $file;
     }
     // Ensure the file exist
     if (!file_exists($serve)) {
         // Throw error
         App::abort(404, Lang::txt('COM_PROJECTS_FILE_NOT_FOUND'));
     }
     // Initiate a new content server and serve up the file
     $server = new \Hubzero\Content\Server();
     $server->filename($serve);
     $server->disposition($disp);
     $server->acceptranges(false);
     // @TODO fix byte range support
     $server->saveas(basename($file));
     $result = $server->serve();
     if ($deleteTemp) {
         // Delete downloaded temp file
         Filesystem::delete($serve);
     }
     if (!$result) {
         // Should only get here on error
         App::abort(404, Lang::txt('PLG_PROJECTS_FILES_SERVER_ERROR'));
     } else {
         exit;
     }
     return;
 }
Exemplo n.º 2
0
 /**
  * Optimize git repo
  *
  * @return  void
  */
 public function gitgcTask()
 {
     $id = Request::getVar('id', 0);
     // Get repo model
     require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'models' . DS . 'repo.php';
     $project = new Models\Project($id);
     if (!$project->exists()) {
         App::redirect(Route::url('index.php?option=' . $this->_option, false), Lang::txt('COM_PROJECTS_NOTICE_ID_NOT_FOUND'), 'error');
         return;
     }
     $repo = new \Components\Projects\Models\Repo($project, 'local');
     $params = array('path' => $repo->get('path'), 'adv' => true);
     $repo->call('optimize', $params);
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&task=edit&id=' . $id, false), Lang::txt('Git repo optimized'));
 }
Exemplo n.º 3
0
 /**
  * Collect overall projects stats
  *
  * @return  array
  */
 public function getStats($model, $cron = false, $publishing = false, $period = 'alltime', $limit = 3)
 {
     // Incoming
     $period = Request::getVar('period', $period);
     $limit = Request::getInt('limit', $limit);
     if ($cron == true) {
         $publicOnly = false;
         $saveLog = true;
     } else {
         $publicOnly = $model->reviewerAccess('admin') ? false : true;
         $saveLog = false;
     }
     // Collectors
     $stats = array();
     $updated = NULL;
     $lastLog = NULL;
     $pastMonth = Date::of(time() - 32 * 24 * 60 * 60)->toSql('Y-m-d');
     $thisYearNum = Date::format('y');
     $thisMonthNum = Date::format('m');
     $thisWeekNum = Date::format('W');
     // Pull recent stats
     if ($this->loadLog($thisYearNum, $thisMonthNum, $thisWeekNum)) {
         $lastLog = json_decode($this->stats, true);
         $updated = $this->processed;
     } else {
         // Save stats
         $saveLog = true;
     }
     // Get project table class
     $tbl = $model->table();
     // Get inlcude /exclude lists
     $exclude = $tbl->getProjectsByTag('test', true, 'id');
     $include = $tbl->getProjectsByTag('test', false, 'id');
     $validProjects = $tbl->getProjectsByTag('test', false, 'alias');
     $validCount = count($validProjects) > 0 ? count($validProjects) : 1;
     // Collect overview stats
     $stats['general'] = array('total' => $tbl->getCount(array('exclude' => $exclude, 'all' => 1), true), 'setup' => $tbl->getCount(array('exclude' => $exclude, 'setup' => 1), true), 'active' => $tbl->getCount(array('exclude' => $exclude, 'active' => 1), true), 'public' => $tbl->getCount(array('exclude' => $exclude, 'private' => '0'), true), 'sponsored' => $tbl->getCount(array('exclude' => $exclude, 'reviewer' => 'sponsored'), true), 'sensitive' => $tbl->getCount(array('exclude' => $exclude, 'reviewer' => 'sensitive'), true), 'new' => $tbl->getCount(array('exclude' => $exclude, 'created' => date('Y-m', time()), 'all' => 1), true));
     $active = $stats['general']['active'] ? $stats['general']['active'] : 1;
     $total = $stats['general']['total'] ? $stats['general']['total'] : 1;
     // Activity stats
     $objAA = new Activity($this->_db);
     $recentlyActive = $tbl->getCount(array('exclude' => $exclude, 'timed' => $pastMonth, 'active' => 1), true);
     $perc = round($recentlyActive * 100 / $active) . '%';
     $stats['activity'] = array('total' => $objAA->getActivityStats($include, 'total'), 'average' => $objAA->getActivityStats($include, 'average'), 'usage' => $perc);
     $stats['topActiveProjects'] = $objAA->getTopActiveProjects($exclude, 5, $publicOnly);
     // Collect team stats
     $objO = new Owner($this->_db);
     $multiTeam = $objO->getTeamStats($exclude, 'multi');
     $activeTeam = $objO->getTeamStats($exclude, 'registered');
     $invitedTeam = $objO->getTeamStats($exclude, 'invited');
     $multiProjectUsers = $objO->getTeamStats($exclude, 'multiusers');
     $teamTotal = $activeTeam + $invitedTeam;
     $perc = round($multiTeam * 100 / $total) . '%';
     $stats['team'] = array('total' => $teamTotal, 'average' => $objO->getTeamStats($exclude, 'average'), 'multi' => $perc, 'multiusers' => $multiProjectUsers);
     $stats['topTeamProjects'] = $objO->getTopTeamProjects($exclude, $limit, $publicOnly);
     // Collect files stats
     if ($lastLog) {
         $stats['files'] = $lastLog['files'];
     } else {
         // Get repo model
         require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'models' . DS . 'repo.php';
         // Compute
         $repo = new \Components\Projects\Models\Repo();
         $fTotal = $repo->getStats($validProjects);
         $fAverage = number_format($fTotal / $validCount, 0);
         $fUsage = $repo->getStats($validProjects, 'usage');
         $fDSpace = $repo->getStats($validProjects, 'diskspace');
         $fCommits = $repo->getStats($validProjects, 'commitCount');
         $pDSpace = $repo->getStats($validProjects, 'pubspace');
         $perc = round($fUsage * 100 / $active) . '%';
         $stats['files'] = array('total' => $fTotal, 'average' => $fAverage, 'usage' => $perc, 'diskspace' => \Hubzero\Utility\Number::formatBytes($fDSpace), 'commits' => $fCommits, 'pubspace' => \Hubzero\Utility\Number::formatBytes($pDSpace));
     }
     // Collect publication stats
     if ($publishing) {
         $objP = new \Components\Publications\Tables\Publication($this->_db);
         $objPV = new \Components\Publications\Tables\Version($this->_db);
         $prPub = $objP->getPubStats($include, 'usage');
         $perc = round($prPub * 100 / $total) . '%';
         $stats['pub'] = array('total' => $objP->getPubStats($include, 'total'), 'average' => $objP->getPubStats($include, 'average'), 'usage' => $perc, 'released' => $objP->getPubStats($include, 'released'), 'versions' => $objPV->getPubStats($include));
     }
     // Save weekly stats
     if ($saveLog) {
         $this->year = $thisYearNum;
         $this->month = $thisMonthNum;
         $this->week = $thisWeekNum;
         $this->processed = Date::toSql();
         $this->stats = json_encode($stats);
         $this->store();
     }
     $stats['updated'] = $updated ? $updated : NULL;
     return $stats;
 }