From 3014339c5444a0acf91285a21a39c44906185bf2 Mon Sep 17 00:00:00 2001 From: ben Date: Mon, 6 Oct 2008 17:31:07 +0000 Subject: 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 --- engine/lib/metadata.php | 53 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'engine') 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 -- cgit v1.2.3