|
@@ -12,6 +12,8 @@
|
|
|
|
|
|
namespace Packagist\WebBundle\Controller;
|
|
|
|
|
|
+use Packagist\WebBundle\Form\ConfirmForm;
|
|
|
+use Packagist\WebBundle\Form\ConfirmFormType;
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
|
use Packagist\WebBundle\Entity\Package;
|
|
|
use Packagist\WebBundle\Entity\Version;
|
|
@@ -56,27 +58,52 @@ class WebController extends Controller
|
|
|
$form = $this->get('form.factory')->create(new PackageType, $package);
|
|
|
|
|
|
$request = $this->get('request');
|
|
|
+ $provider = $this->get('packagist.repository_provider');
|
|
|
if ($request->getMethod() == 'POST') {
|
|
|
$form->bindRequest($request);
|
|
|
if ($form->isValid()) {
|
|
|
- try {
|
|
|
- $user = $this->getUser();
|
|
|
- $package->addMaintainers($user);
|
|
|
- $em = $this->get('doctrine')->getEntityManager();
|
|
|
- $em->persist($package);
|
|
|
- $em->flush();
|
|
|
+ $user = $this->getUser();
|
|
|
+ $package->addMaintainers($user);
|
|
|
+ $repository = $provider->getRepository($package->getRepository());
|
|
|
|
|
|
- $this->get('session')->setFlash('success', $package->getName().' has been added to the package list, the repository will be parsed for releases in a bit.');
|
|
|
- return new RedirectResponse($this->generateUrl('home'));
|
|
|
- } catch (\PDOException $e) {
|
|
|
- $this->get('session')->setFlash('error', $package->getName().' could not be saved in our database, most likely the name is already in use.');
|
|
|
- }
|
|
|
+ $composerFile = $repository->getComposerInformation('master');
|
|
|
+ $package->setName($composerFile['name']);
|
|
|
+
|
|
|
+ $this->get('session')->set('package', $package);
|
|
|
+ return new RedirectResponse($this->generateUrl('confirm'));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return array('form' => $form->createView(), 'page' => 'submit');
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @Template()
|
|
|
+ * @Route("/submit/confirm", name="confirm")
|
|
|
+ */
|
|
|
+ public function confirmPackageAction()
|
|
|
+ {
|
|
|
+ if(($package = $this->get('session')->get('package')) instanceof Package) {
|
|
|
+ $confirmForm = new ConfirmForm;
|
|
|
+ $form = $this->createForm(new ConfirmFormType, $confirmForm);
|
|
|
+ $request = $this->getRequest();
|
|
|
+ if($request->getMethod() == 'POST') {
|
|
|
+ $form->bindRequest($request);
|
|
|
+ if($form->isValid()){
|
|
|
+ try {
|
|
|
+ $this->get('session')->remove('package');
|
|
|
+ $this->getDoctrine()->getEntityManager()->persist($package);
|
|
|
+ $this->get('session')->setFlash('success', $package->getName().' has been added to the package list, the repository will be parsed for releases in a bit.');
|
|
|
+ return new RedirectResponse($this->generateUrl('home'));
|
|
|
+ } catch (\PDOException $e) {
|
|
|
+ $this->get('session')->setFlash('error', $package->getName().' could not be saved in our database, most likely the name is already in use.');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return array('form' => $form->createView(), 'page' => 'confirm');
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @Template()
|
|
|
* @Route("/about", name="about")
|