Browse Source

Redirect to search if package name is not found, fixes #51

Jordi Boggiano 13 years ago
parent
commit
7efda2b19b
1 changed files with 7 additions and 2 deletions
  1. 7 2
      src/Packagist/WebBundle/Controller/WebController.php

+ 7 - 2
src/Packagist/WebBundle/Controller/WebController.php

@@ -86,6 +86,11 @@ class WebController extends Controller
     {
         $form = $this->createSearchForm();
 
+        // transform q=search shortcut
+        if ($req->query->has('q')) {
+            $req->query->set('search_query', array('query' => $req->query->get('q')));
+        }
+
         if ($req->query->has('search_query')) {
             $form->bindRequest($req);
             if ($form->isValid()) {
@@ -199,7 +204,7 @@ class WebController extends Controller
             ->getResult();
 
         if (!$packages) {
-            throw new NotFoundHttpException('The requested vendor, '.$vendor.', was not found.');
+            return $this->redirect($this->generateUrl('search', array('q' => $vendor, 'reason' => 'vendor_not_found')));
         }
 
         return array('packages' => $packages, 'vendor' => $vendor, 'paginate' => false, 'searchForm' => $this->createSearchForm()->createView());
@@ -216,7 +221,7 @@ class WebController extends Controller
             ->findOneByName($name);
 
         if (!$package) {
-            throw new NotFoundHttpException('The requested package, '.$name.', was not found.');
+            return $this->redirect($this->generateUrl('search', array('q' => $name, 'reason' => 'package_not_found')));
         }
 
         $data = array('package' => $package);