aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/elgglib.php17
-rw-r--r--engine/lib/metadata.php24
-rw-r--r--engine/lib/output.php2
-rw-r--r--engine/lib/relationships.php5
-rw-r--r--engine/lib/upgrades/2010062301.php21
-rw-r--r--engine/lib/upgrades/2010062302.php33
-rw-r--r--engine/schema/mysql.sql1
-rw-r--r--engine/schema/upgrades/2010062401.sql1
-rw-r--r--engine/tests/api/entity_getter_functions.php189
9 files changed, 266 insertions, 27 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index f74fbec09..3d08227e4 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -1624,22 +1624,15 @@ function is_not_null($string) {
function elgg_normalise_plural_options_array($options, $singulars) {
foreach ($singulars as $singular) {
$plural = $singular . 's';
-
- // normalize the singular to plural
- // isset() returns FALSE for array values of NULL, so they are ignored.
- // everything else falsy is included.
- //if (isset($options[$singular]) && $options[$singular] !== NULL && $options[$singular] !== FALSE) {
- if (isset($options[$singular])) {
- if (isset($options[$plural])) {
- if (is_array($options[$plural])) {
- $options[$plural][] = $options[$singlar];
- } else {
- $options[$plural] = array($options[$plural], $options[$singular]);
- }
+
+ if (array_key_exists($singular, $options)) {
+ if ($options[$singular] === ELGG_ENTITIES_ANY_VALUE) {
+ $options[$plural] = $options[$singular];
} else {
$options[$plural] = array($options[$singular]);
}
}
+
unset($options[$singular]);
}
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php
index 74ea6858a..6e849cdd9 100644
--- a/engine/lib/metadata.php
+++ b/engine/lib/metadata.php
@@ -186,10 +186,11 @@ function remove_metadata($entity_guid, $name, $value = "") {
* @param int $entity_guid The entity to attach the metadata to
* @param string $name Name of the metadata
* @param string $value Value of the metadata (cannot be associative array)
- * @param string $value_type
- * @param int $owner_guid
- * @param int $access_id
- * @param bool $allow_multiple
+ * @param string $value_type 'text', 'integer', or '' for automatic detection
+ * @param int $owner_guid GUID of entity that owns the metadata
+ * @param int $access_id Default is ACCESS_PRIVATE
+ * @param bool $allow_multiple Allow multiple values for one key. Default is FALSE
+ * @return bool
*/
function create_metadata($entity_guid, $name, $value, $value_type, $owner_guid, $access_id = ACCESS_PRIVATE, $allow_multiple = false) {
global $CONFIG;
@@ -218,8 +219,7 @@ function create_metadata($entity_guid, $name, $value, $value_type, $owner_guid,
if (!$result) {
return false;
}
- }
- else if (isset($value)) {
+ } else if (isset($value)) {
// Support boolean types
if (is_bool($value)) {
if ($value) {
@@ -343,12 +343,12 @@ function update_metadata($id, $name, $value, $value_type, $owner_guid, $access_i
/**
* This function creates metadata from an associative array of "key => value" pairs.
*
- * @param int $entity_guid
- * @param string $name_and_values
- * @param string $value_type
- * @param int $owner_guid
- * @param int $access_id
- * @param bool $allow_multiple
+ * @param int $entity_guid The entity to attach the metadata to
+ * @param string $name_and_values Associative array
+ * @param string $value_type 'text', 'integer', or '' for automatic detection
+ * @param int $owner_guid GUID of entity that owns the metadata
+ * @param int $access_id Default is ACCESS_PRIVATE
+ * @param bool $allow_multiple Allow multiple values for one key. Default is FALSE
*/
function create_metadata_from_array($entity_guid, array $name_and_values, $value_type, $owner_guid, $access_id = ACCESS_PRIVATE, $allow_multiple = false) {
foreach ($name_and_values as $k => $v) {
diff --git a/engine/lib/output.php b/engine/lib/output.php
index 70c3821d6..3b82447b0 100644
--- a/engine/lib/output.php
+++ b/engine/lib/output.php
@@ -116,7 +116,7 @@ function elgg_make_excerpt($text, $num_chars = 250) {
$excerpt = trim(elgg_substr($excerpt, 0, $space));
if ($string_length != elgg_strlen($excerpt)) {
- $excerpt .= '&#8230';
+ $excerpt .= '...';
}
return $excerpt;
diff --git a/engine/lib/relationships.php b/engine/lib/relationships.php
index f813cacba..f1d119452 100644
--- a/engine/lib/relationships.php
+++ b/engine/lib/relationships.php
@@ -358,13 +358,16 @@ function add_entity_relationship($guid_one, $relationship, $guid_two) {
$guid_one = (int)$guid_one;
$relationship = sanitise_string($relationship);
$guid_two = (int)$guid_two;
+ $time = time();
// Check for duplicates
if (check_entity_relationship($guid_one, $relationship, $guid_two)) {
return false;
}
- $result = insert_data("INSERT into {$CONFIG->dbprefix}entity_relationships (guid_one, relationship, guid_two) values ($guid_one, '$relationship', $guid_two)");
+ $result = insert_data("INSERT into {$CONFIG->dbprefix}entity_relationships
+ (guid_one, relationship, guid_two, time_created)
+ values ($guid_one, '$relationship', $guid_two, $time)");
if ($result!==false) {
$obj = get_relationship($result);
diff --git a/engine/lib/upgrades/2010062301.php b/engine/lib/upgrades/2010062301.php
new file mode 100644
index 000000000..96fd6c810
--- /dev/null
+++ b/engine/lib/upgrades/2010062301.php
@@ -0,0 +1,21 @@
+<?php
+
+/**
+ * Change ownership of group ACLs to group entity
+ */
+
+elgg_set_ignore_access(TRUE);
+
+$params = array('type' => 'group',
+ 'limit' => 0);
+$groups = elgg_get_entities($params);
+if ($groups) {
+ foreach ($groups as $group) {
+ $acl = $group->group_acl;
+
+ $query = "UPDATE {$CONFIG->dbprefix}access_collections SET owner_guid = $group->guid WHERE id = $acl";
+ update_data($query);
+ }
+}
+elgg_set_ignore_access(FALSE);
+
diff --git a/engine/lib/upgrades/2010062302.php b/engine/lib/upgrades/2010062302.php
new file mode 100644
index 000000000..fe33e12ea
--- /dev/null
+++ b/engine/lib/upgrades/2010062302.php
@@ -0,0 +1,33 @@
+<?php
+
+/**
+ * Make sure that everyone who belongs to a group is a member of the group's access collection
+ */
+
+
+elgg_set_ignore_access(TRUE);
+
+$params = array('type' => 'group', 'limit' => 0);
+$groups = elgg_get_entities($params);
+if ($groups) {
+ foreach ($groups as $group) {
+ $acl = $group->group_acl;
+
+ $query = "SELECT u.guid FROM {$CONFIG->dbprefix}users_entity u
+ JOIN {$CONFIG->dbprefix}entity_relationships r
+ ON u.guid = r.guid_one AND r.relationship = 'member' AND r.guid_two = $group->guid
+ LEFT JOIN {$CONFIG->dbprefix}access_collection_membership a
+ ON u.guid = a.user_guid AND a.access_collection_id = $acl
+ WHERE a.user_guid IS NULL";
+
+ $results = get_data($query);
+ if ($results != FALSE) {
+ foreach ($results as $user) {
+ $insert = "INSERT INTO {$CONFIG->dbprefix}access_collection_membership
+ (user_guid, access_collection_id) VALUES ($user->guid, $acl)";
+ insert_data($insert);
+ }
+ }
+ }
+}
+elgg_set_ignore_access(FALSE);
diff --git a/engine/schema/mysql.sql b/engine/schema/mysql.sql
index 23e81f39d..526cc8ce6 100644
--- a/engine/schema/mysql.sql
+++ b/engine/schema/mysql.sql
@@ -155,6 +155,7 @@ CREATE TABLE `prefix_entity_relationships` (
`guid_one` bigint(20) unsigned NOT NULL,
`relationship` varchar(50) NOT NULL,
`guid_two` bigint(20) unsigned NOT NULL,
+ `time_created` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `guid_one` (`guid_one`,`relationship`,`guid_two`),
KEY `relationship` (`relationship`),
diff --git a/engine/schema/upgrades/2010062401.sql b/engine/schema/upgrades/2010062401.sql
new file mode 100644
index 000000000..fbb49bfcf
--- /dev/null
+++ b/engine/schema/upgrades/2010062401.sql
@@ -0,0 +1 @@
+ALTER TABLE `prefix_entity_relationships` ADD COLUMN `time_created` int(11) NOT NULL AFTER `guid_two`; \ No newline at end of file
diff --git a/engine/tests/api/entity_getter_functions.php b/engine/tests/api/entity_getter_functions.php
index faa91db34..f193fda41 100644
--- a/engine/tests/api/entity_getter_functions.php
+++ b/engine/tests/api/entity_getter_functions.php
@@ -2168,7 +2168,7 @@ class ElggCoreEntityGetterFunctionsTest extends ElggCoreUnitTest {
);
$es = elgg_get_entities_from_relationship($options);
-
+
$this->assertTrue(empty($es));
foreach ($guids as $guid) {
@@ -2176,4 +2176,191 @@ class ElggCoreEntityGetterFunctionsTest extends ElggCoreUnitTest {
$e->delete();
}
}
+
+ public function testElggApiGettersEntitySiteSingular() {
+ global $CONFIG;
+
+ $guids = array();
+
+ $obj1 = new ElggObject();
+ $obj1->test_md = 'test';
+ // luckily this is never checked.
+ $obj1->site_guid = 2;
+ $obj1->save();
+ $guids[] = $obj1->guid;
+ $right_guid = $obj1->guid;
+
+ $obj2 = new ElggObject();
+ $obj2->test_md = 'test';
+ $obj2->site_guid = $CONFIG->site->guid;
+ $obj2->save();
+ $guids[] = $obj2->guid;
+
+ $options = array(
+ 'metadata_name' => 'test_md',
+ 'metadata_value' => 'test',
+ 'site_guid' => 2
+ );
+
+ $es = elgg_get_entities_from_metadata($options);
+ $this->assertTrue(is_array($es));
+ $this->assertEqual(1, count($es));
+ $this->assertEqual($right_guid, $es[0]->guid);
+
+ foreach ($guids as $guid) {
+ get_entity($guid)->delete();
+ }
+ }
+
+ public function testElggApiGettersEntitySiteSingularAny() {
+ global $CONFIG;
+
+ $guids = array();
+
+ $obj1 = new ElggObject();
+ $obj1->test_md = 'test';
+ // luckily this is never checked.
+ $obj1->site_guid = 2;
+ $obj1->save();
+ $guids[] = $obj1->guid;
+
+ $obj2 = new ElggObject();
+ $obj2->test_md = 'test';
+ $obj2->site_guid = $CONFIG->site->guid;
+ $obj2->save();
+ $guids[] = $obj2->guid;
+
+ $options = array(
+ 'metadata_name' => 'test_md',
+ 'metadata_value' => 'test',
+ 'site_guid' => ELGG_ENTITIES_ANY_VALUE,
+ 'limit' => 2,
+ 'order_by' => 'e.guid DESC'
+ );
+
+ $es = elgg_get_entities_from_metadata($options);
+ $this->assertTrue(is_array($es));
+ $this->assertEqual(2, count($es));
+
+ foreach ($es as $e) {
+ $this->assertTrue(in_array($e->guid, $guids));
+ }
+
+ foreach ($guids as $guid) {
+ get_entity($guid)->delete();
+ }
+ }
+
+ public function testElggApiGettersEntitySitePlural() {
+ global $CONFIG;
+
+ $guids = array();
+
+ $obj1 = new ElggObject();
+ $obj1->test_md = 'test';
+ // luckily this is never checked.
+ $obj1->site_guid = 2;
+ $obj1->save();
+ $guids[] = $obj1->guid;
+
+ $obj2 = new ElggObject();
+ $obj2->test_md = 'test';
+ $obj2->site_guid = $CONFIG->site->guid;
+ $obj2->save();
+ $guids[] = $obj2->guid;
+
+ $options = array(
+ 'metadata_name' => 'test_md',
+ 'metadata_value' => 'test',
+ 'site_guids' => array($CONFIG->site->guid, 2),
+ 'limit' => 2,
+ 'order_by' => 'e.guid DESC'
+ );
+
+ $es = elgg_get_entities_from_metadata($options);
+ $this->assertTrue(is_array($es));
+ $this->assertEqual(2, count($es));
+
+ foreach ($es as $e) {
+ $this->assertTrue(in_array($e->guid, $guids));
+ }
+
+ foreach ($guids as $guid) {
+ get_entity($guid)->delete();
+ }
+ }
+
+ public function testElggApiGettersEntitySitePluralSomeInvalid() {
+ global $CONFIG;
+
+ $guids = array();
+
+ $obj1 = new ElggObject();
+ $obj1->test_md = 'test';
+ // luckily this is never checked.
+ $obj1->site_guid = 2;
+ $obj1->save();
+ $guids[] = $obj1->guid;
+
+ $obj2 = new ElggObject();
+ $obj2->test_md = 'test';
+ $obj2->save();
+ $guids[] = $obj2->guid;
+ $right_guid = $obj2->guid;
+
+ $options = array(
+ 'metadata_name' => 'test_md',
+ 'metadata_value' => 'test',
+ // just created the first entity so nothing will be "sited" by it.
+ 'site_guids' => array($CONFIG->site->guid, $guids[0]),
+ 'limit' => 2,
+ 'order_by' => 'e.guid DESC'
+ );
+
+ $es = elgg_get_entities_from_metadata($options);
+
+ $this->assertTrue(is_array($es));
+ $this->assertEqual(1, count($es));
+ $this->assertEqual($es[0]->guid, $right_guid);
+
+ foreach ($guids as $guid) {
+ get_entity($guid)->delete();
+ }
+ }
+
+ public function testElggApiGettersEntitySitePluralAllInvalid() {
+ global $CONFIG;
+
+ $guids = array();
+
+ $obj1 = new ElggObject();
+ $obj1->test_md = 'test';
+ // luckily this is never checked.
+ $obj1->site_guid = 2;
+ $obj1->save();
+ $guids[] = $obj1->guid;
+
+ $obj2 = new ElggObject();
+ $obj2->test_md = 'test';
+ $obj2->save();
+ $guids[] = $obj2->guid;
+ $right_guid = $obj2->guid;
+
+ $options = array(
+ 'metadata_name' => 'test_md',
+ 'metadata_value' => 'test',
+ // just created the first entity so nothing will be "sited" by it.
+ 'site_guids' => array($guids[0], $guids[1]),
+ 'limit' => 2,
+ 'order_by' => 'e.guid DESC'
+ );
+
+ $es = elgg_get_entities_from_metadata($options);
+
+ $this->assertTrue(empty($es));
+
+ foreach ($guids as $guid) {
+ get_entity($guid)->delete();
+ }
+ }
}