Example #1
0
 /**
  * Create SVN repositories
  *
  * @param string Project name
  * @param bool Create standard directories (/trunk, /tags, /branches)
  */
 private static function createProjectSVN($project_name, $create_dir)
 {
     $config = Zend_Registry::get('config');
     $path = $config->subversion->path . DIRECTORY_SEPARATOR . 'svn' . DIRECTORY_SEPARATOR . $project_name;
     if (!USVN_SVNUtils::isSVNRepository($path, true)) {
         $directories = explode(DIRECTORY_SEPARATOR, $path);
         $tmp_path = '';
         foreach ($directories as $directory) {
             $tmp_path .= $directory . DIRECTORY_SEPARATOR;
             if (USVN_SVNUtils::isSVNRepository($tmp_path)) {
                 $tmp_path = '';
                 break;
             }
         }
         if ($tmp_path === $path . DIRECTORY_SEPARATOR) {
             @mkdir($path, 0700, true);
             USVN_SVNUtils::createSVN($path);
             if ($create_dir) {
                 USVN_SVNUtils::createStandardDirectories($path);
             }
         } else {
             $message = "One of these repository's subfolders is a subversion repository.";
             throw new USVN_Exception(T_("Can't create subversion repository:<br />%s"), $message);
         }
     } else {
         $message = $project_name . " is a SVN repository.";
         throw new USVN_Exception(T_("Can't create subversion repository:<br />%s"), $message);
     }
 }
Example #2
0
 protected function setUp()
 {
     parent::setUp();
     mkdir('tests/fakehome');
     chmod('tests/fakehome', 00);
     putenv('HOME=tests/fakehome');
     $this->_saveHOME = getenv("HOME");
     USVN_SVNUtils::createSvn('tests/tmp/svn directory');
     USVN_SVNUtils::createStandardDirectories('tests/tmp/svn directory');
     USVN_SVNUtils::checkoutSvn('tests/tmp/svn directory', 'tests/tmp/out');
     file_put_contents('tests/tmp/svn directory/hooks/pre-revprop-change.bat', "@ECHO OFF\r\n");
     file_put_contents('tests/tmp/svn directory/hooks/pre-revprop-change', "#!/bin/sh\nexit 0");
     chmod('tests/tmp/svn directory/hooks/pre-revprop-change', 0700);
     $path = getcwd();
     chdir('tests/tmp/out');
     mkdir('trunk/testdir');
     `svn add trunk/testdir`;
     touch('trunk/testfile');
     `svn add trunk/testfile`;
     `svn commit --non-interactive --username toto -m Test`;
     touch('trunk/testfile2');
     `svn add trunk/testfile2`;
     `svn commit --non-interactive --username tutu -m Test2`;
     `svn propset svn:date --revprop -r3 "1984-12-03T01:02:03.218987Z" .`;
     chdir($path);
 }
Example #3
0
 /**
  * Create SVN repositories
  *
  * @param string Project name
  * @param bool Create standard directories (/trunk, /tags, /branches)
  */
 private static function createProjectSVN($project_name, $create_dir)
 {
     $config = Zend_Registry::get('config');
     $path = $config->subversion->path . DIRECTORY_SEPARATOR . 'svn' . DIRECTORY_SEPARATOR . $project_name;
     if (!USVN_SVNUtils::isSVNRepository($path, true)) {
         $directories = explode(DIRECTORY_SEPARATOR, $path);
         $tmp_path = '';
         foreach ($directories as $directory) {
             $tmp_path .= $directory . DIRECTORY_SEPARATOR;
             if (USVN_SVNUtils::isSVNRepository($tmp_path)) {
                 $tmp_path = '';
                 break;
             }
         }
         if ($tmp_path === $path . DIRECTORY_SEPARATOR) {
             if ($mod = $config->subversion->chmod) {
                 $mod = intval($mod, 8);
             } else {
                 $mod = 0700;
             }
             @mkdir($path, $mod, true);
             @chmod($path, $mod);
             // mkdir is bogus
             USVN_SVNUtils::createSVN($path);
             if ($create_dir) {
                 USVN_SVNUtils::createStandardDirectories($path);
             }
             // apply files rights
             $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST);
             foreach ($iterator as $file) {
                 @chmod((string) $file, $mod);
             }
             // apply special dir rights on repo/db
             if ($mod = $config->subversion->chmod_db) {
                 $mod = intval($mod, 8);
                 $dbPath = $path . '/db';
                 @chmod($dbPath, $mod);
                 $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dbPath, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST);
                 foreach ($iterator as $file) {
                     if ($file->isDir()) {
                         @chmod((string) $file, $mod);
                     }
                 }
                 //$escape_path = escapeshellarg($path);
                 //USVN_ConsoleUtils::runCmdCaptureMessage("chmod g+s $escape_path/*/db && find $escape_path/*/db -type d ! -perm -g=s | xargs chmod g+s", $return);
                 //@USVN_DirectoryUtils::chmodRecursive($path.'/db', intval($mod, 8));
             }
         } else {
             $message = "One of these repository's subfolders is a subversion repository.";
             throw new USVN_Exception(T_("Can't create subversion repository:<br />%s"), $message);
         }
     } else {
         $message = $project_name . " is a SVN repository.";
         throw new USVN_Exception(T_("Can't create subversion repository:<br />%s"), $message);
     }
 }
