/** * (non-PHPdoc) * @see \MB\DashboardBundle\Model\Connector\ConnectorInterface::fillProject() */ public function fillProject(SourceProjectInterface $project, \stdClass $data, SourceGroupInterface $sourceGroup = null) { $project->setSourceId($data->id); $project->setSourceConnectorIdentifier($this->getName()); if ($sourceGroup) { $project->setSourceGroup($sourceGroup); $sourceGroup->addProject($project); } $project->setSourceTitle($data->path); $project->setSourceUrl($data->web_url); $project->setSourceDescription($data->description); $project->setSourcePath($data->path); return $project; }
/** * Import the given project and include the commits if asked to (can be used to refresh an existing project too) * * @throws \Exception */ public function importProject(SourceProjectInterface $project, $includeCommits = false) { if (!isset($this->connections[$project->getSourceConnectorIdentifier()])) { throw new \Exception('There is no configurer connector for the given identifier : "' . $project->getSourceConnectorIdentifier() . '"'); } else { $connect = $this->connections[$project->getSourceConnectorIdentifier()]; } /* @var $connect \MB\DashboardBundle\Model\Connector\ConnectorInterface */ $rawProject = $connect->importProject($project); // Get the source group, create if doesn't exists, fill/update and store $sourceGroup = $this->sourceGroupRepo->findOneBy(array('sourceId' => $connect->getGroupId($rawProject), 'sourceConnectorIdentifier' => $connect->getName())); if (!$sourceGroup) { $sourceGroup = new SourceGroup(); } $sourceGroup = $connect->fillGroup($sourceGroup, $rawProject); $sourceGroup = $connect->fillGroup($sourceGroup, $rawProject); $this->em->persist($sourceGroup); $project = $this->projectRepo->findOneBy(array('sourceId' => $connect->getProjectId($rawProject), 'sourceConnectorIdentifier' => $connect->getName())); if (!$project) { $project = new Project(); } $project = $connect->fillProject($project, $rawProject, $sourceGroup); $this->em->persist($project); $this->em->flush(); if ($includeCommits) { $commits = $connect->importAllCommits($project); foreach ($commits as $rawCommit) { $commit = $this->commitRepo->findOneBy(array('sourceId' => $connect->getCommitId($rawCommit), 'project' => $project)); if (!$commit) { $commit = new Commit(); } $commit = $connect->fillCommit($commit, $rawCommit, $project); $this->em->persist($commit); } $this->em->flush(); } }