diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2011-02-14 03:13:31 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2011-02-14 03:13:31 +0000 |
commit | 8e065905e4172d0ccd01266c6f8e58a65803d011 (patch) | |
tree | adb6f8d3e3b76f1e6339d46a18945b3b29c80dbc /engine/classes | |
parent | 422434216351c84e868b2c91e8bf0059446b89ed (diff) | |
download | elgg-8e065905e4172d0ccd01266c6f8e58a65803d011.tar.gz elgg-8e065905e4172d0ccd01266c6f8e58a65803d011.tar.bz2 |
Fixes #2918. Moved annotation/metadata delete functions from ElggUser to ElggEntity. When deleted, entities now correctly delete metadata they own as well as metadata on them. Removed uses of deprecated functions.
git-svn-id: http://code.elgg.org/elgg/trunk@8222 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/classes')
-rw-r--r-- | engine/classes/ElggEntity.php | 99 | ||||
-rw-r--r-- | engine/classes/ElggUser.php | 3 |
2 files changed, 93 insertions, 9 deletions
diff --git a/engine/classes/ElggEntity.php b/engine/classes/ElggEntity.php index 37422d702..3dc5088f5 100644 --- a/engine/classes/ElggEntity.php +++ b/engine/classes/ElggEntity.php @@ -341,12 +341,12 @@ abstract class ElggEntity extends ElggData implements } /** - * Deletes all metadata on this object. If you pass a name, only - * metadata matching that name will be deleted. + * Deletes all metadata on this object (metadata.entity_guid = $this->guid). + * If you pass a name, only metadata matching that name will be deleted. * * @warning Calling this with no or empty arguments will clear all metadata on the entity. * - * @param string $name The metadata name to remove. + * @param null|string $name The metadata name to remove. * @return bool * @since 1.8 */ @@ -363,6 +363,31 @@ abstract class ElggEntity extends ElggData implements } /** + * Deletes all metadata owned by this object (metadata.owner_guid = $this->guid). + * If you pass a name, only metadata matching that name will be deleted. + * + * @param null|string $name The name of metadata to delete. + * @return bool + * @since 1.8 + */ + public function deleteOwnedMetadata($name = null) { + // access is turned off for this because they might + // no longer have access to an entity they created metadata on. + $ia = elgg_set_ignore_access(true); + $options = array( + 'metadata_owner_guid' => $this->guid, + 'limit' => 0 + ); + if ($name) { + $options['metadata_name'] = $name; + } + + $r = elgg_delete_metadata($options); + elgg_set_ignore_access($ia); + return $r; + } + + /** * Remove metadata * * @warning Calling this with no or empty arguments will clear all metadata on the entity. @@ -372,6 +397,7 @@ abstract class ElggEntity extends ElggData implements * @deprecated 1.8 Use deleteMetadata() */ public function clearMetaData($name = '') { + elgg_deprecated_notice('ElggEntity->clearMetadata() is deprecated by ->deleteMetadata()', 1.8); return $this->deleteMetadata($name); } @@ -458,13 +484,26 @@ abstract class ElggEntity extends ElggData implements * @see ElggEntity::addRelationship() * @see ElggEntity::removeRelationship() */ - public function clearRelationships() { + public function deleteRelationships() { remove_entity_relationships($this->getGUID()); remove_entity_relationships($this->getGUID(), "", true); return true; } /** + * Remove all relationships to and from this entity. + * + * @return bool + * @see ElggEntity::addRelationship() + * @see ElggEntity::removeRelationship() + * @deprecated 1.8 Use ->deleteRelationship() + */ + public function clearRelationships() { + elgg_deprecated_notice('ElggEntity->clearRelationships() is deprecated by ->deleteRelationships()', 1.8); + return $this->deleteRelationships(); + } + + /** * Add a relationship between this an another entity. * * @tip Read the relationship like "$guid is a $relationship of this entity." @@ -545,6 +584,53 @@ abstract class ElggEntity extends ElggData implements } /** + * Deletes all annotations on this object (annotations.entity_guid = $this->guid). + * If you pass a name, only annotations matching that name will be deleted. + * + * @warning Calling this with no or empty arguments will clear all annotations on the entity. + * + * @param null|string $name The annotations name to remove. + * @return bool + * @since 1.8 + */ + public function deleteAnnotations($name = null) { + $options = array( + 'guid' => $this->guid, + 'limit' => 0 + ); + if ($name) { + $options['annotations_name'] = $name; + } + + return elgg_delete_annotations($options); + } + + /** + * Deletes all annotations owned by this object (annotations.owner_guid = $this->guid). + * If you pass a name, only annotations matching that name will be deleted. + * + * @param null|string $name The name of annotations to delete. + * @return bool + * @since 1.8 + */ + public function deleteOwnedAnnotations($name = null) { + // access is turned off for this because they might + // no longer have access to an entity they created annotations on. + $ia = elgg_set_ignore_access(true); + $options = array( + 'annotations_owner_guid' => $this->guid, + 'limit' => 0 + ); + if ($name) { + $options['annotations_name'] = $name; + } + + $r = elgg_delete_annotations($options); + elgg_set_ignore_access($ia); + return $r; + } + + /** * Disables annotations for this entity, optionally based on name. * * @param string $name An options name of annotations to disable. @@ -662,11 +748,12 @@ abstract class ElggEntity extends ElggData implements * all annotations on the entity. * * @param string $name Annotation name - * * @return bool + * @deprecated 1.8 Use ->deleteAnnotations() */ function clearAnnotations($name = "") { - return clear_annotations($this->getGUID(), $name); + elgg_deprecated_notice('ElggEntity->clearAnnotations() is deprecated by ->deleteAnnotations()', 1.8); + return $this->deleteAnnotations($name); } /** diff --git a/engine/classes/ElggUser.php b/engine/classes/ElggUser.php index b2303c525..82f03c6ed 100644 --- a/engine/classes/ElggUser.php +++ b/engine/classes/ElggUser.php @@ -157,9 +157,6 @@ class ElggUser extends ElggEntity unset($CODE_TO_GUID_MAP_CACHE[$this->code]); } - // Delete owned data - clear_annotations_by_owner($this->guid); - clear_metadata_by_owner($this->guid); clear_user_files($this); // Delete entity |