コード例 #1
0
 /**
  * start/create project for requisite
  *
  * @param $requisite_id
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function startAction($requisite_id)
 {
     $em = $this->getDoctrine()->getManager();
     $requisite = $this->getDoctrine()->getRepository('AppBundle:Requisite')->find($requisite_id);
     $project = $requisite->getProject();
     if ($project) {
         throw new NotFoundHttpException('Requisite already have project');
     }
     $project = new Project();
     $project->setRequisite($requisite);
     $project->setStatus(0);
     $projecter = $this->get('projecter');
     // heroky app create
     $herokuResponse = $projecter->buildHerokuProject(false, $requisite->getUser()->getHerokuApiToken());
     // github create repository
     $loginString = $requisite->getUser()->getGitHubAccountUser() . ":" . $requisite->getUser()->getGitHubAccountPassword();
     $projecter->createGitHubRepository($herokuResponse["name"], $loginString);
     // Create auhtorization token
     $gitHubToken = $projecter->createGitHubToken($loginString);
     $herokuToken = $projecter->createHerokuToken($requisite->getUser()->getHerokuApiToken());
     // create webhooks Auto-Deploy
     $projecter->createGitHubHookAutoDeployForRepository($herokuResponse["name"], $gitHubToken, $loginString);
     // create webhooks HerokuBeta
     $projecter->createGitHubHerokuBetaForRepository($herokuResponse["name"], $gitHubToken, $herokuToken, $loginString);
     // set fields entity
     $project->setHerokuIdentifier($herokuResponse["id"]);
     $project->setHerokuGit($herokuResponse["git_url"]);
     $project->setHerokuHttp($herokuResponse["web_url"]);
     $project->setName($herokuResponse["name"]);
     $project->setGitHubToken($gitHubToken);
     $project->setHerokuToken($herokuToken);
     $project->setGitHubRepositoryName($herokuResponse["name"]);
     // UserProject
     $userProject = new UserProject();
     $userProject->setProject($project);
     $userProject->setUser($this->getUser());
     $em->persist($userProject);
     $em->persist($project);
     $em->flush();
     return $this->redirectToRoute('project_list');
 }