/**
  * @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();
     }
 }
 /**
  * @param int $id
  * @param int $status
  * @param PropelPDO $con
  * @return string
  */
 public function changeBranchStatus($id, $status, PropelPDO $con)
 {
     $branch = BranchQuery::create()->filterById($id)->findOne();
     $this->forward404Unless($branch, 'Branch `%s` Not Found', $id);
     $oldStatus = $branch->getStatus();
     $branch->changeStatus($status, $this->getUser()->getId(), $con);
     $this->dispatcher->notify(new sfEvent($this, 'notification.status', array('project-id' => $branch->getRepositoryId(), 'type' => 'branch', 'object' => $branch, 'old' => $oldStatus)));
 }
 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));
     }
 }
 /**
  * @param sfWebRequest $request
  * @return void
  */
 public function execute($request)
 {
     $repository = RepositoryPeer::retrieveByPK($request->getParameter('repository'));
     $this->forward404Unless($repository, "Repository Not Found");
     $branches = BranchQuery::create()->filterByRepositoryId($repository->getId())->filterByIsBlacklisted(0)->find();
     foreach ($branches as $branch) {
         BranchPeer::synchronize($this->gitCommand, $repository, $branch, true);
     }
     $this->redirect('default/branchList?repository=' . $repository->getId());
 }
 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
 /**
  * @static
  * @param int $userId
  * @param int $repositoryId
  * @param int $branchId
  * @param int $oldStatus
  * @param int $newStatus
  * @param string $message
  * @return int
  */
 public static function saveAction($userId, $repositoryId, $branchId, $oldStatus, $newStatus, $message = 'status was changed from <strong>%s</strong> to <strong>%s</strong>')
 {
     if ($oldStatus === $newStatus) {
         return 0;
     }
     $branch = BranchQuery::create()->filterById($branchId)->findOne();
     if (!$branch) {
         return false;
     }
     $statusAction = new StatusAction();
     return $statusAction->setUserId($userId)->setRepositoryId($repositoryId)->setBranchId($branchId)->setOldStatus($oldStatus)->setNewStatus($newStatus)->setMessage(sprintf($message, BranchPeer::getLabelStatus($oldStatus), BranchPeer::getLabelStatus($newStatus)))->save();
 }
Example #7
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 #8
0
 /**
  * @static
  * @param GitCommand $gitCommand
  * @param Repository $repository
  * @param Branch $branch
  * @param bool $deleteOnly
  * @return void
  */
 public static function synchronize(GitCommand $gitCommand, Repository $repository, Branch $branch, $deleteOnly = false)
 {
     $branchGit = $gitCommand->getNoMergedBranchInfos($repository->getGitDir(), $branch->getBaseBranchName(), $branch->getName());
     $branchModel = BranchQuery::create()->filterByRepositoryId($repository->getId())->filterByName($branch->getName())->findOne();
     if ($branchModel) {
         if (is_null($branchGit)) {
             $branchModel->delete();
         } elseif (!$branchModel->getIsBlacklisted() && !$deleteOnly) {
             $lastSynchronizationCommit = $branchModel->getLastCommit();
             $branchModel->setCommitReference($branchGit['commit_reference']);
             $branchModel->setLastCommit($branchGit['last_commit']);
             $branchModel->setLastCommitDesc($branchGit['last_commit_desc']);
             $branchModel->save();
             return FilePeer::synchronize($gitCommand, $branchModel, $lastSynchronizationCommit);
         }
     }
     return 0;
 }
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] list reviews = 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) {
             $result = $branches->toArray();
         }
         $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 #10
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 #11
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this sfGuardUser is new, it will return
  * an empty collection; or if this sfGuardUser has previously
  * been saved, it will retrieve related Branchs from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in sfGuardUser.
  *
  * @param      Criteria $criteria optional Criteria object to narrow the query
  * @param      PropelPDO $con optional connection object
  * @param      string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
  * @return     PropelCollection|array Branch[] List of Branch objects
  */
 public function getBranchsJoinRepository($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $query = BranchQuery::create(null, $criteria);
     $query->joinWith('Repository', $join_behavior);
     return $this->getBranchs($query, $con);
 }
Example #12
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(BranchPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = BranchQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         // symfony_behaviors behavior
         foreach (sfMixer::getCallables('BaseBranch: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('BaseBranch: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;
     }
 }
Example #13
0
 /**
  * Returns a new BranchQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return    BranchQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof BranchQuery) {
         return $criteria;
     }
     $query = new BranchQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Example #14
0
 /**
  * Get the associated Branch object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     Branch The associated Branch object.
  * @throws     PropelException
  */
 public function getBranch(PropelPDO $con = null)
 {
     if ($this->aBranch === null && $this->branch_id !== null) {
         $this->aBranch = BranchQuery::create()->findPk($this->branch_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->aBranch->addFiles($this);
         		 */
     }
     return $this->aBranch;
 }