/** * {@inheritDoc} */ public function import(array $providerData, Closure $callback = null) { if (null === $this->provider) { throw new RuntimeException('No provider set'); } if (null === $this->user) { throw new RuntimeException('No user set'); } $logger = $this->logger; $logger->info('importing project', ['full_name' => $providerData['full_name']]); $project = new Project(); $project->setFullName($providerData['full_name']); $project->addUser($this->getUser()); $project->setProviderData($providerData); if (null === $callback) { $callback = function () { }; } $announce = function ($step) use($callback, $logger) { $logger->debug('running import step', $step); $callback($step); }; foreach ($this->getSteps() as $step) { $announce($step); if (!method_exists($this, $step['callback'])) { $logger->error('could not run step: method does not exist', $step); throw new RuntimeException(sprintf('Step method does not exist (step id: %s, method: %s', $step['id'], $step['callback'])); } $ret = call_user_func([$this, $step['callback']], $project); if ($ret === false && $step['abort_on_error']) { $logger->error('aborting import on step error', $step); return false; } } # set default build policy $settings = new ProjectSettings(); $settings->setProject($project); $settings->setPolicy(ProjectSettings::POLICY_ALL); $em = $this->doctrine->getManager(); $em->persist($project); $em->flush(); $em->persist($settings); $em->flush(); return $project; }