浏览代码

Anomalie #45: Ajout d'un élément: err 500

bastien 13 年前
父节点
当前提交
2e33a1597f
共有 2 个文件被更改,包括 27 次插入22 次删除
  1. 8 5
      src/Muzich/CoreBundle/Entity/Element.php
  2. 19 17
      src/Muzich/CoreBundle/Validator/TagsValidator.php

+ 8 - 5
src/Muzich/CoreBundle/Entity/Element.php 查看文件

353
    */
353
    */
354
   public function setTagsWithIds(EntityManager $em, $ids)
354
   public function setTagsWithIds(EntityManager $em, $ids)
355
   {
355
   {
356
-    $tags = $em->getRepository('MuzichCoreBundle:Tag')->findByIds($ids)->execute();
357
     $this->tags = null;
356
     $this->tags = null;
358
-    // Pour les nouveaux ids restants
359
-    foreach ($tags as $tag)
360
-    {      
361
-      $this->addTag($tag);
357
+    if (count($ids))
358
+    {
359
+      $tags = $em->getRepository('MuzichCoreBundle:Tag')->findByIds($ids)->execute();
360
+      // Pour les nouveaux ids restants
361
+      foreach ($tags as $tag)
362
+      {      
363
+        $this->addTag($tag);
364
+      }
362
     }
365
     }
363
   }
366
   }
364
   
367
   

+ 19 - 17
src/Muzich/CoreBundle/Validator/TagsValidator.php 查看文件

18
   
18
   
19
   public function isValid($value, Constraint $constraint)
19
   public function isValid($value, Constraint $constraint)
20
   {
20
   {
21
-    if (array_diff($value, array_unique($value)))
21
+    if (count($value))
22
     {
22
     {
23
-      $this->setMessage('Tags saisies incorrects');
24
-      return false;
25
-    }
26
-    
27
-    $count = $this->entityManager
28
-      ->createQuery("SELECT COUNT(t)
29
-        FROM MuzichCoreBundle:Tag t
30
-        WHERE t IN (:tids)")
31
-      ->setParameter('tids', $value)
32
-    ->getSingleScalarResult();
33
-    
34
-    if ($count != count ($value))
35
-    {
36
-      $this->setMessage('Tags saisies incorrects');
37
-      return false;
23
+      if (array_diff($value, array_unique($value)))
24
+      {
25
+        $this->setMessage('Tags saisies incorrects');
26
+        return false;
27
+      }
28
+
29
+      $count = $this->entityManager
30
+        ->createQuery("SELECT COUNT(t)
31
+          FROM MuzichCoreBundle:Tag t
32
+          WHERE t IN (:tids)")
33
+        ->setParameter('tids', $value)
34
+      ->getSingleScalarResult();
35
+
36
+      if ($count != count ($value))
37
+      {
38
+        $this->setMessage('Tags saisies incorrects');
39
+        return false;
40
+      }
38
     }
41
     }
39
-    
40
     return true;
42
     return true;
41
   }
43
   }
42
 }
44
 }