Example #1
0
 /**
  * Returns a new RepositoryQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return    RepositoryQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof RepositoryQuery) {
         return $criteria;
     }
     $query = new RepositoryQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
 /**
  * @param sfWebRequest $request
  * @return void
  */
 public function execute($request)
 {
     $this->list = null;
     $this->userIsAuthenticated = $this->getUser()->isAuthenticated();
     $this->currentBreadCrumbFile = null;
     $this->currentBreadCrumbBranch = null;
     $this->currentBreadCrumbRepository = null;
     $this->fileBreadCrumbList = array();
     $this->branchBreadCrumbList = array();
     $this->repositoryBreadCrumbList = array();
     if ($fileId = $request->getParameter('file')) {
         $this->currentBreadCrumbFile = FileQuery::create()->filterById($fileId)->findOne();
         $this->fileBreadCrumbList = FileQuery::create()->filterById($fileId, Criteria::NOT_EQUAL)->filterByBranchId($this->currentBreadCrumbFile->getBranchId())->filterByIsBinary(false)->orderByFilename()->find();
     }
     $branchId = $request->getParameter('branch');
     if (!$branchId) {
         $branchId = null != $this->currentBreadCrumbFile ? $this->currentBreadCrumbFile->getBranchId() : null;
     }
     if (null !== $branchId) {
         $this->currentBreadCrumbBranch = BranchQuery::create()->filterById($branchId)->findOne();
         $this->branchBreadCrumbList = BranchQuery::create()->filterById($branchId, Criteria::NOT_EQUAL)->filterByRepositoryId($this->currentBreadCrumbBranch->getRepositoryId())->orderByName()->find();
     }
     $repositoryId = $request->getParameter('repository');
     if (!$repositoryId) {
         $repositoryId = null != $this->currentBreadCrumbBranch ? $this->currentBreadCrumbBranch->getRepositoryId() : null;
     }
     if (null !== $repositoryId) {
         $this->currentBreadCrumbRepository = RepositoryQuery::create()->filterById($repositoryId)->findOne();
         $this->repositoryBreadCrumbList = RepositoryQuery::create()->filterById($repositoryId, Criteria::NOT_EQUAL)->orderByName()->find();
     }
 }
 /**
  * @throws Exception
  * @param $request
  * @return void
  */
 public function execute($request)
 {
     $id = $request->getParameter('id');
     // get the propel connection
     $con = Propel::getConnection();
     $con->beginTransaction();
     $name = 'N/A';
     $value = 'N/A';
     try {
         $repository = RepositoryQuery::create()->filterById($id)->findOne($con);
         if ($repository) {
             $name = $repository->getName();
             $value = $repository->getValue();
             $gitDir = $repository->getGitDir();
             $repository->delete($con);
             if (is_dir($gitDir)) {
                 exec('rm -rf ' . escapeshellarg($gitDir));
             }
         }
         $con->commit();
         $this->getUser()->setFlash('notice', sprintf("The project '%s' has been deleted successfully.", $name));
     } catch (Exception $e) {
         $con->rollBack();
         $this->getUser()->setFlash('error', sprintf("Delete failed : ", $e->getMessage()));
     }
     $this->redirect("default/repositoryList");
 }
 public function execute($request)
 {
     $this->form = new RepositoryForm();
     $repositories = RepositoryQuery::create()->find();
     $this->repositories = array();
     foreach ($repositories as &$repository) {
         $branchesCount = BranchQuery::create()->filterByRepositoryId($repository->getId())->filterByIsBlacklisted(0)->count();
         $this->repositories[] = array_merge($repository->toArray(), array('NbBranches' => $branchesCount));
     }
 }
 public function execute($request)
 {
     $repositories = RepositoryQuery::create()->find();
     $this->repositories = array();
     foreach ($repositories as &$repository) {
         $branchesCount = BranchQuery::create()->filterByRepositoryId($repository->getId())->filterByIsBlacklisted(0)->count();
         $this->repositories[] = array_merge($repository->toArray(), array('NbBranches' => $branchesCount));
     }
     $this->statusActions = StatusActionPeer::getStatusActionsForBoard();
     $this->commentBoards = CommentPeer::getCommentsForBoard();
 }