Example #4
0
 public function testInsertProjectOkSVNAlreadyExist()
 {
     USVN_SVNUtils::createSVN('tests/tmp/' . DIRECTORY_SEPARATOR . 'svn' . DIRECTORY_SEPARATOR . 'InsertProjectOk');
     $table = new USVN_Db_Table_Projects();
     $project = $table->fetchNew();
     $project->setFromArray(array('projects_name' => 'InsertProjectOk', 'projects_start_date' => '1984-12-03 00:00:00'));
     $project->save();
     $this->assertTrue($table->isAProject('InsertProjectOk'), "Le projet n'est pas cree");
     $this->assertTrue(USVN_SVNUtils::isSVNRepository('tests/tmp/svn/InsertProjectOk'), "Le repository n'est pas cree");
 }
Example #5
0
 public function test_getInformationsAboutSystem()
 {
     $config = Zend_Registry::get('config');
     $informations = USVN_Update::getInformationsAboutSystem();
     $xml = new SimpleXMLElement($informations);
     $this->assertEquals(phpversion(), (string) $xml->php->version);
     $this->assertEquals(PHP_OS, (string) $xml->host->os);
     $this->assertEquals(php_uname(), (string) $xml->host->uname);
     $this->assertEquals(implode(".", USVN_SVNUtils::getSvnVersion()), (string) $xml->subversion->version);
     $this->assertEquals("en_US", (string) $xml->usvn->translation);
     $this->assertEquals("mysql", (string) $xml->usvn->databaseadapter);
     $this->assertEquals("", (string) $xml->php->ini->register_globals);
     foreach ($xml->php->extension as $e) {
         if ($e == "pdo_sqlite") {
             return;
         }
     }
     $this->fail("pdo_sdqlite extension not found");
 }
Example #6
0
 /**
  * Check if a SVN repository can be imported
  *
  * @param string $path
  * @throws USVN_Exception
  * @return bool
  */
 public static function canBeImported($path, $options = array('verbose' => false))
 {
     if (!is_string($path)) {
         throw new USVN_Exception(T_('%s must be a string: %s'), '$path');
     }
     $config = Zend_Registry::get('config');
     $path = realpath($path);
     if (USVN_DirectoryUtils::firstDirectoryIsInclude($path, $config->subversion->path)) {
         if (is_dir($path) && USVN_SVNUtils::isSVNRepository($path)) {
             return true;
         } elseif (isset($options['verbose']) && $options['verbose'] == true) {
             if (!is_dir($path)) {
                 print "'{$path}' is not a directory.\n";
             } elseif (!USVN_SVNUtils::isSVNRepository($path)) {
                 print "'{$path}' is not a SVN repository\n";
             }
         }
     } elseif (isset($options['verbose']) && $options['verbose'] == true) {
         print "'{$path}' is not in subversion's path ({$config->subversion->path}).\n";
     }
     return false;
 }
Example #7
0
 private function getTopLink($project, $path)
 {
     $url = USVN_SVNUtils::getSubversionUrl($project, $path);
     $str = "<h2>";
     $str .= '<a href=\'javascript:getListFile("/");\'>root</a>&nbsp;/&nbsp;';
     $list = array();
     $path = preg_replace("#/+#", '/', $path);
     while ($path != '/' && $path != '\\') {
         array_push($list, $path);
         $path = dirname($path);
     }
     $list = array_reverse($list);
     foreach ($list as $path) {
         $str .= '<a href=\'javascript:getListFile("' . urlencode($path) . '");\'>' . basename($path) . '</a>&nbsp;/&nbsp;';
     }
     $str .= "</h2>";
     $str .= sprintf(T_("Checkout URL : %s"), '<a href="' . $url . '">' . $url . '</a>');
     $str .= "<br /><br /><h3><a href='javascript:dumpRights(\"{$path}\");'>";
     $str .= sprintf(T_("Apply rights on %s"), $path);
     $str .= "</a></h3>";
     return $str;
 }
