Example #1
0
 /**
  * Return available templates
  *
  * @todo check if it is a valid template directory
  * @return array
  */
 public static function listTemplate()
 {
     $res = array();
     $list = USVN_DirectoryUtils::listDirectory(USVN_Template::$locale_directory);
     foreach ($list as $filename) {
         if (USVN_Template::isValidTemplateDirectory(USVN_Template::$locale_directory . '/' . $filename)) {
             $res[] = $filename;
         }
     }
     return $res;
 }
Example #2
0
 /**
  * Look after SVN repositories to import into USVN
  *
  * @param string $path
  * @param array $options array(recursive => true|false)
  * @todo allow to set n level of recursion in options
  * @throws USVN_Exception
  * @return array
  */
 public static function lookAfterSVNRepositoriesToImport($path, $options = array())
 {
     $results = array();
     if (USVN_ImportSVNRepositories::canBeImported($path, $options)) {
         return array($path);
     }
     $folders = USVN_DirectoryUtils::listDirectory($path);
     foreach ($folders as $folder) {
         $current_path = $path . DIRECTORY_SEPARATOR . $folder;
         if (USVN_ImportSVNRepositories::canBeImported($current_path, $options)) {
             $results[] = $current_path;
         } else {
             if (isset($options['recursive']) && $options['recursive'] == true) {
                 $results = array_merge($results, USVN_ImportSVNRepositories::lookAfterSVNRepositoriesToImport($current_path, $options));
             }
         }
     }
     return $results;
 }
Example #3
0
 private static function _loadOldConfig(&$config, $old_config_file)
 {
     set_time_limit(0);
     $old_config = new USVN_Config_Ini($old_config_file['tmp_name'], USVN_CONFIG_SECTION, array('create' => false));
     // Import subversion configuration
     foreach ($old_config->subversion as $key => $value) {
         if ($config->subversion->{$key} != $value && $key != 'url') {
             if (!file_exists($value) || USVN_DirectoryUtils::copyr($value, $config->subversion->{$key}) === false) {
                 throw new USVN_Exception(T_("Can't copy the old configuration.\n"));
             }
         }
     }
     // Import database configuration
     if ($old_config->database->adapterName == 'PDO_SQLITE') {
         if (strpos($old_config->database->options->dbname, $old_config->subversion->path) === 0) {
             $old_config->database->options->dbname = $config->subversion->path . substr($old_config->database->options->dbname, strlen($old_config->subversion->path));
         }
     }
     $config->database = $old_config->database;
 }
Example #4
0
File: Test.php Project: phpscr/usvn
    protected function setUp()
    {
        error_reporting(E_ALL | E_STRICT);
        date_default_timezone_set('UTC');
        $this->_path = getcwd();
        $this->setConsoleLocale();
        USVN_Translation::initTranslation('en_US', 'app/locale');
        USVN_DirectoryUtils::removeDirectory('tests/');
        mkdir("tests");
        mkdir("tests/tmp");
        mkdir("tests/tmp/svn");
        file_put_contents('tests/test.ini', '[general]
subversion.path = "' . getcwd() . '/tests/tmp/"
subversion.passwd = "' . getcwd() . '/tests/tmp/htpasswd"
subversion.authz = "' . getcwd() . '/tests/tmp/authz"
subversion.url = "http://localhost/"
version = "0.8.4"
translation.locale = "en_US"
');
        $config = new USVN_Config_Ini('tests/test.ini', 'general');
        Zend_Registry::set('config', $config);
    }
Example #5
0
 protected function tearDown()
 {
     USVN_DirectoryUtils::removeDirectory($this->_menudir);
     parent::tearDown();
 }
Example #6
0
 public function test_isRootDirectory()
 {
     if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
         $this->assertFalse(USVN_DirectoryUtils::isRootDirectory('C:\\home'));
         $this->assertTrue(USVN_DirectoryUtils::isRootDirectory('C:'));
         $this->assertTrue(USVN_DirectoryUtils::isRootDirectory('C:\\'));
     } else {
         $this->assertFalse(USVN_DirectoryUtils::isRootDirectory('/home'));
         $this->assertTrue(USVN_DirectoryUtils::isRootDirectory('/'));
     }
 }
Example #7
0
 /**
  * Create standard svn directories
  * /trunk
  * /tags
  * /branches
  *
  * @param string Path to create subversion
  */
 public static function createStandardDirectories($path)
 {
     $tmpdir = USVN_DirectoryUtils::getTmpDirectory();
     try {
         mkdir($tmpdir . DIRECTORY_SEPARATOR . "trunk");
         mkdir($tmpdir . DIRECTORY_SEPARATOR . "branches");
         mkdir($tmpdir . DIRECTORY_SEPARATOR . "tags");
         USVN_SVNUtils::_svnImport($path, $tmpdir);
     } catch (Exception $e) {
         USVN_DirectoryUtils::removeDirectory($path);
         USVN_DirectoryUtils::removeDirectory($tmpdir);
         throw $e;
     }
     USVN_DirectoryUtils::removeDirectory($tmpdir);
 }
Example #8
0
 /**
  * Copy a file, or recursively copy a folder and its contents
  *
  * @author      Aidan Lister <*****@*****.**>
  * @version     1.0.1
  * @link        http://aidanlister.com/repos/v/function.copyr.php
  * @param       string   $source    Source path
  * @param       string   $dest      Destination path
  * @return      bool     Returns TRUE on success, FALSE on failure
  */
 public static function copyr($source, $dest)
 {
     // Check for symlinks
     if (is_link($source)) {
         return symlink(readlink($source), $dest);
     }
     // Simple copy for a file
     if (is_file($source)) {
         return copy($source, $dest);
     }
     // Make destination directory
     if (!is_dir($dest)) {
         mkdir($dest);
     }
     // Loop through the folder
     $dir = dir($source);
     while (false !== ($entry = $dir->read())) {
         // Skip pointers
         if ($entry == '.' || $entry == '..') {
             continue;
         }
         // Deep copy directories
         USVN_DirectoryUtils::copyr("{$source}/{$entry}", "{$dest}/{$entry}");
     }
     // Clean up
     $dir->close();
     return true;
 }
 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 #10
0
 public static function deleteProject($project_name)
 {
     $table = new USVN_Db_Table_Projects();
     $project = $table->fetchRow(array('projects_name = ?' => $project_name));
     if ($project === null) {
         throw new USVN_Exception(T_("Project %s doesn't exist."), $project_name);
     }
     $project->delete();
     $groups = new USVN_Db_Table_Groups();
     $where = $groups->getAdapter()->quoteInto("groups_name = ?", $project_name);
     $group = $groups->fetchRow($where);
     if ($group !== null) {
         $group->delete();
     }
     USVN_DirectoryUtils::removeDirectory(Zend_Registry::get('config')->subversion->path . DIRECTORY_SEPARATOR . 'svn' . DIRECTORY_SEPARATOR . $project_name);
 }