]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixed a problem with the annotation batch operation test.
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Thu, 21 Apr 2011 19:36:47 +0000 (19:36 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Thu, 21 Apr 2011 19:36:47 +0000 (19:36 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@9009 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/annotations.php
engine/lib/elgglib.php
engine/lib/metastrings.php
engine/tests/api/metastrings.php

index 7a4e62921297ab4207306ae279aae65d5ed9f3f2..ca8f6b2e182482503be864474148220f5ce57a86 100644 (file)
@@ -404,6 +404,7 @@ function elgg_list_entities_from_annotations($options = array()) {
  * @return mixed
  */
 function elgg_get_entities_from_annotation_calculation($options) {
+       $db_prefix = elgg_get_config('dbprefix');
        $defaults = array(
                'calculation' => 'sum',
                'order_by' => 'calculation desc'
@@ -415,14 +416,14 @@ function elgg_get_entities_from_annotation_calculation($options) {
 
        // you must cast this as an int or it sorts wrong.
        $options['selects'][] = 'e.*';
-       $options['selects'][] = "$function(cast(v.string as signed)) as calculation";
+//     $options['selects'][] = 'a_msv as value';
+       $options['selects'][] = "$function(cast(a_msv.string as signed)) as calculation";
 
-       // need our own join to get the values.
-//     $options['joins'][] = "JOIN {$db_prefix}metastrings msv ON a.value_id = msv.id";
-//     $options['joins'][] = "JOIN {$db_prefix}entities ae ON a.entity_guid = ae.guid";
+       // need our own join to get the values because the lower level functions don't
+       // add all the joins if it's a different callback.
+       $options['joins'][] = "JOIN {$db_prefix}metastrings a_msv ON n_table.value_id = a_msv.id";
 
-       $options['wheres'][] = get_access_sql_suffix('n_table');
-//     $options['wheres'][] = "e.guid = a.entity_guid";
+       // don't need access control because it's taken care of by elgg_get_annotations.
        $options['group_by'] = 'n_table.entity_guid';
 
        $options['callback'] = 'entity_row_to_elggstar';
index 6c94133dfae5e1e6a6e47c065a446aa63072a353..e9172d18426b382c752ca7e3f23ad60c74b590b1 100644 (file)
@@ -1623,8 +1623,9 @@ function is_not_null($string) {
  * names by singular names.
  *
  * @param array $options   The options array. $options['keys'] = 'values';
- * @param array $singulars A list of sinular words to pluralize by adding 's'.
+ * @param array $singulars A list of singular words to pluralize by adding 's'.
  *
+ * @access private
  * @return array
  * @since 1.7.0
  */
index 655617ac6c4be4c89108743a9aaac229e89ce403..4dda05e6bfac836108ecb152b1e3f9ccb0c45a8f 100644 (file)
@@ -373,11 +373,24 @@ function elgg_get_metastring_based_objects($options) {
        }
 
        $joins = $options['joins'];
-
        $joins[] = "JOIN {$db_prefix}entities e ON n_table.entity_guid = e.guid";
-       $joins[] = "JOIN {$db_prefix}metastrings n on n_table.name_id = n.id";
-       $joins[] = "JOIN {$db_prefix}metastrings v on n_table.value_id = v.id";
 
+       if (!is_array($options['selects'])) {
+               $options['selects'] = array($options['selects']);
+       }
+
+       $selects = $options['selects'];
+
+       // For performance reasons we don't want the joins required for metadata / annotations
+       // unless we're going through one of their callbacks.
+       // this means we expect the functions passing different callbacks to pass their required joins.
+       if ($options['callback'] == 'row_to_elggmetadata' || $options['callback'] == 'row_to_elggannotation') {
+               $joins[] = "JOIN {$db_prefix}metastrings n on n_table.name_id = n.id";
+               $joins[] = "JOIN {$db_prefix}metastrings v on n_table.value_id = v.id";
+
+               $selects[] = 'n.string as name';
+               $selects[] = 'v.string as value';
+       }
 
        // remove identical join clauses
        $joins = array_unique($joins);
@@ -406,19 +419,19 @@ function elgg_get_metastring_based_objects($options) {
        }
 
        if ($options['metastring_calculation'] === ELGG_ENTITIES_NO_VALUE) {
+               $selects = array_unique($selects);
                // evalutate selects
-               if ($options['selects']) {
-                       $selects = '';
-                       foreach ($options['selects'] as $select) {
-                               $selects .= ", $select";
+               $select_str = '';
+               if ($selects) {
+                       foreach ($selects as $select) {
+                               $select_str .= ", $select";
                        }
-               } else {
-                       $selects = '';
                }
 
-               $query = "SELECT DISTINCT n_table.*, n.string as name,
-                       v.string as value{$selects} FROM {$db_prefix}$type n_table";
+               $query = "SELECT DISTINCT n_table.*{$select_str} FROM {$db_prefix}$type n_table";
        } else {
+               // @todo this will break if you're counting on an annotation calculation because of the joins
+               // that's a dumb thing to do anyway, but it shouldn't make bad queries
                $query = "SELECT {$options['metastring_calculation']}(v.string) as calculation FROM {$db_prefix}$type n_table";
        }
 
index e5cfe80e1fdf31ddcd618626cbb47c34e0c3181c..9b5d7ee4e7f99d325b7ba0e50e11828a2ae46a07 100644 (file)
@@ -164,7 +164,7 @@ class ElggCoreMetastringsTest extends ElggCoreUnitTest {
                        }
 
                        $options = array();
-                       $this->assertFalse(elgg_is_valid_options_for_batch_operation($options), $type);
+                       $this->assertFalse(elgg_is_valid_options_for_batch_operation($options, $type));
 
                        foreach ($required as $key) {
                                $options = array();