Browse Source

Avoid querying the whole db in case packages.json is missing on packagist.org

Jordi Boggiano 11 years ago
parent
commit
f34136cb6d
1 changed files with 7 additions and 1 deletions
  1. 7 1
      src/Packagist/WebBundle/Controller/ApiController.php

+ 7 - 1
src/Packagist/WebBundle/Controller/ApiController.php

@@ -38,7 +38,7 @@ class ApiController extends Controller
      * @Template()
      * @Route("/packages.json", name="packages", defaults={"_format" = "json"})
      */
-    public function packagesAction()
+    public function packagesAction(Request $req)
     {
         // fallback if any of the dumped files exist
         $rootJson = $this->container->getParameter('kernel.root_dir').'/../web/packages_root.json';
@@ -50,6 +50,12 @@ class ApiController extends Controller
             return new Response(file_get_contents($rootJson));
         }
 
+        if ($req->getHost() === 'packagist.org') {
+            $this->get('logger')->alert('packages.json is missing and the fallback controller is being hit');
+
+            return new Response('Horrible misconfiguration or the dumper script messed up', 404);
+        }
+
         $em = $this->get('doctrine')->getManager();
 
         gc_enable();