|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace Packagist\WebBundle\Controller;
|
|
|
|
|
|
+use Packagist\WebBundle\Form\Type\AbandonedType;
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
|
@@ -68,5 +69,90 @@ class PackageController extends Controller
|
|
|
"package" => $package, "form" => $form->createView()
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param Request $request
|
|
|
+ * @param string $name
|
|
|
+ * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
|
|
|
+ *
|
|
|
+ * @Route(
|
|
|
+ * "/packages/{name}/abandon",
|
|
|
+ * name="abandon_package",
|
|
|
+ * requirements={"name"="[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"}
|
|
|
+ * )
|
|
|
+ * @Template()
|
|
|
+ */
|
|
|
+ public function abandonAction(Request $request, $name)
|
|
|
+ {
|
|
|
+ /** @var $packageRepo \Packagist\WebBundle\Entity\PackageRepository */
|
|
|
+ $packageRepo = $this->getDoctrine()->getRepository('PackagistWebBundle:Package');
|
|
|
+
|
|
|
+ /** @var $package Package */
|
|
|
+ $package = $packageRepo->findOneByName($name);
|
|
|
+
|
|
|
+ if (!$package) {
|
|
|
+ throw $this->createNotFoundException("The requested package, $name, could not be found.");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$package->getMaintainers()->contains($this->getUser()) && !$this->get('security.context')->isGranted('ROLE_EDIT_PACKAGES')) {
|
|
|
+ throw new AccessDeniedException;
|
|
|
+ }
|
|
|
+
|
|
|
+ $form = $this->createForm(new AbandonedType());
|
|
|
+ $form->handleRequest($request);
|
|
|
+
|
|
|
+ if ($form->isValid()) {
|
|
|
+
|
|
|
+ $package->setAbandoned(true);
|
|
|
+ $package->setReplacementPackage($form->get('replacement')->getData());
|
|
|
+
|
|
|
+ $em = $this->getDoctrine()->getManager();
|
|
|
+ $em->persist($package);
|
|
|
+ $em->flush();
|
|
|
+
|
|
|
+ return $this->redirect($this->generateUrl('view_package', array('name' => $package->getName())));
|
|
|
+ }
|
|
|
+
|
|
|
+ return array(
|
|
|
+ 'package' => $package,
|
|
|
+ 'form' => $form->createView()
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param string $name
|
|
|
+ * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
|
|
|
+ *
|
|
|
+ * @Route(
|
|
|
+ * "/packages/{name}/un-abandon",
|
|
|
+ * name="unabandon_package",
|
|
|
+ * requirements={"name"="[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"}
|
|
|
+ * )
|
|
|
+ */
|
|
|
+ public function unabandonAction($name)
|
|
|
+ {
|
|
|
+ /** @var $packageRepo \Packagist\WebBundle\Entity\PackageRepository */
|
|
|
+ $packageRepo = $this->getDoctrine()->getRepository('PackagistWebBundle:Package');
|
|
|
+
|
|
|
+ /** @var $package Package */
|
|
|
+ $package = $packageRepo->findOneByName($name);
|
|
|
+
|
|
|
+ if (!$package) {
|
|
|
+ throw $this->createNotFoundException("The requested package, $name, could not be found.");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$package->getMaintainers()->contains($this->getUser()) && !$this->get('security.context')->isGranted('ROLE_EDIT_PACKAGES')) {
|
|
|
+ throw new AccessDeniedException;
|
|
|
+ }
|
|
|
+
|
|
|
+ $package->setAbandoned(false);
|
|
|
+ $package->setReplacementPackage(null);
|
|
|
+
|
|
|
+ $em = $this->getDoctrine()->getManager();
|
|
|
+ $em->persist($package);
|
|
|
+ $em->flush();
|
|
|
+
|
|
|
+ return $this->redirect($this->generateUrl('view_package', array('name' => $package->getName())));
|
|
|
+ }
|
|
|
}
|
|
|
|