Example #6
0
 /**
  * @param sfWebRequest $request
  * @return void
  */
 public function execute($request)
 {
     file_put_contents(sprintf("%s/api.log", sfConfig::get('sf_log_dir')), sprintf("%s [%s] list projects\n", date('d/m/Y H:i:s'), $_SERVER['REMOTE_ADDR']), FILE_APPEND);
     $repositories = RepositoryQuery::create()->find();
     $result = array();
     foreach ($repositories as $repository) {
         /** @var $repository Repository */
         $result[] = array('id' => $repository->getId(), 'name' => $repository->getName(), 'repository' => $repository->getValue(), 'remote' => $repository->getRemote());
     }
     $this->getResponse()->setStatusCode('200');
     $this->getResponse()->setContentType('application/json');
     return $this->renderText(json_encode($result));
 }
Example #7
0
 /**
  * @param $projectName
  * @param $remote
  * @return int
  */
 public function getProjectStatus($projectName, $remote)
 {
     $project1 = RepositoryQuery::create()->filterByName($projectName)->findOne();
     $project2 = RepositoryQuery::create()->filterByRemote($remote)->findOne();
     if ($project1 === null && $project2 === null) {
         return -1;
     } else {
         if ($project1 !== $project2) {
             return 0;
         } else {
             return $project1->getId();
         }
     }
 }
Example #8
0
 /**
  * @param sfWebRequest $request
  * @return void
  */
 public function execute($request)
 {
     $projectId = $request->getParameter('project_id');
     $baseBranchName = $request->getParameter('base_branch');
     $branchName = $request->getParameter('branch');
     $commit = (string) $request->getParameter('commit');
     // Last commit
     $result = array();
     file_put_contents(sprintf("%s/api.log", sfConfig::get('sf_log_dir')), sprintf("%s [%s] set review = projectId : %s - baseBranchName : %s - branchName : %s - commit : %s\n", date('d/m/Y H:i:s'), $_SERVER['REMOTE_ADDR'], $projectId, $baseBranchName, $branchName, $commit), FILE_APPEND);
     $repository = RepositoryQuery::create()->filterById($projectId)->findOne();
     if ($repository) {
         $branch = BranchQuery::create()->filterByRepositoryId($repository->getId())->filterByName($branchName)->findOne();
         if (!$branch) {
             $branch = new Branch();
             $branch->setName($branchName)->setRepositoryId($repository->getId())->setBaseBranchName($baseBranchName)->save();
         }
         if ($branch->getBaseBranchName() != $baseBranchName) {
             $branch->setBaseBranchName($baseBranchName)->save();
         }
         if (($nbFiles = BranchPeer::synchronize($this->gitCommand, $repository, $branch)) != 0) {
             $result['message'] = sprintf("Your branch '%s' has too many files : %s (max : %s)", $branch->__toString(), $nbFiles, sfConfig::get('app_max_number_of_files_to_review', 4096));
             $this->getResponse()->setStatusCode('500');
         } elseif (!$branch->isDeleted()) {
             if (strlen($commit) === 40) {
                 if (!$this->gitCommand->commitIsInHistory($repository->getGitDir(), $branch->getCommitStatusChanged(), $commit)) {
                     $result['message'] = sprintf("Review has been %sengaged [old status : %s]", $branch->getReviewRequest() ? 're' : '', BranchPeer::getLabelStatus($branch->getStatus()));
                     $branch->setReviewRequest(1)->setStatus(BranchPeer::A_TRAITER)->setIsBlacklisted(0)->save();
                     $this->getResponse()->setStatusCode('201');
                     $this->dispatcher->notify(new sfEvent($this, 'notification.review-request', array('project-id' => $branch->getRepositoryId(), 'object' => $branch)));
                 } else {
                     $result['message'] = sprintf("Commit already used : '%s'", $commit);
                     $this->getResponse()->setStatusCode('200');
                 }
             } else {
                 $result['message'] = sprintf("No valid commit '%s'", $commit);
                 $this->getResponse()->setStatusCode('422');
             }
         } else {
             $result['message'] = sprintf("Unknown branch '%s' in project '%s'", $branchName, $repository->getName());
             $this->getResponse()->setStatusCode('404');
         }
     } else {
         $result['message'] = sprintf("No valid project '%s'", $projectId);
         $this->getResponse()->setStatusCode('400');
     }
     $this->getResponse()->setContentType('application/json');
     return $this->renderText(json_encode($result));
 }
