From 0fe0f9d6dc6577d39bf0615c0e714c7fa7d2ebf3 Mon Sep 17 00:00:00 2001 From: Brett Profitt Date: Mon, 9 Jan 2012 17:29:04 -0800 Subject: Fixes #4243. Added docs for metadata_calculation option to elgg_get_metadata(). --- engine/lib/metastrings.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'engine/lib/metastrings.php') diff --git a/engine/lib/metastrings.php b/engine/lib/metastrings.php index 9fe9b4bff..d8fef6f1c 100644 --- a/engine/lib/metastrings.php +++ b/engine/lib/metastrings.php @@ -609,8 +609,7 @@ function elgg_get_metastring_sql($table, $names = null, $values = null, } /** - * Normalizes metadata / annotation option names to their - * corresponding metastrings name. + * Normalizes metadata / annotation option names to their corresponding metastrings name. * * @param array $options An options array * @since 1.8.0 @@ -631,10 +630,10 @@ function elgg_normalize_metastrings_options(array $options = array()) { // map the metadata_* options to metastring_* options $map = array( - 'names' => 'metastring_names', - 'values' => 'metastring_values', - 'case_sensitive' => 'metastring_case_sensitive', - 'owner_guids' => 'metastring_owner_guids', + 'names' => 'metastring_names', + 'values' => 'metastring_values', + 'case_sensitive' => 'metastring_case_sensitive', + 'owner_guids' => 'metastring_owner_guids', 'created_time_lower' => 'metastring_created_time_lower', 'created_time_upper' => 'metastring_created_time_upper', 'calculation' => 'metastring_calculation', -- cgit v1.2.3 From a3f0353600e749a16abbdab3cbc75b3469d6fd69 Mon Sep 17 00:00:00 2001 From: Brett Profitt Date: Tue, 10 Jan 2012 16:54:49 -0800 Subject: Fixes #4269. Not using ElggBatch to delete metadata / annotations. Added unit tests for deleting annotations/md. Fixed an annoying inconsistency with "metastring/s" option in private functions. --- engine/lib/annotations.php | 2 +- engine/lib/metadata.php | 2 +- engine/lib/metastrings.php | 32 ++++++++++++++++++++++++++++++-- engine/tests/api/annotations.php | 24 ++++++++++++++++++++++++ engine/tests/api/metadata.php | 25 +++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 4 deletions(-) (limited to 'engine/lib/metastrings.php') diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php index 7eb72612f..5049d455b 100644 --- a/engine/lib/annotations.php +++ b/engine/lib/annotations.php @@ -237,7 +237,7 @@ function elgg_disable_annotations(array $options) { return false; } - $options['metastrings_type'] = 'annotations'; + $options['metastring_type'] = 'annotations'; return elgg_batch_metastring_based_objects($options, 'elgg_batch_disable_callback'); } diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php index a097cd3ef..19e8aa3c8 100644 --- a/engine/lib/metadata.php +++ b/engine/lib/metadata.php @@ -324,7 +324,7 @@ function elgg_disable_metadata(array $options) { return false; } - $options['metastrings_type'] = 'metadata'; + $options['metastring_type'] = 'metadata'; return elgg_batch_metastring_based_objects($options, 'elgg_batch_disable_callback'); } diff --git a/engine/lib/metastrings.php b/engine/lib/metastrings.php index d8fef6f1c..62b60e279 100644 --- a/engine/lib/metastrings.php +++ b/engine/lib/metastrings.php @@ -727,10 +727,38 @@ function elgg_batch_metastring_based_objects(array $options, $callback) { return false; } - $batch = new ElggBatch('elgg_get_metastring_based_objects', $options, $callback); - $r = $batch->callbackResult; + switch($options['metastring_type']) { + case 'metadata': + $objects = elgg_get_metadata($options); + break; + + case 'annotations': + $objects = elgg_get_annotations($options); + break; + + default: + return false; + } + + if (!is_array($objects)) { + $r = false; + } elseif (empty($objects)) { + // ElggBatch returns null if the results are an empty array + $r = null; + } else { + $r = true; + foreach($objects as $object) { + $r = $r && $callback($object); + } + } return $r; + +// // @todo restore once ElggBatch supports callbacks that delete rows. +// $batch = new ElggBatch('elgg_get_metastring_based_objects', $options, $callback); +// $r = $batch->callbackResult; +// +// return $r; } /** diff --git a/engine/tests/api/annotations.php b/engine/tests/api/annotations.php index d7551a0fa..947292970 100644 --- a/engine/tests/api/annotations.php +++ b/engine/tests/api/annotations.php @@ -43,4 +43,28 @@ class ElggCoreAnnotationAPITest extends ElggCoreUnitTest { $this->object->delete(); } + + public function testElggDeleteAnnotations() { + $e = new ElggObject(); + $e->save(); + + for ($i=0; $i<30; $i++) { + $e->annotate('test_annotation', rand(0,10000)); + } + + $options = array( + 'guid' => $e->getGUID(), + 'limit' => 0 + ); + + $annotations = elgg_get_annotations($options); + $this->assertIdentical(30, count($annotations)); + + $this->assertTrue(elgg_delete_annotations($options)); + + $annotations = elgg_get_annotations($options); + $this->assertTrue(empty($annotations)); + + $this->assertTrue($e->delete()); + } } diff --git a/engine/tests/api/metadata.php b/engine/tests/api/metadata.php index f5b615ca8..be8ac269c 100644 --- a/engine/tests/api/metadata.php +++ b/engine/tests/api/metadata.php @@ -99,6 +99,31 @@ class ElggCoreMetadataAPITest extends ElggCoreUnitTest { $this->object->delete(); } + public function testElggDeleteMetadata() { + $e = new ElggObject(); + $e->save(); + + for ($i=0; $i<30; $i++) { + $name = "test_metadata" . rand(0, 10000); + $e->$name = rand(0, 10000); + } + + $options = array( + 'guid' => $e->getGUID(), + 'limit' => 0 + ); + + $md = elgg_get_metadata($options); + $this->assertIdentical(30, count($md)); + + $this->assertTrue(elgg_delete_metadata($options)); + + $md = elgg_get_metadata($options); + $this->assertTrue(empty($md)); + + $e->delete(); + } + protected function create_metastring($string) { global $CONFIG, $METASTRINGS_CACHE, $METASTRINGS_DEADNAME_CACHE; -- cgit v1.2.3