Example #8
0
 /**
  * @param string Path to repository
  * @param int Number of revision (0 = no limit)
  * @return array  Key are revision number example:
  *		array(
  *			1 => array("author" => "duponc_j", "msg" => "Test", date=> 1265413),
  *			2 => array("revision" => "crivis_s", "msg" => "Test2", date=>4565654)
  *		)
  *
  * Date are unix timestamp
  */
 public static function log($repository, $limit = 0, $start = 0, $end = 0)
 {
     $repository = USVN_SVNUtils::getRepositoryPath($repository);
     if ($limit) {
         $limit = escapeshellarg($limit);
         $limit = "--limit {$limit}";
     } else {
         $limit = "";
     }
     if ($start) {
         $revision = "-r {$start}";
         if ($end) {
             $revision .= ":{$end}";
         }
     } else {
         $revision = "";
     }
     $message = USVN_ConsoleUtils::runCmdCaptureMessageUnsafe(USVN_SVNUtils::svnCommand("log --xml {$revision} {$limit} {$repository}"), $return);
     if ($return) {
         throw new USVN_Exception(T_("Can't get subversion repository logs: %s"), $message);
     }
     return USVN_SVNLog::parseOutput($message);
 }
Example #9
0
 public function test_listFile()
 {
     USVN_SVNUtils::createSVN('tests/tmp/svn/test');
     USVN_SVNUtils::createStandardDirectories('tests/tmp/svn/test');
     USVN_SVNUtils::checkoutSvn('tests/tmp/svn/test', 'tests/tmp/out');
     $path = getcwd();
     chdir('tests/tmp/out');
     mkdir('trunk/testdir');
     `svn add trunk/testdir`;
     touch('trunk/testfile');
     `svn add trunk/testfile`;
     `svn commit --non-interactive -m Test`;
     chdir($path);
     $svn = new USVN_SVN('test');
     $res = $svn->listFile('/');
     $this->assertEquals(3, count($res));
     $this->assertContains(array("name" => "trunk", "isDirectory" => true, "path" => "/trunk/"), $res);
     $this->assertContains(array("name" => "branches", "isDirectory" => true, "path" => "/branches/"), $res);
     $this->assertContains(array("name" => "tags", "isDirectory" => true, "path" => "/tags/"), $res);
     $res = $svn->listFile('/trunk');
     $this->assertEquals(2, count($res));
     $this->assertContains(array("name" => "testdir", "isDirectory" => true, "path" => "/trunk/testdir/"), $res);
     $this->assertContains(array("name" => "testfile", "isDirectory" => false, "path" => "/trunk/testfile"), $res);
 }
Example #10
0
 /**
  * Return informations about the system into a XML string.
  *
  * @return string XML
  */
 public static function getInformationsAboutSystem()
 {
     $config = Zend_Registry::get('config');
     $xml = new SimpleXMLElement("<informations></informations>");
     $os = $xml->addChild('host');
     $os->addChild('os', PHP_OS);
     $os->addChild('uname', php_uname());
     $subversion = $xml->addChild('subversion');
     $subversion->addChild('version', implode(".", USVN_SVNUtils::getSvnVersion()));
     $usvn = $xml->addChild('usvn');
     $usvn->addChild('version', $config->version);
     $usvn->addChild('translation', $config->translation->locale);
     $usvn->addChild('databaseadapter', $config->database->adapterName);
     $php = $xml->addChild('php');
     $php->addChild('version', phpversion());
     // $ini = $php->addChild('ini');
     // foreach(ini_get_all() as $var => $value)
     // 	$ini->addChild($var, htmlspecialchars((string)$value['local_value']));
     // foreach (get_loaded_extensions() as $ext)
     // 	$php->addChild('extension', $ext);
     // $apache = $xml->addChild('host');
     // if (function_exists("apache_get_modules"))
     // 	foreach (apache_get_modules() as $ext)
     // 		$apache->addChild("module", $ext);
     return $xml->asXml();
 }
