public function process()
 {
     global $sys_allow_restricted_users;
     $parameters = $this->getParametersAsArray();
     $project = null;
     if (!empty($parameters[0])) {
         $project = $this->getProject($parameters[0]);
     } else {
         $this->error('Missing argument project id');
         return false;
     }
     $repositoryName = '';
     if (!empty($parameters[1])) {
         $repositoryName = $parameters[1];
     } else {
         $this->error('Missing argument repository name');
         return false;
     }
     $userId = 0;
     if (!empty($parameters[2])) {
         $userId = $parameters[2];
     } else {
         $this->error('Missing argument user id');
         return false;
     }
     try {
         $repository = new GitRepository();
         $repository->setBackend(Backend::instance('Git', 'GitBackend'));
         $repository->setDescription('-- Default description --');
         //default access is private when restricted users are allowed
         if ($sys_allow_restricted_users == 1) {
             $repository->setAccess(GitRepository::PRIVATE_ACCESS);
         } else {
             $repository->setAccess(GitRepository::PUBLIC_ACCESS);
         }
         $user = null;
         if (!empty($userId)) {
             $user = UserManager::instance()->getUserById($userId);
         }
         if (!empty($user)) {
             $repository->setCreator($user);
         }
         $repository->setProject($project);
         $repository->setName($repositoryName);
         $repository->create();
         $this->done();
     } catch (GitDaoException $e) {
         $this->error($e->getMessage());
         return false;
     } catch (GitDriverException $e) {
         $this->error($e->getMessage());
         return false;
     } catch (GitBackendException $e) {
         $this->error($e->getMessage());
         return false;
     } catch (Exception $e) {
         $this->error($e->getMessage());
         return false;
     }
 }
Beispiel #2
0
 public function generateGitRepository()
 {
     echo "Create Git repo\n";
     $repository_factory = new GitRepositoryFactory(new GitDao(), $this->project_manager);
     $git_system_event_manager = new Git_SystemEventManager($this->system_event_manager, $repository_factory);
     $manager = $this->getGitRepositoryManager($repository_factory, $git_system_event_manager);
     $backend = $this->getGitBackendGitolite($git_system_event_manager);
     $repository = new GitRepository();
     $repository->setBackend($backend);
     $repository->setDescription("Git repository");
     $repository->setCreator($this->user_manager->getUserByUserName(self::TEST_USER_1_NAME));
     $repository->setProject($this->project_manager->getProjectByUnixName(self::PROJECT_TEST_GIT_SHORTNAME));
     $repository->setName('repo01');
     $manager->create($repository, $backend, array());
     return $this;
 }
 public function createReference($projectId, $repositoryName)
 {
     $controller = $this->getController();
     $projectId = intval($projectId);
     try {
         $creator = UserManager::instance()->getCurrentUser();
         $repository = new GitRepository();
         $repository->setBackend($this->backend_gitolite);
         $repository->setDescription(GitRepository::DEFAULT_DESCRIPTION);
         $repository->setCreator($creator);
         $repository->setProject(ProjectManager::instance()->getProject($projectId));
         $repository->setName($repositoryName);
         $this->manager->create($repository, $this->backend_gitolite);
         $this->history_dao->groupAddHistory("git_repo_create", $repositoryName, $projectId);
         $this->redirectToRepo($repository);
     } catch (Exception $exception) {
         $controller->addError($exception->getMessage());
     }
     $controller->redirect('/plugins/git/?action=index&group_id=' . $projectId);
     return;
 }
Beispiel #4
0
 public function createReference($projectId, $repositoryName)
 {
     // Uncomment the following line only for debug prupose if you ever need to
     // create a gitshell repo (good luck, luke, may the force be with you).
     //$this->createGitshellReference($projectId, $repositoryName);
     $c = $this->getController();
     $projectId = intval($projectId);
     try {
         $repository = new GitRepository();
         $repository->setBackend(new Git_Backend_Gitolite(new Git_GitoliteDriver()));
         $repository->setDescription('-- Default description --');
         $repository->setCreator(UserManager::instance()->getCurrentUser());
         $repository->setProject(ProjectManager::instance()->getProject($projectId));
         $repository->setName($repositoryName);
         $this->manager->create($repository);
     } catch (Exception $exception) {
         $c->addError($exception->getMessage());
     }
     $c->redirect('/plugins/git/?action=index&group_id=' . $projectId);
     return;
 }
