diff options
Diffstat (limited to 'engine')
-rw-r--r-- | engine/classes/ElggAnnotation.php | 4 | ||||
-rw-r--r-- | engine/classes/ElggEntity.php | 10 | ||||
-rw-r--r-- | engine/classes/ElggRiverItem.php | 2 | ||||
-rw-r--r-- | engine/handlers/export_handler.php | 2 | ||||
-rw-r--r-- | engine/lib/annotations.php | 26 | ||||
-rw-r--r-- | engine/lib/metadata.php | 16 | ||||
-rw-r--r-- | engine/lib/metastrings.php | 9 | ||||
-rw-r--r-- | engine/tests/api/entity_getter_functions.php | 4 | ||||
-rw-r--r-- | engine/tests/api/metastrings.php | 4 | ||||
-rw-r--r-- | engine/tests/regression/trac_bugs.php | 34 |
10 files changed, 70 insertions, 41 deletions
diff --git a/engine/classes/ElggAnnotation.php b/engine/classes/ElggAnnotation.php index 274cbb923..f61ea520d 100644 --- a/engine/classes/ElggAnnotation.php +++ b/engine/classes/ElggAnnotation.php @@ -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); } } diff --git a/engine/classes/ElggEntity.php b/engine/classes/ElggEntity.php index 3dc5088f5..1be1d5d15 100644 --- a/engine/classes/ElggEntity.php +++ b/engine/classes/ElggEntity.php @@ -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); diff --git a/engine/classes/ElggRiverItem.php b/engine/classes/ElggRiverItem.php index 6ff9b01d1..cdb22239d 100644 --- a/engine/classes/ElggRiverItem.php +++ b/engine/classes/ElggRiverItem.php @@ -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); } /** diff --git a/engine/handlers/export_handler.php b/engine/handlers/export_handler.php index b56a20b93..b91a037e8 100644 --- a/engine/handlers/export_handler.php +++ b/engine/handlers/export_handler.php @@ -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); diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php index c37596ea8..0235476f2 100644 --- a/engine/lib/annotations.php +++ b/engine/lib/annotations.php @@ -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; diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php index 08c87ae67..c05e0b161 100644 --- a/engine/lib/metadata.php +++ b/engine/lib/metadata.php @@ -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(); } /** diff --git a/engine/lib/metastrings.php b/engine/lib/metastrings.php index 6376ac09b..8c702239b 100644 --- a/engine/lib/metastrings.php +++ b/engine/lib/metastrings.php @@ -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) { diff --git a/engine/tests/api/entity_getter_functions.php b/engine/tests/api/entity_getter_functions.php index e3e265d21..1633cbe19 100644 --- a/engine/tests/api/entity_getter_functions.php +++ b/engine/tests/api/entity_getter_functions.php @@ -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) { diff --git a/engine/tests/api/metastrings.php b/engine/tests/api/metastrings.php index 9d089f804..e5cfe80e1 100644 --- a/engine/tests/api/metastrings.php +++ b/engine/tests/api/metastrings.php @@ -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); } diff --git a/engine/tests/regression/trac_bugs.php b/engine/tests/regression/trac_bugs.php index 93831fd7e..71aae3d34 100644 --- a/engine/tests/regression/trac_bugs.php +++ b/engine/tests/regression/trac_bugs.php @@ -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']); |