Пример #1
0
 /**
  * {@inheritDoc}
  */
 public function run(InputInterface $input = null, OutputInterface $output = null)
 {
     if (null === $output) {
         $styles = Factory::createAdditionalStyles();
         $formatter = new OutputFormatter(null, $styles);
         $output = new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, null, $formatter);
     }
     return parent::run($input, $output);
 }
Пример #2
0
 /**
  * Runs the current application.
  *
  * @param  \Symfony\Component\Console\Input\InputInterface    $input
  * @param  \Symfony\Component\Console\Output\OutputInterface  $output
  * @return int
  */
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     $styles = Factory::createAdditionalStyles();
     foreach ($styles as $name => $style) {
         $output->getFormatter()->setStyle($name, $style);
     }
     $this->consoleIo = new ConsoleIO($input, $output, $this->getHelperSet());
     return parent::doRun($input, $output);
 }
Пример #3
0
 /**
  * {@inheritDoc}
  */
 public function run(InputInterface $input = null, OutputInterface $output = null)
 {
     // Add output formatter style used by embedded composer.
     if (null === $output) {
         $styles = \Composer\Factory::createAdditionalStyles();
         $formatter = new OutputFormatter(null, $styles);
         $output = new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, null, $formatter);
     }
     return parent::run($input, $output);
 }
Пример #4
0
 /**
  * Perform the package update
  *
  * @param Request $request the current request
  * @param string $url the repository's URL (deducted from the request)
  * @param string $urlRegex the regex used to split the user packages into domain and path
  * @return Response
  */
 protected function receivePost(Request $request, $url, $urlRegex)
 {
     // try to parse the URL first to avoid the DB lookup on malformed requests
     if (!preg_match($urlRegex, $url)) {
         return new Response(json_encode(array('status' => 'error', 'message' => 'Could not parse payload repository URL')), 406);
     }
     // find the user
     $user = $this->findUser($request);
     if (!$user) {
         return new Response(json_encode(array('status' => 'error', 'message' => 'Invalid credentials')), 403);
     }
     // try to find the user package
     $packages = $this->findPackagesByUrl($user, $url, $urlRegex);
     if (!$packages) {
         return new Response(json_encode(array('status' => 'error', 'message' => 'Could not find a package that matches this request (does user maintain the package?)')), 404);
     }
     // don't die if this takes a while
     set_time_limit(3600);
     // put both updating the database and scanning the repository in a transaction
     $em = $this->get('doctrine.orm.entity_manager');
     $updater = $this->get('packagist.package_updater');
     $config = Factory::createConfig();
     $io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE, new HtmlOutputFormatter(Factory::createAdditionalStyles()));
     $io->loadConfiguration($config);
     try {
         foreach ($packages as $package) {
             $em->transactional(function ($em) use($package, $updater, $io, $config) {
                 // prepare dependencies
                 $loader = new ValidatingArrayLoader(new ArrayLoader());
                 // prepare repository
                 $repository = new VcsRepository(array('url' => $package->getRepository()), $io, $config);
                 $repository->setLoader($loader);
                 // perform the actual update (fetch and re-scan the repository's source)
                 $updater->update($io, $config, $package, $repository);
                 // update the package entity
                 $package->setAutoUpdated(true);
                 $em->flush();
             });
         }
     } catch (\Exception $e) {
         if ($e instanceof InvalidRepositoryException) {
             $this->get('packagist.package_manager')->notifyUpdateFailure($package, $e, $io->getOutput());
         }
         return new Response(json_encode(array('status' => 'error', 'message' => '[' . get_class($e) . '] ' . $e->getMessage(), 'details' => '<pre>' . $io->getOutput() . '</pre>')), 400);
     }
     return new JsonResponse(array('status' => 'success'), 202);
 }
Пример #5
0
 /**
  * @Template()
  * @Route("/packages/{name}", name="update_package", requirements={"name"="[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+"}, defaults={"_format" = "json"})
  * @Method({"PUT"})
  */
 public function updatePackageAction(Request $req, $name)
 {
     $doctrine = $this->getDoctrine();
     try {
         /** @var Package $package */
         $package = $doctrine->getRepository('PackagistWebBundle:Package')->getPackageByName($name);
     } catch (NoResultException $e) {
         return new Response(json_encode(array('status' => 'error', 'message' => 'Package not found')), 404);
     }
     $username = $req->request->has('username') ? $req->request->get('username') : $req->query->get('username');
     $apiToken = $req->request->has('apiToken') ? $req->request->get('apiToken') : $req->query->get('apiToken');
     $update = $req->request->get('update', $req->query->get('update'));
     $autoUpdated = $req->request->get('autoUpdated', $req->query->get('autoUpdated'));
     $updateEqualRefs = $req->request->get('updateAll', $req->query->get('updateAll'));
     $user = $this->getUser() ?: $doctrine->getRepository('PackagistWebBundle:User')->findOneBy(array('username' => $username, 'apiToken' => $apiToken));
     if (!$user) {
         return new Response(json_encode(array('status' => 'error', 'message' => 'Invalid credentials')), 403);
     }
     if ($package->getMaintainers()->contains($user) || $this->isGranted('ROLE_UPDATE_PACKAGES')) {
         $req->getSession()->save();
         if (null !== $autoUpdated) {
             $package->setAutoUpdated((bool) $autoUpdated);
             $doctrine->getManager()->flush();
         }
         if ($update) {
             set_time_limit(3600);
             $updater = $this->get('packagist.package_updater');
             $io = new BufferIO('', OutputInterface::VERBOSITY_VERY_VERBOSE, new HtmlOutputFormatter(Factory::createAdditionalStyles()));
             $config = Factory::createConfig();
             $io->loadConfiguration($config);
             $repository = new VcsRepository(array('url' => $package->getRepository()), $io, $config);
             $loader = new ValidatingArrayLoader(new ArrayLoader());
             $repository->setLoader($loader);
             try {
                 $updater->update($io, $config, $package, $repository, $updateEqualRefs ? Updater::UPDATE_EQUAL_REFS : 0);
             } catch (\Exception $e) {
                 return new Response(json_encode(array('status' => 'error', 'message' => '[' . get_class($e) . '] ' . $e->getMessage(), 'details' => '<pre>' . $io->getOutput() . '</pre>')), 400);
             }
         }
         return new Response('{"status": "success"}', 202);
     }
     return new JsonResponse(array('status' => 'error', 'message' => 'Could not find a package that matches this request (does user maintain the package?)'), 404);
 }
 protected function getIO()
 {
     $styles = Factory::createAdditionalStyles();
     $formatter = new OutputFormatter(null, $styles);
     $output = new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, null, $formatter);
     return new ConsoleIO(new ArgvInput(), $output, new HelperSet(array(new FormatterHelper(), new DialogHelper(), new ProgressHelper())));
 }