]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #5066. Empty subtypes are handled the same way for both 'subtype' and 'subtypes'
authorBrett Profitt <brett.profitt@gmail.com>
Wed, 27 Feb 2013 15:36:47 +0000 (10:36 -0500)
committerBrett Profitt <brett.profitt@gmail.com>
Wed, 27 Feb 2013 15:36:47 +0000 (10:36 -0500)
engine/lib/entities.php
engine/tests/api/entity_getter_functions.php

index 25c927ac6b1865bf39f8d8bd75c142a9728c99fa..156eec040f4a8bb335d5866e5ba60a1083eea948 100644 (file)
@@ -1219,14 +1219,24 @@ function elgg_get_entity_type_subtype_where_sql($table, $types, $subtypes, $pair
                        $subtype_ids = array();
                        if ($subtypes) {
                                foreach ($subtypes as $subtype) {
-                                       // check that the subtype is valid (with ELGG_ENTITIES_NO_VALUE being a valid subtype)
-                                       // @todo simplify this logic
-                                       if (ELGG_ENTITIES_NO_VALUE === $subtype || $subtype_id = get_subtype_id($type, $subtype)) {
-                                               $subtype_ids[] = (ELGG_ENTITIES_NO_VALUE === $subtype) ? ELGG_ENTITIES_NO_VALUE : $subtype_id;
-                                       } else {
-                                               $valid_subtypes_count--;
-                                               elgg_log("Type-subtype '$type:$subtype' does not exist!", 'NOTICE');
+                                       // check that the subtype is valid
+                                       if (!$subtype && ELGG_ENTITIES_NO_VALUE === $subtype) {
+                                               // subtype value is 0
+                                               $subtype_ids[] = ELGG_ENTITIES_NO_VALUE;
+                                       } elseif (!$subtype) {
+                                               // subtype is ignored.
+                                               // this handles ELGG_ENTITIES_ANY_VALUE, '', and anything falsy that isn't 0
                                                continue;
+                                       } else {
+                                               $subtype_id = get_subtype_id($type, $subtype);
+                                               
+                                               if ($subtype_id) {
+                                                       $subtype_ids[] = $subtype_id;
+                                               } else {
+                                                       $valid_subtypes_count--;
+                                                       elgg_log("Type-subtype '$type:$subtype' does not exist!", 'NOTICE');
+                                                       continue;
+                                               }
                                        }
                                }
 
index 6f7a6145e6021a40bf1ee5ee168553110776a233..52470e19d7abfcc76c759cf36ab1e5fe43642ce8 100644 (file)
@@ -2817,4 +2817,38 @@ class ElggCoreEntityGetterFunctionsTest extends ElggCoreUnitTest {
                $entities = elgg_get_entities($options);
                $this->assertFalse($entities);
        }
+
+       public function testEGEEmptySubtypePlurality() {
+               $options = array(
+                       'type' => 'user',
+                       'subtypes' => ''
+               );
+
+               $entities = elgg_get_entities($options);
+               $this->assertTrue(is_array($entities));
+
+               $options = array(
+                       'type' => 'user',
+                       'subtype' => ''
+               );
+
+               $entities = elgg_get_entities($options);
+               $this->assertTrue(is_array($entities));
+
+               $options = array(
+                       'type' => 'user',
+                       'subtype' => array('')
+               );
+
+               $entities = elgg_get_entities($options);
+               $this->assertTrue(is_array($entities));
+
+               $options = array(
+                       'type' => 'user',
+                       'subtypes' => array('')
+               );
+
+               $entities = elgg_get_entities($options);
+               $this->assertTrue(is_array($entities));
+       }
 }