/**
  * PopulateProjects
  *
  * Populates the internal list of projects
  *
  * @access protected
  * @throws Exception if file cannot be read
  */
 protected function PopulateProjects()
 {
     if (!($fp = fopen($this->projectConfig, 'r'))) {
         throw new Exception(sprintf(__('Failed to open project list file %1$s'), $this->projectConfig));
     }
     $projectRoot = GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('projectroot'));
     while (!feof($fp) && ($line = fgets($fp))) {
         if (preg_match('/^([^\\s]+)(\\s.+)?$/', $line, $regs)) {
             if (is_file($projectRoot . $regs[1] . '/HEAD')) {
                 try {
                     $projObj = new GitPHP_Project($projectRoot, $regs[1]);
                     if (isset($regs[2]) && !empty($regs[2])) {
                         $projOwner = trim($regs[2]);
                         if (!empty($projOwner)) {
                             $projObj->SetOwner($projOwner);
                         }
                     }
                     $this->projects[$regs[1]] = $projObj;
                 } catch (Exception $e) {
                     GitPHP_Log::GetInstance()->Log($e->getMessage());
                 }
             } else {
                 GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not a git project', $projectRoot . $regs[1]));
             }
         }
     }
     fclose($fp);
 }
 /**
  * PopulateProjects
  *
  * Populates the internal list of projects
  *
  * @access protected
  * @throws Exception if file cannot be read
  */
 protected function PopulateProjects()
 {
     $projectRoot = GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('projectroot'));
     $use_errors = libxml_use_internal_errors(true);
     $xml = simplexml_load_file($this->projectConfig);
     libxml_clear_errors();
     libxml_use_internal_errors($use_errors);
     if (!$xml) {
         throw new Exception(sprintf('Could not load SCM manager config %1$s', $this->projectConfig));
     }
     foreach ($xml->repositories->repository as $repository) {
         if ($repository->type != 'git') {
             GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not a git project', $repository->name));
             continue;
         }
         if ($repository->public != 'true') {
             GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not public', $repository->name));
             continue;
         }
         $projName = trim($repository->name);
         if (empty($projName)) {
             continue;
         }
         if (is_file($projectRoot . $projName . '/HEAD')) {
             try {
                 $projObj = new GitPHP_Project($projectRoot, $projName);
                 $projOwner = trim($repository->contact);
                 if (!empty($projOwner)) {
                     $projObj->SetOwner($projOwner);
                 }
                 $projDesc = trim($repository->description);
                 if (!empty($projDesc)) {
                     $projObj->SetDescription($projDesc);
                 }
                 $this->projects[$projName] = $projObj;
             } catch (Exception $e) {
                 GitPHP_Log::GetInstance()->Log($e->getMessage());
             }
         } else {
             GitPHP_Log::GetInstance()->Log(sprintf('%1$s is not a git project', $projName));
         }
     }
 }
示例#3
0
 public function testCompareOwner()
 {
     $project = new GitPHP_Project(GITPHP_TEST_PROJECTROOT, 'testrepoexported.git', $this->getMock('GitPHP_ProjectLoadStrategy_Interface'));
     $project->SetOwner('A owner');
     $project2 = new GitPHP_Project(GITPHP_TEST_PROJECTROOT, 'testrepo.git', $this->getMock('GitPHP_ProjectLoadStrategy_Interface'));
     $project->SetOwner('B owner');
     $this->assertEquals(0, GitPHP_Project::CompareOwner($project, $project));
     $this->assertLessThan(0, GitPHP_Project::CompareOwner($project, $project2));
     $this->assertGreaterThan(0, GitPHP_Project::CompareOwner($project2, $project));
     $project->SetCategory('b');
     $this->assertEquals(0, GitPHP_Project::CompareOwner($project, $project));
     $this->assertGreaterThan(0, GitPHP_Project::CompareOwner($project, $project2));
     $this->assertLessThan(0, GitPHP_Project::CompareOwner($project2, $project));
     $project2->SetCategory('a');
     $this->assertEquals(0, GitPHP_Project::CompareOwner($project, $project));
     $this->assertGreaterThan(0, GitPHP_Project::CompareOwner($project, $project2));
     $this->assertLessThan(0, GitPHP_Project::CompareOwner($project2, $project));
 }
示例#4
0
 /**
  * Applies override settings for a project
  *
  * @param GitPHP_Project $project the project object
  * @param array $projData project data array
  */
 protected function ApplyProjectSettings($project, $projData)
 {
     if (!$project) {
         return;
     }
     if (isset($projData['category']) && is_string($projData['category'])) {
         $project->SetCategory($projData['category']);
     }
     if (isset($projData['owner']) && is_string($projData['owner'])) {
         $project->SetOwner($projData['owner']);
     }
     if (isset($projData['description']) && is_string($projData['description'])) {
         $project->SetDescription($projData['description']);
     }
     if (isset($projData['cloneurl']) && is_string($projData['cloneurl'])) {
         $project->SetCloneUrl($projData['cloneurl']);
     }
     if (isset($projData['pushurl']) && is_string($projData['pushurl'])) {
         $project->SetPushUrl($projData['pushurl']);
     }
     if (isset($projData['bugpattern']) && is_string($projData['bugpattern'])) {
         $project->SetBugPattern($projData['bugpattern']);
     }
     if (isset($projData['bugurl']) && is_string($projData['bugurl'])) {
         $project->SetBugUrl($projData['bugurl']);
     }
     if (isset($projData['compat'])) {
         $project->SetCompat($projData['compat']);
     }
     if (isset($projData['website']) && is_string($projData['website'])) {
         $project->SetWebsite($projData['website']);
     }
     if (!empty($projData['allowedusers'])) {
         $project->SetAllowedUsers($projData['allowedusers']);
     }
 }