]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Updated trunk to use new annotation functions. Added checks for annotations_* options...
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Mon, 14 Feb 2011 03:40:59 +0000 (03:40 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Mon, 14 Feb 2011 03:40:59 +0000 (03:40 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@8223 36083f99-b078-4883-b0ff-0f9b5a30f544

16 files changed:
actions/comments/delete.php
actions/likes/delete.php
actions/profile/edit.php
engine/classes/ElggAnnotation.php
engine/classes/ElggEntity.php
engine/classes/ElggRiverItem.php
engine/handlers/export_handler.php
engine/lib/annotations.php
engine/lib/metadata.php
engine/lib/metastrings.php
engine/tests/api/entity_getter_functions.php
engine/tests/api/metastrings.php
engine/tests/regression/trac_bugs.php
mod/blog/lib/blog.php
mod/messageboard/actions/delete.php
mod/pages/revision.php

index 54eb9707776c9a3e38858b5c995e914c337df324..f8458a15253862652a17510f49612ca0b5870446 100644 (file)
@@ -12,7 +12,7 @@ if (!elgg_is_logged_in()) {
 
 // Make sure we can get the comment in question
 $annotation_id = (int) get_input('annotation_id');
-if ($comment = get_annotation($annotation_id)) {
+if ($comment = elgg_get_annotation_from_id($annotation_id)) {
 
        $entity = get_entity($comment->entity_guid);
 
index 168818a60d5d43b75f0599b95e28f2126335bdad..7d535052d870c012717bb0d410ac139e10837e15 100644 (file)
@@ -13,7 +13,7 @@ if (!elgg_is_logged_in()) {
 
 // Make sure we can get the comment in question
 $annotation_id = (int) get_input('annotation_id');
-if ($likes = get_annotation($annotation_id)) {
+if ($likes = elgg_get_annotation_from_id($annotation_id)) {
 
        $entity = get_entity($likes->entity_guid);
 
index 260f2aba9a12c450db9fa8099c7c87ea98b784b1..e86053b07441941db9d106f842dd276b385efe62 100644 (file)
@@ -74,7 +74,11 @@ if ($name) {
 // go through custom fields
 if (sizeof($input) > 0) {
        foreach ($input as $shortname => $value) {
-               remove_metadata($owner->guid, $shortname);
+               $options = array(
+                       'guid' => $owner->guid,
+                       'metadata_name' => $shortname
+               );
+               elgg_delete_metadata($options);
                if (isset($accesslevel[$shortname])) {
                        $access_id = (int) $accesslevel[$shortname];
                } else {
index 274cbb923d4a610612177709caca60c5f0612246..f61ea520d4b036afcd821b8f967dd412d93ec3c3 100644 (file)
@@ -39,7 +39,7 @@ class ElggAnnotation extends ElggExtender {
                        if ($id instanceof stdClass) {
                                $annotation = $id;
                        } else {
-                               $annotation = get_annotation($id);
+                               $annotation = elgg_get_annotation_from_id($id);
                        }
 
                        if ($annotation) {
@@ -122,6 +122,6 @@ class ElggAnnotation extends ElggExtender {
         * @return ElggAnnotation
         */
        public function getObjectFromID($id) {
-               return get_annotation($id);
+               return elgg_get_annotation_from_id($id);
        }
 }
index 3dc5088f592e765fe2c13836390f45f499af64b4..1be1d5d15caf32111f8d2d7595c1cb5e557bf6ef 100644 (file)
@@ -599,7 +599,7 @@ abstract class ElggEntity extends ElggData implements
                        'limit' => 0
                );
                if ($name) {
-                       $options['annotations_name'] = $name;
+                       $options['annotation_name'] = $name;
                }
 
                return elgg_delete_annotations($options);
@@ -618,11 +618,11 @@ abstract class ElggEntity extends ElggData implements
                // no longer have access to an entity they created annotations on.
                $ia = elgg_set_ignore_access(true);
                $options = array(
-                       'annotations_owner_guid' => $this->guid,
+                       'annotation_owner_guid' => $this->guid,
                        'limit' => 0
                );
                if ($name) {
-                       $options['annotations_name'] = $name;
+                       $options['annotation_name'] = $name;
                }
 
                $r = elgg_delete_annotations($options);
@@ -643,7 +643,7 @@ abstract class ElggEntity extends ElggData implements
                        'limit' => 0
                );
                if ($name) {
-                       $options['annotations_name'] = $name;
+                       $options['annotation_name'] = $name;
                }
 
                return elgg_disable_annotations($options);
@@ -664,7 +664,7 @@ abstract class ElggEntity extends ElggData implements
                        'limit' => 0
                );
                if ($name) {
-                       $options['annotations_name'] = $name;
+                       $options['annotation_name'] = $name;
                }
 
                return elgg_enable_annotations($options);
index 6ff9b01d1c364498ec6947131aa156c6a3fd43b5..cdb22239dea8467b8ec1ab11da9c0c18865553c2 100644 (file)
@@ -57,7 +57,7 @@ class ElggRiverItem
         * @return ElggAnnotation
         */
        public function getAnnotation() {
-               return get_annotation($this->annotation_id);
+               return elgg_get_annotation_from_id($this->annotation_id);
        }
 
        /**
index b56a20b9387a62d4ca425f7fb36bbe84ef6f2d79..b91a037e8d4f818edea05f9968056e2a8204ba86 100644 (file)
@@ -66,7 +66,7 @@ if (($guid != "") && ($type == "") && ($id_or_name == "")) {
                        $m = elgg_get_metadata_from_id($id_or_name);
                        break;
                case 'annotation' :
-                       $m = get_annotation($id_or_name);
+                       $m = elgg_get_annotation_from_id($id_or_name);
                        break;
                case 'relationship' :
                        $r = get_relationship($id_or_name);
index c37596ea865604c238e1964ca7ac9adb3c4c341f..0235476f2f167b747dbcb94b0e5671224bfdc319 100644 (file)
@@ -32,7 +32,21 @@ function row_to_elggannotation($row) {
  * @return false|ElggAnnotation
  */
 function elgg_get_annotation_from_id($id) {
-       return elgg_get_metastring_based_object_by_id($id, 'annotations');
+       return elgg_get_metastring_based_object_from_id($id, 'annotations');
+}
+
+/**
+ * Deletes an annotation using its ID.
+ *
+ * @param int $id The annotation ID to delete.
+ * @return bool
+ */
+function elgg_delete_annotation_by_id($id) {
+       $annotation = elgg_get_annotation_from_id($id);
+       if (!$annotation) {
+               return false;
+       }
+       return $annotation->delete();
 }
 
 /**
@@ -88,12 +102,12 @@ $owner_guid, $access_id = ACCESS_PRIVATE) {
                        ($entity_guid,'$name',$value,'$value_type', $owner_guid, $time, $access_id)");
 
                if ($result !== false) {
-                       $obj = get_annotation($result);
+                       $obj = elgg_get_annotation_from_id($result);
                        if (elgg_trigger_event('create', 'annotation', $obj)) {
                                return $result;
                        } else {
                                // plugin returned false to reject annotation
-                               delete_annotation($result);
+                               elgg_delete_annotation_by_id($result);
                                return FALSE;
                        }
                }
@@ -148,12 +162,12 @@ function update_annotation($annotation_id, $name, $value, $value_type, $owner_gu
                where id=$annotation_id and name_id='$name' and $access");
 
        if ($result !== false) {
-               $obj = get_annotation($annotation_id);
+               $obj = elgg_get_annotation_from_id($annotation_id);
                if (elgg_trigger_event('update', 'annotation', $obj)) {
                        return true;
                } else {
                        // @todo add plugin hook that sends old and new annotation information before db access
-                       delete_annotation($annotation_id);
+                       elgg_delete_annotation_by_id($annotation_id);
                }
        }
 
@@ -470,7 +484,7 @@ function export_annotation_plugin_hook($hook, $entity_type, $returnvalue, $param
 function get_annotation_url($id) {
        $id = (int)$id;
 
-       if ($extender = get_annotation($id)) {
+       if ($extender = elgg_get_annotation_from_id($id)) {
                return get_extender_url($extender);
        }
        return false;
index 08c87ae67355c0b5a5c4f60c5c663353df34d01e..c05e0b161d30654ee7a8173e8606a88cc3e28b24 100644 (file)
@@ -32,7 +32,21 @@ function row_to_elggmetadata($row) {
  * @return false|ElggMetadata
  */
 function elgg_get_metadata_from_id($id) {
-       return elgg_get_metastring_based_object_by_id($id, 'metadata');
+       return elgg_get_metastring_based_object_from_id($id, 'metadata');
+}
+
+/**
+ * Deletes metadata using its ID.
+ *
+ * @param int $id The metadata ID to delete.
+ * @return bool
+ */
+function elgg_delete_metadata_by_id($id) {
+       $metadata = elgg_get_metadata_from_id($id);
+       if (!$metadata) {
+               return false;
+       }
+       return $metadata->delete();
 }
 
 /**
index 6376ac09ba3165e9fa2ba63177f79de182ea4946..8c702239b25210b0142421da96b567e8023fd81a 100644 (file)
@@ -585,7 +585,8 @@ function elgg_normalize_metastrings_options(array $options = array()) {
 
        $options['metastring_type'] = $type;
 
-       $prefixes = array('metadata_', 'annotation_');
+       // support annotation_ and annotations_ because they're way too easy to confuse
+       $prefixes = array('metadata_', 'annotation_', 'annotations_');
 
        // map the metadata_* options to metastring_* options
        $map = array(
@@ -632,7 +633,7 @@ function elgg_set_metastring_based_object_enabled_by_id($id, $enabled, $type) {
        $id = (int)$id;
        $db_prefix = elgg_get_config('dbprefix');
 
-       $object = elgg_get_metastring_based_object_by_id($id, $type);
+       $object = elgg_get_metastring_based_object_from_id($id, $type);
 
        switch($type) {
                case 'annotation':
@@ -702,7 +703,7 @@ function elgg_batch_metastring_based_objects(array $options, $callback) {
  * @since 1.8
  * @access private
  */
-function elgg_get_metastring_based_object_by_id($id, $type) {
+function elgg_get_metastring_based_object_from_id($id, $type) {
        $id = (int)$id;
        if (!$id) {
                return false;
@@ -750,7 +751,7 @@ function elgg_delete_metastring_based_object_by_id($id, $type) {
                        return false;
        }
 
-       $obj = elgg_get_metastring_based_object_by_id($id, $type);
+       $obj = elgg_get_metastring_based_object_from_id($id, $type);
        $table = $db_prefix . $type;
 
        if ($obj) {
index e3e265d21185e660db7185f2aae39a877feb0502..1633cbe19aa70dd9bdf01846ca61f4401075a0ea 100644 (file)
@@ -239,7 +239,7 @@ class ElggCoreEntityGetterFunctionsTest extends ElggCoreUnitTest {
                        $name = 'test_annotation_name_' . rand();
                        $value = rand();
                        $id = create_annotation($entity->getGUID(), $name, $value, 'integer', $entity->getGUID());
-                       $annotations[] = get_annotation($id);
+                       $annotations[] = elgg_get_annotation_from_id($id);
                }
 
                return $annotations;
@@ -2772,7 +2772,7 @@ class ElggCoreEntityGetterFunctionsTest extends ElggCoreUnitTest {
                        } while(in_array($e->guid, $a_e_map));
 
                        // remove annotations left over from previous tests.
-                       clear_annotations($e->guid);
+                       elgg_delete_annotations(array('annotation_owner_guid' => $e->guid));
                        $annotations = $this->createRandomAnnotations($e);
 
                        foreach($annotations as $a) {
index 9d089f804707ea22a326b49612cd98b7c1e5ec3d..e5cfe80e1fdf31ddcd618626cbb47c34e0c3181c 100644 (file)
@@ -88,14 +88,14 @@ class ElggCoreMetastringsTest extends ElggCoreUnitTest {
                }
        }
 
-       public function testGetMetastringObjectByID() {
+       public function testGetMetastringObjectFromID() {
                $db_prefix = elgg_get_config('dbprefix');
                $annotations = $this->createAnnotations(1);
                $metadata = $this->createMetadata(1);
 
                foreach ($this->metastringTypes as $type) {
                        $id = ${$type}[0];
-                       $test = elgg_get_metastring_based_object_by_id($id, $type);
+                       $test = elgg_get_metastring_based_object_from_id($id, $type);
 
                        $this->assertEqual($id, $test->id);
                }
index 93831fd7e688e1ddbb958ed37ff1b1059c1d504a..71aae3d34331d3b30aafb54ed2d303ed261cfb81 100644 (file)
@@ -14,7 +14,7 @@ class ElggCoreRegressionBugsTest extends ElggCoreUnitTest {
        public function __construct() {
                $this->ia = elgg_set_ignore_access(TRUE);
                parent::__construct();
-               
+
                // all __construct() code should come after here
        }
 
@@ -48,20 +48,20 @@ class ElggCoreRegressionBugsTest extends ElggCoreUnitTest {
        public function testElggObjectClearAnnotations() {
                $this->entity = new ElggObject();
                $guid = $this->entity->save();
-               
+
                $this->entity->annotate('test', 'hello', ACCESS_PUBLIC);
-               
-               $this->entity->clearAnnotations('does not exist');
-               
+
+               $this->entity->deleteAnnotations('does not exist');
+
                $num = $this->entity->countAnnotations('test');
-               
+
                //$this->assertIdentical($num, 1);
                $this->assertEqual($num, 1);
-               
+
                // clean up
                $this->entity->delete();
        }
-       
+
        /**
         * #2063 - get_resized_image_from_existing_file() fails asked for image larger than selection and not scaling an image up
         * Test get_image_resize_parameters().
@@ -69,44 +69,44 @@ class ElggCoreRegressionBugsTest extends ElggCoreUnitTest {
        public function testElggResizeImage() {
                $orig_width = 100;
                $orig_height = 150;
-               
+
                // test against selection > max
                $options = array(
                        'maxwidth' => 50,
                        'maxheight' => 50,
                        'square' => TRUE,
                        'upscale' => FALSE,
-               
+
                        'x1' => 25,
                        'y1' => 75,
                        'x2' => 100,
                        'y2' => 150
                );
-               
-               // should get back the same x/y offset == x1, y1 and an image of 50x50  
+
+               // should get back the same x/y offset == x1, y1 and an image of 50x50
                $params = get_image_resize_parameters($orig_width, $orig_height, $options);
-               
+
                $this->assertEqual($params['newwidth'], $options['maxwidth']);
                $this->assertEqual($params['newheight'], $options['maxheight']);
                $this->assertEqual($params['xoffset'], $options['x1']);
                $this->assertEqual($params['yoffset'], $options['y1']);
-               
+
                // test against selection < max
                $options = array(
                        'maxwidth' => 50,
                        'maxheight' => 50,
                        'square' => TRUE,
                        'upscale' => FALSE,
-               
+
                        'x1' => 75,
                        'y1' => 125,
                        'x2' => 100,
                        'y2' => 150
                );
-               
+
                // should get back the same x/y offset == x1, y1 and an image of 25x25
                $params = get_image_resize_parameters($orig_width, $orig_height, $options);
-               
+
                $this->assertEqual($params['newwidth'], 25);
                $this->assertEqual($params['newheight'], 25);
                $this->assertEqual($params['xoffset'], $options['x1']);
index fdd408feb535a6659b1ab86f1363d65407cc9df6..ede87386c586213f9194f54979b5d845508c281b 100644 (file)
@@ -296,7 +296,7 @@ function blog_get_page_content_edit($page, $guid = 0, $revision = NULL) {
                        $title .= ": \"$blog->title\"";
 
                        if ($revision) {
-                               $revision = get_annotation((int)$revision);
+                               $revision = elgg_get_annotation_from_id((int)$revision);
                                $vars['revision'] = $revision;
                                $title .= ' ' . elgg_echo('blog:edit_revision_notice');
 
index 6e72c201eee11cc9b2a64dd02e886689ddbe6000..1cc20f285080eec539856cd21dd586a25c1698bf 100644 (file)
@@ -10,7 +10,7 @@
 $annotation_id = (int) get_input('annotation_id');
 
 //make sure that there is a message on the message board matching the passed id
-if ($message = get_annotation($annotation_id)) {
+if ($message = elgg_get_annotation_from_id($annotation_id)) {
 
        //grab the user or group entity
        $entity = get_entity($message->entity_guid);
index 1945bb8afe27fbc3bcec59b08ecf7586a9cf009e..1537e035511846f80824221f77231ccc6451c90c 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 $id = get_input('id');
-$annotation = get_annotation($id);
+$annotation = elgg_get_annotation_from_id($id);
 if (!$annotation) {
        forward();
 }