Ejemplo n.º 1
0
 public function indexAction(Request $request, SessionInterface $session)
 {
     Util::checkUserIsLoggedInAndRedirect();
     $menuSelectedCategory = 'svn';
     $session->set('selected_product_id', SystemProduct::SYS_PRODUCT_SVN_HOSTING);
     $isSVNAdministrator = $session->get('user/svn_administrator_flag');
     $emptyName = false;
     $duplicateName = false;
     $emptyCode = false;
     $duplicateCode = false;
     $clientId = $session->get('client/id');
     if ($request->request->has('confirm_new_svn_repository')) {
         $name = Util::cleanRegularInputField($request->request->get('name'));
         $code = Util::cleanRegularInputField($request->request->get('code'));
         $description = Util::cleanRegularInputField($request->request->get('description'));
         if (empty($name)) {
             $emptyName = true;
         }
         if (empty($code)) {
             $emptyCode = true;
         } else {
             $svn_repository_exists = $this->getRepository(SvnRepository::class)->getByCode(mb_strtolower($code), $clientId);
             if ($svn_repository_exists) {
                 $duplicateCode = true;
             }
         }
         if (!$emptyName && !$emptyCode && !$duplicateName && !$duplicateCode) {
             $currentDate = Util::getServerCurrentDateTime();
             $repoId = $this->getRepository(SvnRepository::class)->addRepo($clientId, $session->get('user/id'), $name, $description, $code, $currentDate);
             $repoPath = UbirimiContainer::get()['subversion.path'] . Util::slugify($session->get('client/company_domain')) . '/' . Util::slugify($name);
             /* create the repository on disk */
             @mkdir(UbirimiContainer::get()['subversion.path'] . Util::slugify($session->get('client/company_domain')), 0700, true);
             @mkdir(UbirimiContainer::get()['subversion.path'] . Util::slugify($session->get('client/company_domain')) . '/' . Util::slugify($name), 0700, true);
             try {
                 $this->getRepository(SvnRepository::class)->createSvn($repoPath);
                 SVNUtils::createStandardDirectories($repoPath);
                 /* add the user */
                 $this->getRepository(SvnRepository::class)->addUser($repoId, $session->get('user/id'));
                 $this->getRepository(SvnRepository::class)->updateUserPermissions($repoId, $session->get('user/id'), 1, 1);
                 /* apache config */
                 $this->getRepository(SvnRepository::class)->apacheConfig(Util::slugify($session->get('client/company_domain')), Util::slugify($name));
             } catch (\Exception $e) {
             }
             $userEvent = new UserEvent(UserEvent::STATUS_NEW_SVN, $session->get('user/first_name'), $session->get('user/last_name'), $session->get('user/username'), null, $session->get('user/email'), array('svnRepoId' => $repoId, 'svnRepositoryName' => $name));
             UbirimiContainer::get()['dispatcher']->dispatch(UbirimiEvents::USER, $userEvent);
             $this->getLogger()->addInfo('ADD SVN Repository ' . Util::slugify($name), $this->getLoggerContext());
             return new RedirectResponse('/svn-hosting/administration/all-repositories');
         }
     }
     return $this->render(__DIR__ . '/../../Resources/views/administration/AddRepository.php', get_defined_vars());
 }
Ejemplo n.º 2
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 = 25, $start = 0, $end = 0)
 {
     $repository = 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 = ConsoleUtils::runCmdCaptureMessageUnsafe(SVNUtils::svnCommand("log --xml {$revision} {$limit} {$repository}"), $return);
     if ($return) {
         throw new Exception("Can't get subversion repository logs: " . $message);
     }
     return SVNLog::parseOutput($message);
 }
Ejemplo n.º 3
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 = SVNUtils::getCannocialPath($path);
         } else {
             $path = $newpath;
         }
         return "\"file:///" . str_replace('\\', '/', $path) . "\"";
     }
     $newpath = realpath($path);
     if ($newpath === FALSE) {
         $newpath = SVNUtils::getCannocialPath($path);
     }
     return escapeshellarg('file://' . $newpath);
 }
Ejemplo n.º 4
0
 /**
  * Create SVN repository with standard organisation
  * /trunk
  * /tags
  * /branches
  *
  * @param string Path to create subversion
  */
 public function createSvn($path)
 {
     $escape_path = escapeshellarg($path);
     $message = ConsoleUtils::runCmdCaptureMessage(SVNUtils::svnadminCommand("create {$escape_path}"), $return);
     if ($return) {
         throw new Exception("Can't create subversion repository: " . $message);
     }
 }