Browse Source

Anomalie #58: 500 sur une url pas préparé

bastien 13 years ago
parent
commit
86e6174f90
1 changed files with 73 additions and 69 deletions
  1. 73 69
      src/Muzich/CoreBundle/Controller/CoreController.php

+ 73 - 69
src/Muzich/CoreBundle/Controller/CoreController.php View File

@@ -132,6 +132,11 @@ class CoreController extends Controller
132 132
    */
133 133
   public function elementAddAction($group_slug)
134 134
   {    
135
+    if ($this->getRequest()->getMethod() != 'POST')
136
+    {
137
+      throw $this->createNotFoundException('Cette ressource n\'est pas accessible');
138
+    }
139
+    
135 140
     $user = $this->getUser();
136 141
     $em = $this->getDoctrine()->getEntityManager();
137 142
     
@@ -160,82 +165,81 @@ class CoreController extends Controller
160 165
       )
161 166
     );
162 167
     
163
-    if ($this->getRequest()->getMethod() == 'POST')
168
+    
169
+    $form->bindRequest($this->getRequest());
170
+    if ($form->isValid())
164 171
     {
165
-      $form->bindRequest($this->getRequest());
166
-      if ($form->isValid())
172
+
173
+      /**
174
+       * Bug lors des tests: L'user n'est pas 'lié' a celui en base par doctrine.
175
+       * Docrine le voit si on faire une requete directe.
176
+       */
177
+      if ($this->container->getParameter('env') == 'test')
178
+      {
179
+        $user = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneById(
180
+          $this->container->get('security.context')->getToken()->getUser()->getId(),
181
+          array()
182
+        )->getSingleResult();
183
+      }
184
+
185
+      // On utilise le gestionnaire d'élément
186
+      $factory = new ElementManager($element, $em, $this->container);
187
+      $factory->proceedFill($user);
188
+
189
+      // Si on a précisé un groupe dans lequel mettre l'element
190
+      if ($group)
167 191
       {
168
-        
169
-        /**
170
-         * Bug lors des tests: L'user n'est pas 'lié' a celui en base par doctrine.
171
-         * Docrine le voit si on faire une requete directe.
172
-         */
173
-        if ($this->container->getParameter('env') == 'test')
174
-        {
175
-          $user = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneById(
176
-            $this->container->get('security.context')->getToken()->getUser()->getId(),
177
-            array()
178
-          )->getSingleResult();
179
-        }
180
-        
181
-        // On utilise le gestionnaire d'élément
182
-        $factory = new ElementManager($element, $em, $this->container);
183
-        $factory->proceedFill($user);
184
-        
185
-        // Si on a précisé un groupe dans lequel mettre l'element
186
-        if ($group)
187
-        {
188
-          $element->setGroup($group);
189
-          $redirect_url = $this->generateUrl('show_group', array('slug' => $group_slug));
190
-        }
191
-        else
192
-        {
193
-          $redirect_url = $this->generateUrl('home');
194
-        }
195
-        
196
-        $em->persist($element);
197
-        $em->flush();
198
-        
199
-        if ($this->getRequest()->isXmlHttpRequest())
200
-        {
201
-          
202
-        }
203
-        else
204
-        {
205
-          return $this->redirect($redirect_url);
206
-        }
207
-        
192
+        $element->setGroup($group);
193
+        $redirect_url = $this->generateUrl('show_group', array('slug' => $group_slug));
208 194
       }
209 195
       else
210 196
       {
211
-        if ($this->getRequest()->isXmlHttpRequest())
212
-        {
213
-
214
-        }
215
-        else
216
-        {
217
-          
218
-          $search_object = $this->getElementSearcher();
219
-          $search_form = $this->getSearchForm($search_object);
220
-          $add_form = $this->getAddForm();
221
-
222
-          return $this->render('MuzichHomeBundle:Home:index.html.twig', array(
223
-            'tags'             => $this->getTagsArray(),
224
-            'search_tags_id'   => $search_object->getTags(),
225
-            'user'             => $this->getUser(),
226
-            'add_form'         => $add_form->createView(),
227
-            'add_form_name'    => $add_form->getName(),
228
-            'search_form'      => $search_form->createView(),
229
-            'search_form_name' => $search_form->getName(),
230
-            'elements'         => $search_object->getElements($this->getDoctrine(), $this->getUserId()),
231
-            'more_count'       => $this->container->getParameter('search_default_count')*2
232
-          ));
233
-          
234
-        }
235
-        
197
+        $redirect_url = $this->generateUrl('home');
236 198
       }
237
-      
199
+
200
+      $em->persist($element);
201
+      $em->flush();
202
+
203
+      if ($this->getRequest()->isXmlHttpRequest())
204
+      {
205
+
206
+      }
207
+      else
208
+      {
209
+        return $this->redirect($redirect_url);
210
+      }
211
+
238 212
     }
213
+    else
214
+    {
215
+      if ($this->getRequest()->isXmlHttpRequest())
216
+      {
217
+
218
+      }
219
+      else
220
+      {
221
+
222
+        $search_object = $this->getElementSearcher();
223
+        $search_form = $this->getSearchForm($search_object);
224
+        $add_form = $this->getAddForm();
225
+
226
+        return $this->render('MuzichHomeBundle:Home:index.html.twig', array(
227
+          'tags'             => $this->getTagsArray(),
228
+          'search_tags_id'   => $search_object->getTags(),
229
+          'user'             => $this->getUser(),
230
+          'add_form'         => $add_form->createView(),
231
+          'add_form_name'    => $add_form->getName(),
232
+          'search_form'      => $search_form->createView(),
233
+          'search_form_name' => $search_form->getName(),
234
+          'elements'         => $search_object->getElements($this->getDoctrine(), $this->getUserId()),
235
+          'more_count'       => $this->container->getParameter('search_default_count')*2
236
+        ));
237
+
238
+      }
239
+
240
+    }
241
+      
242
+    
239 243
     
240 244
   }
241 245