Example #1
0
 /**
  * Add and commit untracked/changed files
  *
  * This is helpful in case git add/commit failed during file upload
  *
  * @return  void
  */
 public function gitaddTask()
 {
     $id = Request::getVar('id', 0);
     $file = Request::getVar('file', '');
     // Initiate extended database class
     $obj = new Tables\Project($this->database);
     if (!$id or !$obj->loadProject($id)) {
         App::redirect(Route::url('index.php?option=' . $this->_option, false), Lang::txt('COM_PROJECTS_NOTICE_ID_NOT_FOUND'), 'error');
         return;
     }
     $url = Route::url('index.php?option=' . $this->_option . '&task=edit&id=' . $id, false);
     if (!$file) {
         App::redirect($url, Lang::txt('Please specify a file/directory path to add and commit into project'), 'error');
         return;
     }
     // Delete base dir for .git repos
     $prefix = $this->config->get('offroot', 0) ? '' : PATH_APP;
     $repodir = trim($this->config->get('webpath'), DS);
     $path = $prefix . DS . $repodir . DS . $obj->alias . DS . 'files';
     if (!is_file($path . DS . $file)) {
         App::redirect($url, Lang::txt('Error: File not found in the project, cannot add and commit'), 'error');
         return;
     }
     // Git helper
     require_once dirname(__DIR__) . DS . 'helpers' . DS . 'githelper.php';
     $gitHelper = new Helpers\Git($path);
     $commitMsg = '';
     // Git add & commit
     $gitHelper->gitAdd($file, $commitMsg);
     $gitHelper->gitCommit($commitMsg);
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&task=edit&id=' . $id, false), Lang::txt('File checked into project Git repo'));
 }
Example #2
0
 /**
  * Get files stats for all projects
  *
  * @param      array	$aliases	Project aliases for which to compute stats
  * @param      string		$get
  *
  * @return     mixed
  */
 public function getStats($aliases = array(), $get = 'total')
 {
     if (empty($aliases)) {
         return false;
     }
     $files = 0;
     $diskSpace = 0;
     $commits = 0;
     $usage = 0;
     // Publication space
     if ($get == 'pubspace') {
         // Load publications component configs
         $pubconfig = Component::params('com_publications');
         $base_path = DS . trim($pubconfig->get('webpath'), DS);
         chdir(PATH_APP . $base_path);
         exec('du -sk ', $out);
         $used = 0;
         if ($out && isset($out[0])) {
             $kb = str_replace('.', '', trim($out[0]));
             $used = $kb * 1024;
         }
         return $used;
     }
     // Compute size of local project repos
     foreach ($aliases as $alias) {
         $path = Helpers\Html::getProjectRepoPath($alias, 'files', false);
         // Make sure there is .git directory
         if (!is_dir($path) || !is_dir($path . DS . '.git')) {
             continue;
         }
         if ($get == 'diskspace') {
             $diskSpace = $diskSpace + $this->call('getDiskUsage', $params = array('path' => $path, 'working' => true, 'git' => true));
         } else {
             $git = new Helpers\Git($path);
             if ($get == 'commitCount') {
                 $nf = $git->callGit('ls-files --full-name ');
                 if ($nf && substr($nf[0], 0, 5) != 'fatal') {
                     $out = $git->callGit('log | grep "^commit" | wc -l');
                     if (is_array($out)) {
                         $c = end($out);
                         $commits = $commits + $c;
                     }
                 }
             } else {
                 $count = count($git->getFiles());
                 $files = $files + $count;
                 if ($count > 1) {
                     $usage++;
                 }
             }
         }
     }
     // Output
     switch ($get) {
         case 'total':
             return $files;
             break;
         case 'usage':
             return $usage;
             break;
         case 'diskspace':
             return $diskSpace;
             break;
         case 'commitCount':
             return $commits;
             break;
     }
 }