Permalink
Browse files

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
  • Loading branch information...
1 parent 4224342 commit 8e065905e4172d0ccd01266c6f8e58a65803d011 @brettp brettp committed Feb 14, 2011
Showing with 100 additions and 12 deletions.
  1. +93 −6 engine/classes/ElggEntity.php
  2. +0 −3 engine/classes/ElggUser.php
  3. +7 −3 engine/lib/entities.php
@@ -341,12 +341,12 @@ public function setMetaData($name, $value, $value_type = "", $multiple = false)
}
/**
- * 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 @@ public function deleteMetadata($name = null) {
}
/**
+ * 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 @@ public function deleteMetadata($name = null) {
* @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 @@ public function setVolatileData($name, $value) {
* @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 @@ function removePrivateSetting($name) {
}
/**
+ * 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 @@ function getAnnotations($name, $limit = 50, $offset = 0, $order = "asc") {
* 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);
}
/**
@@ -157,9 +157,6 @@ public function delete() {
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
@@ -1462,12 +1462,16 @@ function delete_entity($guid, $recursive = true) {
}
// Now delete the entity itself
- $entity->clearMetadata();
- $entity->clearAnnotations();
- $entity->clearRelationships();
+ $entity->deleteMetadata();
+ $entity->deleteOwnedMetadata();
+ $entity->deleteAnnotations();
+ $entity->deleteOwnedAnnotations();
+ $entity->deleteRelationships();
+
remove_from_river_by_subject($guid);
remove_from_river_by_object($guid);
remove_all_private_settings($guid);
+
$res = delete_data("DELETE from {$CONFIG->dbprefix}entities where guid={$guid}");
if ($res) {
$sub_table = "";

0 comments on commit 8e06590

Please sign in to comment.