Skip to content

Commit

Permalink
Merge remote-tracking branch 'timmillwood/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Aug 13, 2015
2 parents 69a367f + c6e4f78 commit 611338a
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/Packagist/WebBundle/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,42 @@ public function packagesAction(Request $req)
return new Response('Horrible misconfiguration or the dumper script messed up, you need to use app/console packagist:dump', 404);
}

/**
* @Route("/api/create-package", name="generic_create", defaults={"_format" = "json"})
* @Method({"POST"})
*/
public function createPackageAction(Request $request)
{
$payload = json_decode($request->getContent(), true);
if (!$payload) {
return new JsonResponse(array('status' => 'error', 'message' => 'Missing payload parameter'), 406);
}
$url = $payload['repository']['url'];
$package = new Package;
$package->setEntityRepository($this->getDoctrine()->getRepository('PackagistWebBundle:Package'));
$package->setRouter($this->get('router'));
$user = $this->findUser($request);
$package->addMaintainer($user);
$package->repository = $url;
$errors = $this->get('validator')->validate($package)
if (count($errors) > 0) {
foreach ($errors as $error) {
$errorArray[$error->getPropertyPath()] = $error->getMessage();
}
return new JsonResponse(array('status' => 'error', 'message' => $errorArray), 406);
}
try {
$em = $this->getDoctrine()->getManager();
$em->persist($package);
$em->flush();
} catch (\Exception $e) {
$this->get('logger')->crit($e->getMessage(), array('exception', $e));
return new JsonResponse(array('status' => 'error', 'message' => 'Error saving package'), 500);
}

return new JsonResponse(array('status' => 'success'), 202);
}

/**
* @Route("/api/update-package", name="generic_postreceive", defaults={"_format" = "json"})
* @Route("/api/github", name="github_postreceive", defaults={"_format" = "json"})
Expand Down

0 comments on commit 611338a

Please sign in to comment.