Example #9
0
 /**
  * @param sfWebRequest $request
  * @return void
  */
 public function execute($request)
 {
     $projectId = $request->getParameter('project_id');
     $result = array();
     file_put_contents(sprintf("%s/api.log", sfConfig::get('sf_log_dir')), sprintf("%s [%s] get project = projectId : %s\n", date('d/m/Y H:i:s'), $_SERVER['REMOTE_ADDR'], $projectId), FILE_APPEND);
     $repository = RepositoryQuery::create()->filterById($projectId)->findOne();
     if ($repository) {
         $result = $repository->toArray();
         $this->getResponse()->setStatusCode('200');
     } else {
         $result['message'] = sprintf("No valid project '%s'", $projectId);
         $this->getResponse()->setStatusCode('404');
     }
     $this->getResponse()->setContentType('application/json');
     return $this->renderText(json_encode($result));
 }
Example #10
0
 /**
  * @param sfWebRequest $request
  * @return void
  */
 public function execute($request)
 {
     $projectId = $request->getParameter('project_id');
     $result = array();
     file_put_contents(sprintf("%s/api.log", sfConfig::get('sf_log_dir')), sprintf("%s [%s] clean project = projectId : %s\n", date('d/m/Y H:i:s'), $_SERVER['REMOTE_ADDR'], $projectId), FILE_APPEND);
     $repository = RepositoryQuery::create()->filterById($projectId)->findOne();
     if ($repository) {
         $branches = BranchQuery::create()->filterByRepositoryId($repository->getId())->find();
         if ($branches) {
             foreach ($branches as $branch) {
                 BranchPeer::synchronize($this->gitCommand, $repository, $branch, true);
             }
         }
         $this->getResponse()->setStatusCode('200');
     } else {
         $result['message'] = sprintf("No valid project '%s'", $projectId);
         $this->getResponse()->setStatusCode('400');
     }
     $this->getResponse()->setContentType('application/json');
     return $this->renderText(json_encode($result));
 }
Example #11
0
 /**
  * @param sfWebRequest $request
  * @return void
  */
 public function execute($request)
 {
     $this->branch = null;
     if ($request->hasParameter('name') && $request->hasParameter('repository')) {
         $repository = RepositoryQuery::create()->filterByName($request->getParameter('repository'))->findOne();
         $this->forward404Unless($repository, "Repository not found");
         $this->branch = BranchQuery::create()->filterByName($request->getParameter('name'))->filterByRepository($repository)->findOne();
         // Dirty hack to make the breadcrumb work /!\
         if ($this->branch) {
             $this->redirect('default/fileList?branch=' . $this->branch->getId());
         }
     } elseif ($request->hasParameter('branch')) {
         $this->branch = BranchPeer::retrieveByPK($request->getParameter('branch'));
     }
     $this->forward404Unless($this->branch, "Branch not found");
     $this->getResponse()->setTitle($this->branch->getName());
     $this->repository = RepositoryPeer::retrieveByPK($this->branch->getRepositoryId());
     $this->forward404Unless($this->repository, "Repository not found");
     $files = FileQuery::create()->filterByBranchId($this->branch->getId())->find();
     $this->files = array();
     foreach ($files as $file) {
         $fileCommentsCount = CommentQuery::create()->filterByFileId($file->getId())->filterByType(CommentPeer::TYPE_FILE)->count();
         $fileCommentsCountNotChecked = CommentQuery::create()->filterByFileId($file->getId())->filterByType(CommentPeer::TYPE_FILE)->filterByCheckUserId(null)->count();
         $lineCommentsCount = CommentQuery::create()->filterByFileId($file->getId())->filterByCommit($file->getLastChangeCommit())->filterByType(CommentPeer::TYPE_LINE)->count();
         $lineCommentsCountNotChecked = CommentQuery::create()->filterByFileId($file->getId())->filterByCommit($file->getLastChangeCommit())->filterByType(CommentPeer::TYPE_LINE)->filterByCheckUserId(null)->count();
         $lastCommentId = 0;
         if ($fileCommentsCount || $lineCommentsCount) {
             $lastComment = CommentQuery::create()->filterByFileId($file->getId())->filterByCommit($file->getLastChangeCommit())->_or()->filterByType(CommentPeer::TYPE_FILE)->orderById(Criteria::DESC)->findOne();
             if ($lastComment) {
                 $lastCommentId = $lastComment->getId();
             }
         }
         $this->files[] = array_merge($file->toArray(), array('NbFileComments' => $fileCommentsCount + $lineCommentsCount, 'NbFileCommentsNotChecked' => $fileCommentsCountNotChecked + $lineCommentsCountNotChecked, 'LastCommentId' => $lastCommentId));
     }
     usort($this->files, array('self', 'sortPath'));
     $this->statusActions = StatusActionPeer::getStatusActionsForBoard(null, $this->repository->getId(), $this->branch->getId());
     $this->commentBoards = CommentPeer::getCommentsForBoard(null, $this->repository->getId(), $this->branch->getId());
 }