Beispiel #5
0
 /**
  * @deprecated Should use GitRepository::getInstanceFrom row instead.
  * @param GitRepository $repository
  * @param type $result
  */
 public function hydrateRepositoryObject(GitRepository $repository, $result)
 {
     $repository->setName($result[self::REPOSITORY_NAME]);
     $repository->setPath($result[self::REPOSITORY_PATH]);
     $repository->setId($result[self::REPOSITORY_ID]);
     $repository->setDescription($result[self::REPOSITORY_DESCRIPTION]);
     $repository->setParentId($result[self::REPOSITORY_PARENT]);
     $project = ProjectManager::instance()->getProject($result[self::FK_PROJECT_ID]);
     $repository->setProject($project);
     $repository->setCreationDate($result[self::REPOSITORY_CREATION_DATE]);
     $user = UserManager::instance()->getUserById($result[self::REPOSITORY_CREATION_USER_ID]);
     $repository->setCreator($user);
     $repository->setIsInitialized($result[self::REPOSITORY_IS_INITIALIZED]);
     $repository->setDeletionDate($result[self::REPOSITORY_DELETION_DATE]);
     $repository->setAccess($result[self::REPOSITORY_ACCESS]);
     $repository->setMailPrefix($result[self::REPOSITORY_MAIL_PREFIX]);
     $repository->setBackendType($result[self::REPOSITORY_BACKEND_TYPE]);
     $repository->setNamespace($result[self::REPOSITORY_NAMESPACE]);
     $repository->setBackupPath($result[self::REPOSITORY_BACKUP_PATH]);
     $repository->setScope($result[self::REPOSITORY_SCOPE]);
     $repository->setRemoteServerId($result[self::REMOTE_SERVER_ID]);
     $repository->setRemoteServerDisconnectDate($result[self::REMOTE_SERVER_DISCONNECT_DATE]);
     $repository->setRemoteProjectDeletionDate($result[self::REMOTE_SERVER_DELETE_DATE]);
     $repository->setRemoteServerMigrationStatus($result[self::REMOTE_SERVER_MIGRATION_STATUS]);
     $repository->loadNotifiedMails();
     /* Here just for reviewer test, will be replaced by real DB data in a future changeset*/
     $result[self::ENABLE_ONLINE_EDIT] = false;
     if ($result[self::ENABLE_ONLINE_EDIT] && GitConfig::instance()->isOnlineEditEnabled()) {
         $repository->enableOnlineEdit();
     }
 }
 public function process()
 {
     $parameters = $this->getParametersAsArray();
     //print_r($parameters);
     $project = null;
     if (!empty($parameters[0])) {
         $project = $this->getProject($parameters[0]);
     } else {
         $this->error('Missing argument project id');
         return false;
     }
     $repositoryName = '';
     if (!empty($parameters[1])) {
         $repositoryName = $parameters[1];
     } else {
         $this->error('Missing argument repository name');
         return false;
     }
     $parentId = '';
     if (!empty($parameters[2])) {
         $parentId = $parameters[2];
     } else {
         $this->error('Missing argument parent id');
         return false;
     }
     $userId = 0;
     if (!empty($parameters[3])) {
         $userId = $parameters[3];
     } else {
         $this->error('Missing argument user id');
         return false;
     }
     try {
         $repository = new GitRepository();
         $repository->setProject($project);
         $repository->setId($parentId);
         //load before setting creator
         $repository->load();
         $user = null;
         if (!empty($userId)) {
             $user = UserManager::instance()->getUserById($userId);
         }
         if (!empty($user)) {
             $repository->setCreator($user);
         }
         $repository->forkShell($repositoryName);
         $this->done();
     } catch (GitDaoException $e1) {
         $this->error($e1->getMessage());
         return false;
     } catch (GitDriverException $e2) {
         $this->error($e2->getMessage());
         return false;
     } catch (GitBackendException $e3) {
         $this->error($e3->getMessage());
         return false;
     } catch (Exception $e4) {
         $this->error($e4->getMessage());
         return false;
     }
 }
 /**
  * Returns a default-value-filled repository
  * @return GitRepository
  */
 public function buildRepository(Project $project, $repository_name, PFUser $creator, Git_Backend_Interface $backend, $description = GitRepository::DEFAULT_DESCRIPTION)
 {
     $repository = new GitRepository();
     $repository->setBackend($backend);
     $repository->setDescription($description);
     $repository->setCreator($creator);
     $repository->setProject($project);
     $repository->setName($repository_name);
     return $repository;
 }
