Changeset 17688

Show
Ignore:
Timestamp:
09/25/08 13:24:06 (2 months ago)
Author:
rambo
Message:

fix #223 again (regressed in r17009), keep the old style score vs metadata->score difference, minor cleanup

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/MidCOM_2_8/midcom.admin.folder/handler/order.php

    r17009 r17688  
    6868            { 
    6969                // Set the score reversed: the higher the value, the higher the rank 
    70                 $score = $count - $i; 
     70                $score = (int)$i; 
     71                $score_r = (int)($count - $i); 
    7172 
    7273                // Use the DB Factory to resolve the class and to get the object 
     
    8182                } 
    8283 
    83                 // Get the original approval status 
    84                 $metadata =& midcom_helper_metadata::retrieve($guid); 
     84                // Get the original approval status and update metadata reference 
     85                $metadata =& midcom_helper_metadata::retrieve($object); 
     86                if (!is_object($metadata)) 
     87                { 
     88                    $_MIDCOM->generate_error(MIDCOM_ERRCRIT, "Couild not fetch metadata for object {$guid}"); 
     89                    // This will exit 
     90                } 
     91                // Make sure this is reference to correct direction (from our point of view) 
     92                $metadata->object =& $object; 
     93 
     94                // Get the approval status if metadata object is available 
    8595                $approval_status = false; 
    86  
    87                 // Get the approval status if metadata object is available 
    88                 if (   is_object($metadata) 
    89                     && $metadata->is_approved()) 
     96                if ($metadata->is_approved()) 
    9097                { 
    9198                    $approval_status = true; 
     
    95102                if (isset($object->score)) 
    96103                { 
     104                    /**  
     105                     * Why is article->score opposite of article->medatadata score ??  
     106                     * @see: http://www.midgard-project.org/discussion/developer-forum/using-metadata-score-with-midcom-components/  
     107                     */ 
    97108                    $object->score = $score; 
    98109                } 
    99  
    100                 $object->metadata->score = $score; 
    101  
    102                 // Show an error message on an update failure 
     110                $object->metadata->score = $score_r; 
     111 
     112                /* 
    103113                if (!$object->update()) 
    104                 { 
    105                     // Some heuristics for the update logging 
    106                     if (   isset($object->title) 
    107                         && $object->title) 
    108                     { 
    109                         $title = $object->title; 
    110                     } 
    111                     elseif (isset($object->extra) 
    112                         && $object->extra) 
    113                     { 
    114                         $title = $object->extra; 
    115                     } 
    116                     elseif (isset($object->name) 
    117                         && $object->name) 
    118                     { 
    119                         $title = $object->name; 
    120                     } 
    121                     else 
    122                     { 
    123                         $title = sprintf("{$object->guid} %s", get_class($object)); 
    124                     } 
    125  
     114                $metadata->set() calls update *AND* updates the metadata cache correctly, thus we use that in stead of raw update 
     115                */ 
     116                if (!$metadata->set('score', $object->metadata->score)) 
     117                { 
     118                    // Show an error message on an update failure 
     119                    $_MIDCOM->load_library('midcom.helper.reflector'); 
     120                    $reflector =& midcom_helper_reflector::get($object); 
     121                    $title = $reflector->get_class_label() . ' ' . $reflector->get_object_label($object); 
    126122                    $_MIDCOM->uimessages->add($this->_l10n->get('midcom.admin.folder'), sprintf($this->_l10n->get('failed to update %s due to: %s'), $title, mgd_errstr()), 'error'); 
    127123                    $success = false;