Example #12
0
 /**
  * @param sfWebRequest $request
  * @return void
  */
 public function execute($request)
 {
     $projectId = $request->getParameter('project_id');
     $branchName = $request->getParameter('branch');
     $result = array();
     file_put_contents(sprintf("%s/api.log", sfConfig::get('sf_log_dir')), sprintf("%s [%s] delete review = projectId : %s - branchName : %s\n", date('d/m/Y H:i:s'), $_SERVER['REMOTE_ADDR'], $projectId, $branchName), FILE_APPEND);
     $repository = RepositoryQuery::create()->filterById($projectId)->findOne();
     if ($repository) {
         $branch = BranchQuery::create()->filterByRepositoryId($repository->getId())->filterByName($branchName)->findOne();
         if ($branch) {
             $branch->delete();
             $result['message'] = sprintf("Review has been deleted");
             $this->getResponse()->setStatusCode('200');
         } else {
             $result['message'] = sprintf("Unknown branch '%s' in project '%s'", $branchName, $repository->getName());
             $this->getResponse()->setStatusCode('404');
         }
     } else {
         $result['message'] = sprintf("No valid project '%s'", $projectId);
         $this->getResponse()->setStatusCode('400');
     }
     $this->getResponse()->setContentType('application/json');
     return $this->renderText(json_encode($result));
 }
Example #13
0
 /**
  * Update cached package info for repositories.
  */
 public static function updateRepositories()
 {
     foreach (RepositoryQuery::create()->find() as $repository) {
         try {
             self::getCachedFile($repository->getUrl(), true);
             self::log($repository->getUrl() . ' updated!', Curry_Backend::MSG_SUCCESS);
         } catch (Exception $e) {
             self::log($repository->getUrl() . ' update failed! ' . $e->getMessage(), Curry_Backend::MSG_ERROR);
         }
     }
 }
Example #14
0
 /**
  * Get the associated Repository object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     Repository The associated Repository object.
  * @throws     PropelException
  */
 public function getRepository(PropelPDO $con = null)
 {
     if ($this->aRepository === null && $this->repository_id !== null) {
         $this->aRepository = RepositoryQuery::create()->findPk($this->repository_id, $con);
         /* The following can be used additionally to
         			guarantee the related object contains a reference
         			to this object.  This level of coupling may, however, be
         			undesirable since it could result in an only partially populated collection
         			in the referenced object.
         			$this->aRepository->addBranchs($this);
         		 */
     }
     return $this->aRepository;
 }
Example #15
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      PropelPDO $con
  * @return     void
  * @throws     PropelException
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(RepositoryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = RepositoryQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         // symfony_behaviors behavior
         foreach (sfMixer::getCallables('BaseRepository:delete:pre') as $callable) {
             if (call_user_func($callable, $this, $con)) {
                 $con->commit();
                 return;
             }
         }
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             // symfony_behaviors behavior
             foreach (sfMixer::getCallables('BaseRepository:delete:post') as $callable) {
                 call_user_func($callable, $this, $con);
             }
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }