diff options
author | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-10-06 17:31:07 +0000 |
---|---|---|
committer | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-10-06 17:31:07 +0000 |
commit | 3014339c5444a0acf91285a21a39c44906185bf2 (patch) | |
tree | a8bb5166769b1a0c23681eed9146bbaf822b7b39 /engine | |
parent | 4abe1362ab10fbf59bb87c1b7c894537b7766b58 (diff) | |
download | elgg-3014339c5444a0acf91285a21a39c44906185bf2.tar.gz elgg-3014339c5444a0acf91285a21a39c44906185bf2.tar.bz2 |
Introduced a way to either tether metadata access to entities, or to make them independent - in either case, explicitly.
git-svn-id: https://code.elgg.org/elgg/trunk@2197 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r-- | engine/lib/metadata.php | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php index 4c2685296..4084d6959 100644 --- a/engine/lib/metadata.php +++ b/engine/lib/metadata.php @@ -766,6 +766,54 @@ return get_extender_url($extender); } return false; + }
+
+ /**
+ * Mark entities with a particular type and subtype as having access permissions
+ * that can be changed independently from their parent entity
+ *
+ * @param string $type The type - object, user, etc
+ * @param string $subtype The subtype; all subtypes by default
+ */
+ function register_metadata_as_independent($type, $subtype = '*') {
+ global $CONFIG;
+ if (!isset($CONFIG->independents)) $CONFIG->independents = array();
+ $CONFIG->independents[$type][$subtype] = true;
+ }
+
+ /**
+ * Determines whether entities of a given type and subtype should not change
+ * their metadata in line with their parent entity
+ *
+ * @param string $type The type - object, user, etc
+ * @param string $subtype The entity subtype
+ * @return true|false
+ */
+ function is_metadata_independent($type, $subtype) {
+ global $CONFIG;
+ if (empty($CONFIG->independents)) return false;
+ if (!empty($CONFIG->independents[$type][$subtype])
+ || !empty($CONFIG->independents[$type]['*'])) return true;
+ return false;
+ }
+
+ /**
+ * When an entity is updated, resets the access ID on all of its child metadata
+ *
+ * @param string $event The name of the event
+ * @param string $object_type The type of object
+ * @param ElggEntity $object The entity itself
+ */
+ function metadata_update($event, $object_type, $object) {
+ if ($object instanceof ElggEntity) {
+ if (!is_metadata_independent($object->getType(), $object->getSubtype())) {
+ global $CONFIG;
+ $access_id = (int) $object->access_id;
+ $guid = (int) $object->getGUID();
+ update_data("update {$CONFIG->dbprefix}metadata set access_id = {$access_id} where entity_guid = {$guid}");
+ }
+ }
+ return true;
} /** @@ -779,5 +827,8 @@ } /** Register the hook */ - register_plugin_hook("export", "all", "export_metadata_plugin_hook", 2); + register_plugin_hook("export", "all", "export_metadata_plugin_hook", 2);
+ /** Call a function whenever an entity is updated **/
+ register_elgg_event_handler('update','all','metadata_update');
+ ?>
\ No newline at end of file |