Beispiel #8
0
 /**
  * Clone a repository, it inherits access
  * @param String forkName
  */
 public function forkShell($forkName)
 {
     $clone = new GitRepository();
     $clone->setName($forkName);
     $clone->setProject($this->getProject());
     $clone->setParent($this);
     $clone->setCreationDate(date('Y-m-d H:i:s'));
     $clone->setCreator($this->getCreator());
     $clone->setAccess($this->getAccess());
     $clone->setIsInitialized(1);
     $clone->setDescription('-- Default description --');
     $this->getBackend()->createFork($clone);
 }
 public function testUserRepositoryDoesNotBelongToAnotherUser()
 {
     $creator = new PFUser(array('language_id' => 1));
     $creator->setId(123);
     $user = new PFUser(array('language_id' => 1));
     $user->setId(456);
     $repo = new GitRepository();
     $repo->setCreator($creator);
     $repo->setScope(GitRepository::REPO_SCOPE_INDIVIDUAL);
     $this->assertFalse($repo->belongsTo($user));
 }
Beispiel #10
0
 public function hydrateRepositoryObject(GitRepository $repository, $result)
 {
     $repository->setName($result[self::REPOSITORY_NAME]);
     $repository->setPath($result[self::REPOSITORY_PATH]);
     $repository->setId($result[self::REPOSITORY_ID]);
     $repository->setDescription($result[self::REPOSITORY_DESCRIPTION]);
     $repository->setParentId($result[self::REPOSITORY_PARENT]);
     $project = ProjectManager::instance()->getProject($result[self::FK_PROJECT_ID]);
     $repository->setProject($project);
     $repository->setCreationDate($result[self::REPOSITORY_CREATION_DATE]);
     $user = UserManager::instance()->getUserById($result[self::REPOSITORY_CREATION_USER_ID]);
     $repository->setCreator($user);
     $repository->setIsInitialized($result[self::REPOSITORY_IS_INITIALIZED]);
     $repository->setDeletionDate($result[self::REPOSITORY_DELETION_DATE]);
     $repository->setAccess($result[self::REPOSITORY_ACCESS]);
     $repository->setMailPrefix($result[self::REPOSITORY_MAIL_PREFIX]);
     $repository->setBackendType($result[self::REPOSITORY_BACKEND_TYPE]);
     $repository->setNamespace($result[self::REPOSITORY_NAMESPACE]);
     $repository->setScope($result[self::REPOSITORY_SCOPE]);
     $repository->loadNotifiedMails();
 }
Beispiel #11
0
 public function createReference($projectId, $repositoryName)
 {
     // Uncomment the following line only for debug prupose if you ever need to
     // create a gitshell repo (good luck, luke, may the force be with you).
     //$this->createGitshellReference($projectId, $repositoryName);
     $c = $this->getController();
     $projectId = intval($projectId);
     $repository = new GitRepository();
     $repository->setBackend(new Git_Backend_Gitolite(new Git_GitoliteDriver()));
     if ($repository->isNameValid($repositoryName) === false) {
         $c->addError($this->getText('actions_input_format_error', array($repository->getBackend()->getAllowedCharsInNamePattern(), GitDao::REPO_NAME_MAX_LENGTH)));
         $c->redirect('/plugins/git/?action=index&group_id=' . $projectId);
         return false;
     }
     $project = ProjectManager::instance()->getProject($projectId);
     $repository->setDescription('-- Default description --');
     $repository->setCreator(UserManager::instance()->getCurrentUser());
     $repository->setProject($project);
     $repository->setName($repositoryName);
     if (!$this->factory->isRepositoryExistingByName($project, $repositoryName)) {
         $repository->create();
     } else {
         $c->addError($this->getText('actions_create_repo_exists', array($repositoryName)));
     }
     $c->redirect('/plugins/git/?action=index&group_id=' . $projectId);
     return;
 }