Example #11
0
 /**
  * Return clean version of a Subversion repository path betwenn ' and with file:// before
  *
  * @param string Path to repository
  * @return string absolute path to repository
  */
 public static function getRepositoryPath($path)
 {
     if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
         $newpath = realpath($path);
         if ($newpath === FALSE) {
             $path = str_replace('//', '/', str_replace('\\', '/', $path));
             $path = USVN_SVNUtils::getCannocialPath($path);
         } else {
             $path = $newpath;
         }
         return "\"file:///" . str_replace('\\', '/', $path) . "\"";
     }
     $newpath = realpath($path);
     if ($newpath === FALSE) {
         $newpath = USVN_SVNUtils::getCannocialPath($path);
     }
     return escapeshellarg('file://' . $newpath);
 }
 public function indexAction()
 {
     $this->view->config = Zend_Registry::get('config');
     $this->view->subversionversion = implode('.', USVN_SVNUtils::getSvnVersion());
 }
Example #13
0
 public function testImportSVNRepositoriesOk()
 {
     try {
         $table = new USVN_Db_Table_Users();
         $obj = $table->fetchNew();
         $obj->setFromArray(array('users_login' => 'user_test', 'users_password' => 'password', 'users_firstname' => 'firstname', 'users_lastname' => 'lastname', 'users_email' => '*****@*****.**'));
         $obj->save();
     } catch (USVN_Exception $e) {
         print $e->getMessage() . "\n";
         $this->fail();
     }
     $path = 'tests/tmp/svn/test/';
     mkdir($path);
     USVN_SVNUtils::createSvn($path . 'test');
     USVN_SVNUtils::createSvn($path . 'test2');
     mkdir($path . 'test3');
     USVN_SVNUtils::createSvn($path . 'test3/test3');
     $options = array('recursive' => true, 'login' => 'user_test');
     $imp = new USVN_ImportSVNRepositories();
     $results = $imp->lookAfterSVNRepositoriesToImport($path, $options);
     if (count($results) != 3) {
         $this->fail();
     }
     $imp->addSVNRepositoriesToImport($results, $options);
     try {
         $imp->importSVNRepositories();
     } catch (USVN_Exception $e) {
         print $e->getMessage() . "\n";
         $this->fail();
     }
     USVN_DirectoryUtils::removeDirectory($path);
 }
Example #14
0
 public function testCreateProjectWithoutGroupWithoutAdminButWithSvnDirectories()
 {
     $project = USVN_Project::createProject(array('projects_name' => 'InsertProjectOk', 'projects_start_date' => '1984-12-03 00:00:00'), "test", false, false, false, true);
     $table = new USVN_Db_Table_Projects();
     $this->assertTrue($table->isAProject('InsertProjectOk'), "Le projet n'est pas cree");
     $this->assertTrue(USVN_SVNUtils::isSVNRepository('tests/tmp/svn/InsertProjectOk'), "Le repository n'est pas cree");
     $table = new USVN_Db_Table_Groups();
     $this->assertFalse($table->isAGroup('InsertProjectOk'), "Le groupe est cree alors qu'il ne doit pas");
     $this->assertFalse($project->userIsAdmin($this->_user));
     $this->assertEquals(array(array('name' => 'branches', 'isDirectory' => true, 'path' => '/branches/'), array('name' => 'tags', 'isDirectory' => true, 'path' => '/tags/'), array('name' => 'trunk', 'isDirectory' => true, 'path' => '/trunk/')), USVN_SVNUtils::listSVN(Zend_Registry::get('config')->subversion->path . '/svn/InsertProjectOk', '/'));
 }
