aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/metadata.php2
-rw-r--r--engine/lib/upgrades/2010061501.php4
-rw-r--r--engine/tests/api/entity_getter_functions.php135
3 files changed, 138 insertions, 3 deletions
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php
index d28999a77..74ea6858a 100644
--- a/engine/lib/metadata.php
+++ b/engine/lib/metadata.php
@@ -677,7 +677,7 @@ function elgg_get_entity_metadata_where_sql($e_table, $n_table, $names = NULL, $
&& (!$values && $values !== 0)
&& (!$pairs && $pairs !== 0)
&& (!$owner_guids && $owner_guids !== 0)
- && !isset($order_by_metadata)) {
+ && !$order_by_metadata) {
return '';
}
diff --git a/engine/lib/upgrades/2010061501.php b/engine/lib/upgrades/2010061501.php
index 19d6467ed..2b65cc5c7 100644
--- a/engine/lib/upgrades/2010061501.php
+++ b/engine/lib/upgrades/2010061501.php
@@ -30,9 +30,9 @@ if ($dbversion < 2009100701) {
$qs[] = "ALTER TABLE {$CONFIG->dbprefix}users_entity DISABLE KEYS";
$qs[] = "REPLACE INTO {$CONFIG->dbprefix}users_entity (guid, name, username, password, salt, email, language, code,
- banned, last_action, prev_last_action, last_login, prev_last_login)
+ banned, admin, last_action, prev_last_action, last_login, prev_last_login)
SELECT guid, name, unhex(hex(convert(username using latin1))), password, salt, email, language, code,
- banned, last_action, prev_last_action, last_login, prev_last_login
+ banned, admin, last_action, prev_last_action, last_login, prev_last_login
FROM {$CONFIG->dbprefix}users_entity";
$qs[] = "ALTER TABLE {$CONFIG->dbprefix}users_entity ENABLE KEYS";
diff --git a/engine/tests/api/entity_getter_functions.php b/engine/tests/api/entity_getter_functions.php
index 9fcc6fe01..faa91db34 100644
--- a/engine/tests/api/entity_getter_functions.php
+++ b/engine/tests/api/entity_getter_functions.php
@@ -2041,4 +2041,139 @@ class ElggCoreEntityGetterFunctionsTest extends ElggCoreUnitTest {
}
}
}
+
+ // Make sure metadata doesn't affect getting entities by relationship. See #2274
+ public function testElggApiGettersEntityRelationshipWithMetadata() {
+ $guids = array();
+
+ $obj1 = new ElggObject();
+ $obj1->test_md = 'test';
+ $obj1->save();
+ $guids[] = $obj1->guid;
+
+ $obj2 = new ElggObject();
+ $obj2->test_md = 'test';
+ $obj2->save();
+ $guids[] = $obj2->guid;
+
+ add_entity_relationship($guids[0], 'test', $guids[1]);
+
+ $options = array(
+ 'relationship' => 'test',
+ 'relationship_guid' => $guids[0]
+ );
+
+ $es = elgg_get_entities_from_relationship($options);
+ $this->assertTrue(is_array($es));
+ $this->assertTrue(count($es), 1);
+
+ foreach ($es as $e) {
+ $this->assertEqual($guids[1], $e->guid);
+ }
+
+ foreach ($guids as $guid) {
+ $e = get_entity($guid);
+ $e->delete();
+ }
+ }
+
+ public function testElggApiGettersEntityRelationshipWithOutMetadata() {
+ $guids = array();
+
+ $obj1 = new ElggObject();
+ $obj1->save();
+ $guids[] = $obj1->guid;
+
+ $obj2 = new ElggObject();
+ $obj2->save();
+ $guids[] = $obj2->guid;
+
+ add_entity_relationship($guids[0], 'test', $guids[1]);
+
+ $options = array(
+ 'relationship' => 'test',
+ 'relationship_guid' => $guids[0]
+ );
+
+ $es = elgg_get_entities_from_relationship($options);
+ $this->assertTrue(is_array($es));
+ $this->assertTrue(count($es), 1);
+
+ foreach ($es as $e) {
+ $this->assertEqual($guids[1], $e->guid);
+ }
+
+ foreach ($guids as $guid) {
+ $e = get_entity($guid);
+ $e->delete();
+ }
+ }
+
+ public function testElggApiGettersEntityRelationshipWithMetadataIncludingRealMetadata() {
+ $guids = array();
+
+ $obj1 = new ElggObject();
+ $obj1->test_md = 'test';
+ $obj1->save();
+ $guids[] = $obj1->guid;
+
+ $obj2 = new ElggObject();
+ $obj2->test_md = 'test';
+ $obj2->save();
+ $guids[] = $obj2->guid;
+
+ add_entity_relationship($guids[0], 'test', $guids[1]);
+
+ $options = array(
+ 'relationship' => 'test',
+ 'relationship_guid' => $guids[0],
+ 'metadata_name' => 'test_md',
+ 'metadata_value' => 'test',
+ );
+
+ $es = elgg_get_entities_from_relationship($options);
+ $this->assertTrue(is_array($es));
+ $this->assertTrue(count($es), 1);
+
+ foreach ($es as $e) {
+ $this->assertEqual($guids[1], $e->guid);
+ }
+
+ foreach ($guids as $guid) {
+ $e = get_entity($guid);
+ $e->delete();
+ }
+ }
+
+ public function testElggApiGettersEntityRelationshipWithMetadataIncludingFakeMetadata() {
+ $guids = array();
+
+ $obj1 = new ElggObject();
+ $obj1->test_md = 'test';
+ $obj1->save();
+ $guids[] = $obj1->guid;
+
+ $obj2 = new ElggObject();
+ $obj2->test_md = 'test';
+ $obj2->save();
+ $guids[] = $obj2->guid;
+
+ add_entity_relationship($guids[0], 'test', $guids[1]);
+
+ $options = array(
+ 'relationship' => 'test',
+ 'relationship_guid' => $guids[0],
+ 'metadata_name' => 'test_md',
+ 'metadata_value' => 'invalid',
+ );
+
+ $es = elgg_get_entities_from_relationship($options);
+
+ $this->assertTrue(empty($es));
+
+ foreach ($guids as $guid) {
+ $e = get_entity($guid);
+ $e->delete();
+ }
+ }
}