]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Deprecated ElggEntity->clearMetadata() by ElggEntity->deleteMetadata(). Disabling...
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sun, 13 Feb 2011 23:53:30 +0000 (23:53 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sun, 13 Feb 2011 23:53:30 +0000 (23:53 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@8213 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/classes/ElggEntity.php
engine/lib/entities.php
engine/tests/objects/entities.php

index 4e1bc586c8f08ea6e037f9d3589dc4b9705f02f7..37422d7027040bbfc067bfd1a3fbe5dfc57e017c 100644 (file)
@@ -271,7 +271,7 @@ abstract class ElggEntity extends ElggData implements
                if (array_key_exists($name, $this->attributes)) {
                        $this->attributes[$name] = "";
                } else {
-                       $this->clearMetaData($name);
+                       $this->deleteMetadata($name);
                }
        }
 
@@ -340,21 +340,79 @@ 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.
+        *
+        * @warning Calling this with no or empty arguments will clear all metadata on the entity.
+        *
+        * @param string $name The metadata name to remove.
+        * @return bool
+        * @since 1.8
+        */
+       public function deleteMetadata($name = null) {
+               $options = array(
+                       'guid' => $this->guid,
+                       'limit' => 0
+               );
+               if ($name) {
+                       $options['metadata_name'] = $name;
+               }
+
+               return elgg_delete_metadata($options);
+       }
+
        /**
         * Remove metadata
         *
         * @warning Calling this with no or empty arguments will clear all metadata on the entity.
         *
         * @param string $name The name of the metadata to clear
-        *
         * @return mixed bool
+        * @deprecated 1.8 Use deleteMetadata()
         */
        public function clearMetaData($name = '') {
-               if (empty($name)) {
-                       return clear_metadata($this->getGUID());
-               } else {
-                       return remove_metadata($this->getGUID(), $name);
+               return $this->deleteMetadata($name);
+       }
+
+       /**
+        * Disables metadata for this entity, optionally based on name.
+        *
+        * @param string $name An options name of metadata to disable.
+        * @return bool
+        * @since 1.8
+        */
+       public function disableMetadata($name = '') {
+               $options = array(
+                       'guid' => $this->guid,
+                       'limit' => 0
+               );
+               if ($name) {
+                       $options['metadata_name'] = $name;
+               }
+
+               return elgg_disable_metadata($options);
+       }
+
+       /**
+        * Enables metadata for this entity, optionally based on name.
+        *
+        * @warning Before calling this, you must use {@link access_show_hidden_entities()}
+        *
+        * @param string $name An options name of metadata to enable.
+        * @return bool
+        * @since 1.8
+        */
+       public function enableMetadata($name = '') {
+               $options = array(
+                       'guid' => $this->guid,
+                       'limit' => 0
+               );
+               if ($name) {
+                       $options['metadata_name'] = $name;
                }
+
+               return elgg_enable_metadata($options);
        }
 
        /**
@@ -376,7 +434,6 @@ abstract class ElggEntity extends ElggData implements
                }
        }
 
-
        /**
         * Set a piece of volatile (non-persisted) data on this entity
         *
@@ -393,7 +450,6 @@ abstract class ElggEntity extends ElggData implements
                $this->volatile[$name] = $value;
        }
 
-
        /**
         * Remove all relationships to and from this entity.
         *
@@ -488,11 +544,52 @@ abstract class ElggEntity extends ElggData implements
                return remove_private_setting($this->getGUID(), $name);
        }
 
+       /**
+        * Disables annotations for this entity, optionally based on name.
+        *
+        * @param string $name An options name of annotations to disable.
+        * @return bool
+        * @since 1.8
+        */
+       public function disableAnnotations($name = '') {
+               $options = array(
+                       'guid' => $this->guid,
+                       'limit' => 0
+               );
+               if ($name) {
+                       $options['annotations_name'] = $name;
+               }
+
+               return elgg_disable_annotations($options);
+       }
+
+       /**
+        * Enables annotations for this entity, optionally based on name.
+        *
+        * @warning Before calling this, you must use {@link access_show_hidden_entities()}
+        *
+        * @param string $name An options name of annotations to enable.
+        * @return bool
+        * @since 1.8
+        */
+       public function enableAnnotations($name = '') {
+               $options = array(
+                       'guid' => $this->guid,
+                       'limit' => 0
+               );
+               if ($name) {
+                       $options['annotations_name'] = $name;
+               }
+
+               return elgg_enable_annotations($options);
+       }
+
        /**
         * Helper function to return annotation calculation results
         *
         * @param string $name        The annotation name.
         * @param string $calculation A valid MySQL function to run its values through
+        * @return mixed
         */
        private function getAnnotationCalculation($name, $calculation) {
                $options = array(
@@ -726,9 +823,9 @@ abstract class ElggEntity extends ElggData implements
        /**
         * Can a user write to this entity
         *
-        * @param int $user_guid The user.
-        * @param string $type The type of entity we're looking to write
-        * @param string $subtype The subtype of the entity we're looking to write
+        * @param int    $user_guid The user.
+        * @param string $type      The type of entity we're looking to write
+        * @param string $subtype   The subtype of the entity we're looking to write
         *
         * @return bool
         */
index 4f58e96a8fc1d079e2a861cfeb11bf42d9d29633..af0092ca1dd22d1a6b44395380962fba1a71b124 100644 (file)
@@ -1153,8 +1153,8 @@ $time_created_lower = NULL, $time_updated_upper = NULL, $time_updated_lower = NU
  *      pagination => BOOL Display pagination links
  *   gallery => BOOL display in gallery view
  *
- * @param mixed $getter The entity getter function to use to fetch the entities
- * @param mixed $viewer The function to use to view the entity list.
+ * @param mixed $getter  The entity getter function to use to fetch the entities
+ * @param mixed $viewer  The function to use to view the entity list.
  *
  * @return string
  * @since 1.7
@@ -1345,20 +1345,14 @@ function disable_entity($guid, $reason = "", $recursive = true) {
                                                }
                                        }
 
-                                       // disable annotations
-                                       // Now delete the entity itself
-//                                     $entity->clearMetadata();
-//                                     $entity->clearAnnotations();
-//                                     $entity->clearRelationships();
-//
-//                                     $res = delete_data("DELETE from {$CONFIG->dbprefix}entities where guid={$guid}");
-//                                     if ($res) {
-//                                             $sub_table = "";
-//                                     }
-
                                        $__RECURSIVE_DELETE_TOKEN = null;
                                }
 
+                               $entity->disableMetadata();
+                               $entity->disableAnnotations();
+                               // relationships can't be disabled. hope they join to the entities table.
+                               //$entity->disableRelationships();
+
                                $res = update_data("UPDATE {$CONFIG->dbprefix}entities
                                        set enabled='no'
                                        where guid={$guid}");
@@ -1398,7 +1392,10 @@ function enable_entity($guid) {
                                $result = update_data("UPDATE {$CONFIG->dbprefix}entities
                                        set enabled='yes'
                                        where guid={$guid}");
-                               $entity->clearMetaData('disable_reason');
+
+                               $entity->deleteMetadata('disable_reason');
+                               $entity->enableMetadata();
+                               $entity->enableAnnotations();
 
                                return $result;
                        }
@@ -1830,9 +1827,9 @@ function get_entity_url($entity_guid) {
 /**
  * Sets the URL handler for a particular entity type and subtype
  *
- * @param string $function_name  The function to register
  * @param string $entity_type    The entity type
  * @param string $entity_subtype The entity subtype
+ * @param string $function_name  The function to register
  *
  * @return true|false Depending on success
  * @see get_entity_url()
@@ -1840,7 +1837,6 @@ function get_entity_url($entity_guid) {
  * @since 1.8.0
  */
 function elgg_register_entity_url_handler($entity_type, $entity_subtype, $function_name) {
-
        global $CONFIG;
 
        if (!is_callable($function_name)) {
@@ -1876,7 +1872,7 @@ function elgg_register_entity_url_handler($entity_type, $entity_subtype, $functi
  * @link http://docs.elgg.org/Search
  * @link http://docs.elgg.org/Tutorials/Search
  */
-function register_entity_type($type, $subtype=null) {
+function register_entity_type($type, $subtype = null) {
        global $CONFIG;
 
        $type = strtolower($type);
@@ -1977,7 +1973,7 @@ function get_registered_entity_types($type = null) {
  *
  * @return true|false Depending on whether or not the type has been registered
  */
-function is_registered_entity_type($type, $subtype=null) {
+function is_registered_entity_type($type, $subtype = null) {
        global $CONFIG;
 
        if (!isset($CONFIG->registered_entities)) {
index 67dd0259628a9511c82fb2ab69b0408405bd26b6..824b47a8a56409e8915300d2d2dec41096f43949 100644 (file)
@@ -186,19 +186,42 @@ class ElggCoreEntityTest extends ElggCoreUnitTest {
                // ensure enabled
                $this->assertTrue($this->entity->isEnabled());
 
-               // false on disable
+               // false on disable because it's not saved yet.
                $this->assertFalse($this->entity->disable());
 
                // save and disable
                $this->save_entity();
+
+               // add annotations and metadata to check if they're disabled.
+               $annotation_id = create_annotation($this->entity->guid, 'test_annotation_' . rand(), 'test_value_' . rand());
+               $metadata_id = create_metadata($this->entity->guid, 'test_metadata_' . rand(), 'test_value_' . rand());
+
                $this->assertTrue($this->entity->disable());
 
                // ensure disabled by comparing directly with database
                $entity = get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid = '{$this->entity->guid}'");
                $this->assertIdentical($entity->enabled, 'no');
 
+               $annotation = get_data_row("SELECT * FROM {$CONFIG->dbprefix}annotations WHERE id = '$annotation_id'");
+               $this->assertIdentical($annotation->enabled, 'no');
+
+               $metadata = get_data_row("SELECT * FROM {$CONFIG->dbprefix}metadata WHERE id = '$metadata_id'");
+               $this->assertIdentical($metadata->enabled, 'no');
+
                // re-enable for deletion to work
                $this->assertTrue($this->entity->enable());
+
+               // check enabled
+               // check annotations and metadata enabled.
+               $entity = get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid = '{$this->entity->guid}'");
+               $this->assertIdentical($entity->enabled, 'yes');
+
+               $annotation = get_data_row("SELECT * FROM {$CONFIG->dbprefix}annotations WHERE id = '$annotation_id'");
+               $this->assertIdentical($annotation->enabled, 'yes');
+
+               $metadata = get_data_row("SELECT * FROM {$CONFIG->dbprefix}metadata WHERE id = '$metadata_id'");
+               $this->assertIdentical($metadata->enabled, 'yes');
+
                $this->assertTrue($this->entity->delete());
        }