Example #15
0
 /**
  * Display a file using appropriate highlighting
  *
  * @return void
  */
 public function commitAction()
 {
     include_once 'geshi/geshi.php';
     $this->view->project = $this->_project;
     $config = new USVN_Config_Ini(USVN_CONFIG_FILE, USVN_CONFIG_SECTION);
     $project_name = str_replace(USVN_URL_SEP, '/', $this->_project->name);
     $local_project_path = USVN_SVNUtils::getRepositoryPath($config->subversion->path . "/svn/" . $project_name . "/");
     $commit = $this->getRequest()->getParam('commit');
     $base = $commit - 1;
     $cmd = USVN_SVNUtils::svnCommand("log --non-interactive --revision {$commit} {$local_project_path}");
     $log = USVN_ConsoleUtils::runCmdCaptureMessageUnsafe($cmd, $return);
     if (!$return) {
         $cmd = USVN_SVNUtils::svnCommand("diff --non-interactive --revision " . ($commit - 1) . ":{$commit} {$local_project_path}");
         $diff = USVN_ConsoleUtils::runCmdCaptureMessageUnsafe($cmd, $return);
         if (!$return) {
             $diff = explode("\n", $diff);
             array_pop($diff);
             // Skip the final "\n"
             $file = NULL;
             $count = 0;
             $indiff = FALSE;
             $tab_diff = array();
             $tab_index = NULL;
             foreach ($diff as $line) {
                 if (strpos($line, 'Index: ') === 0) {
                     $file = substr($line, 7);
                     $tab_diff[$file] = array();
                     $indiff = FALSE;
                 } elseif (!$indiff) {
                     if (preg_match('#^@@ \\-([0-9]+)(,([0-9]+))? \\+([0-9]+)(,([0-9]+))? @@$#', $line, $tmp)) {
                         $tab_index = count($tab_diff[$file]);
                         $tab_diff[$file][$tab_index] = array($base => array('begin' => $tmp[1], 'end' => empty($tmp[3]) ? $tmp[1] : $tmp[3], 'content' => array()), $commit => array('begin' => $tmp[4], 'end' => empty($tmp[6]) ? $tmp[4] : $tmp[6], 'content' => array()), 'common' => array());
                         $count = 0;
                         $indiff = TRUE;
                     }
                 } else {
                     $diff_char = substr($line, 0, 1);
                     if ($diff_char == '\\') {
                         continue;
                     }
                     $line = htmlentities(substr($line, 1));
                     if ($diff_char == '-') {
                         $tab_diff[$file][$tab_index][$base]['content'][$count++] = $line;
                     } elseif ($diff_char == '+') {
                         $tab_diff[$file][$tab_index][$commit]['content'][$count++] = $line;
                     } else {
                         $tab_diff[$file][$tab_index]['common'][$count++] = $line;
                     }
                 }
             }
             $this->view->diff = $tab_diff;
             $this->view->commit = $commit;
             $this->view->base = $base;
             unset($tab_diff);
             $log = explode("\n", $log);
             if (preg_match('#^r[0-9]* \\| (.*) \\| ([0-9-]+ [0-9:]+) [^\\|]* \\| ([0-9]*)[^\\|]*$#', $log[1], $tmp)) {
                 $this->view->author = $tmp[1];
                 $this->view->date = $tmp[2];
                 $this->view->log = NULL;
                 for ($i = 0; $i < $tmp[3]; ++$i) {
                     $this->view->log .= ($this->view->log != NULL ? "\n" : '') . $log[3 + $i];
                 }
             }
         } else {
             throw new USVN_Exception(T_("Can't read from subversion repository.\nCommand:\n%s\n\nError:\n%s"), $cmd, $message);
         }
     } else {
         throw new USVN_Exception(T_("Can't read from subversion repository.\nCommand:\n%s\n\nError:\n%s"), $cmd, $message);
     }
 }
Example #16
0
 public function test_getSubversionUrl()
 {
     $this->assertEquals("http://localhost/test/toto/tutu", USVN_SVNUtils::getSubversionUrl("test", "/toto/tutu"));
 }
 public function test_createWithSVNDirectories()
 {
     $_POST["creategroup"] = 0;
     $_POST["addmetogroup"] = 0;
     $_POST["admin"] = 0;
     $_POST['createsvndir'] = 1;
     $project = $this->create_project();
     $this->assertFalse($project->userIsAdmin('god'));
     $this->assertNull($this->get_created_group());
     $this->assertEquals(array(array('name' => 'branches', 'isDirectory' => true, 'path' => '/branches/'), array('name' => 'tags', 'isDirectory' => true, 'path' => '/tags/'), array('name' => 'trunk', 'isDirectory' => true, 'path' => '/trunk/')), USVN_SVNUtils::listSVN(Zend_Registry::get('config')->subversion->path . '/svn/Test', '/'));
 }
Example #18
0
File: SVN.php Project: phpscr/usvn
 /**
  * @param string Path into subversion directory.
  * @return associative array Array of files or directory included in the path.
  */
 public function listFile($path)
 {
     return USVN_SVNUtils::listSvn($this->_repository, $path);
 }