private function updateServers(array $request_gerrit_servers)
 {
     foreach ($request_gerrit_servers as $id => $settings) {
         $server = $this->servers[$id];
         if (empty($server)) {
             continue;
         }
         if (!empty($settings['delete'])) {
             $this->gerrit_server_factory->delete($server);
             unset($this->servers[$id]);
             continue;
         }
         $host = isset($settings['host']) ? $settings['host'] : '';
         $ssh_port = isset($settings['ssh_port']) ? $settings['ssh_port'] : '';
         $http_port = isset($settings['http_port']) ? $settings['http_port'] : '';
         $login = isset($settings['login']) ? $settings['login'] : '';
         $identity_file = isset($settings['identity_file']) ? $settings['identity_file'] : '';
         $replication_ssh_key = isset($settings['replication_key']) ? $settings['replication_key'] : '';
         $use_ssl = isset($settings['use_ssl']);
         $gerrit_version = isset($settings['gerrit_version']) ? $settings['gerrit_version'] : '';
         $http_password = isset($settings['http_password']) ? $settings['http_password'] : '';
         if ($host !== '' && ($host != $server->getHost() || $ssh_port != $server->getSSHPort() || $http_port != $server->getHTTPPort() || $login != $server->getLogin() || $identity_file != $server->getIdentityFile() || $replication_ssh_key != $server->getReplicationKey() || $use_ssl != $server->usesSSL() || $gerrit_version != $server->getGerritVersion() || $http_password != $server->getHTTPPassword())) {
             $server->setHost($host)->setSSHPort($ssh_port)->setHTTPPort($http_port)->setLogin($login)->setIdentityFile($identity_file)->setReplicationKey($replication_ssh_key)->setUseSSL($use_ssl)->setGerritVersion($gerrit_version)->setHTTPPassword($http_password);
             $this->gerrit_server_factory->save($server);
             $this->servers[$server->getId()] = $server;
         }
     }
 }
 public function process()
 {
     $parameters = $this->getParametersAsArray();
     if (!empty($parameters[0])) {
         $repository_id = (int) $parameters[0];
     } else {
         $this->error('Missing argument repository id');
         return false;
     }
     if (!empty($parameters[1])) {
         $remote_server_id = (int) $parameters[1];
     } else {
         $this->error('Missing argument remote server id');
         return false;
     }
     $repository = $this->repository_factory->getRepositoryById($repository_id);
     if (!$repository) {
         $this->error('Failed to find repository ' . $repository_id);
         return false;
     }
     $server = $this->server_factory->getServerById($remote_server_id);
     if (!$server) {
         $this->error('Failed to find server ' . $remote_server_id);
         return false;
     }
     $project = $repository->getProject();
     if (!$project) {
         $this->error('Failed to find project ' . $repository->getProject());
         return false;
     }
     return $this->makeGerritProjectReadOnly($repository, $server, $project);
 }
 private function getServer()
 {
     try {
         return $this->gerrit_server_factory->getServerById($this->getServerId());
     } catch (Git_RemoteServer_NotFoundException $e) {
         return new Git_RemoteServer_GerritServer($this->getServerId(), '', '', '', '', '', '', false, '', '');
     }
 }
Esempio n. 4
0
 private function gerritProjectAlreadyExists($remote_server_id, GitRepository $repo)
 {
     $gerrit_server = $this->gerrit_server_factory->getServerById($remote_server_id);
     $driver = $this->driver_factory->getDriver($gerrit_server);
     $gerrit_project_name = $driver->getGerritProjectName($repo);
     return $driver->doesTheProjectExist($gerrit_server, $gerrit_project_name);
 }
 /**
  * Makes sure there is one copy of each key on each remote server
  * 
  * @param Git_RemoteServer_GerritServerFactory $remote_gerrit_factory
  * @return void
  * @throws Git_UserSynchronisationException
  */
 public function pushSSHKeys(PFUser $user)
 {
     if (!$this->isGerrit($user)) {
         return;
     }
     $gerrit_user = $this->getGerritUser($user);
     $user_keys = array_unique($user->getAuthorizedKeysArray());
     if (!$user_keys) {
         return;
     }
     $errors = array();
     $remote_servers = $this->remote_gerrit_factory->getRemoteServersForUser($user);
     foreach ($remote_servers as $remote_server) {
         try {
             $this->removeKeys($remote_server, $user_keys, $gerrit_user);
             $this->addKeys($remote_server, $user_keys, $gerrit_user);
         } catch (Git_Driver_Gerrit_Exception $e) {
             $errors[] = $e->getTraceAsString();
         }
     }
     if ($errors) {
         $message = implode(PHP_EOL, $errors);
         throw new Git_UserSynchronisationException($message);
     }
 }
 private function verbalizeRemoteServerId($remote_server_id, $with_link)
 {
     $txt = '#' . $remote_server_id;
     if ($with_link) {
         try {
             $server = $this->server_factory->getServerById($remote_server_id);
             $txt = $server->getHost();
         } catch (Git_RemoteServer_NotFoundException $exception) {
             $txt .= " GERRIT SERVER DELETED";
         }
     }
     return $txt;
 }
Esempio n. 7
0
 public function disconnectFromGerrit(GitRepository $repository)
 {
     $repository->getBackend()->disconnectFromGerrit($repository);
     $this->git_system_event_manager->queueRepositoryUpdate($repository);
     $server = $this->gerrit_server_factory->getServerById($repository->getRemoteServerId());
     $driver = $this->driver_factory->getDriver($server);
     $disconnect_option = $this->request->get(GitViews_RepoManagement_Pane_Gerrit::OPTION_DISCONNECT_GERRIT_PROJECT);
     if ($disconnect_option == GitViews_RepoManagement_Pane_Gerrit::OPTION_DELETE_GERRIT_PROJECT) {
         $this->git_system_event_manager->queueRemoteProjectDeletion($repository, $driver);
         $this->history_dao->groupAddHistory("git_disconnect_gerrit_delete", $repository->getName(), $repository->getProjectId());
     }
     if ($disconnect_option == GitViews_RepoManagement_Pane_Gerrit::OPTION_READONLY_GERRIT_PROJECT) {
         $this->git_system_event_manager->queueRemoteProjectReadOnly($repository, $driver);
         $this->history_dao->groupAddHistory("git_disconnect_gerrit_read_only", $repository->getName(), $repository->getProjectId());
     }
 }
 public function itDoesNotDeleteUsedServer()
 {
     expect($this->dao)->delete($this->server_id)->never();
     $this->factory->delete($this->main_gerrit_server);
 }