]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Merging r6517:6520 from 1.7 branch
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 21 Aug 2010 19:37:19 +0000 (19:37 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 21 Aug 2010 19:37:19 +0000 (19:37 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@6839 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/metadata.php
engine/lib/upgrades/2010061501.php
engine/tests/api/entity_getter_functions.php
mod/search/start.php

index d28999a7714526b1a0bb4a29567d836c56e75892..74ea6858a653024aa7f1c4d392a4902c8daa2991 100644 (file)
@@ -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 '';
        }
 
index 19d6467edac37496154abd8783d01c01aa3a151d..2b65cc5c775494c5c0adceb56c239b01db3e0214 100644 (file)
@@ -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";
index 9fcc6fe0127a0cb9418397f5089ca5ad305a7c44..faa91db3457665e43caf71265b3f3ef365a2039d 100644 (file)
@@ -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();
+               }
+       }
 }
index 3467420b7339359eb52f87b9225069d082650f0a..781afb8ec2f87e5abcc5516263a706e14766acfc 100644 (file)
@@ -259,6 +259,8 @@ function search_highlight_words($words, $string) {
        );
 
        foreach ($words as $word) {
+               // escape the delimiter and any other regexp special chars
+               $word = preg_quote($word, '/');
                $search = "/($word)/i";
 
                // must replace with placeholders in case one of the search terms is