Changeset 16096

Show
Ignore:
Timestamp:
04/15/08 16:29:18 (4 months ago)
Author:
rambo
Message:

saner logging, better log pretty-printing, button to re-queue object for replication

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/MidCOM_2_8/midcom.helper.replicator/config/config.inc

    r16086 r16096  
    1 'queue_root_dir' => '/var/spool/midgard/replicator_queue/', 
     1'queue_root_dir' => '/var/spool/midgard/replicator_queue//', 
    22'log_filename'   => "{$GLOBALS['midcom_config']['log_filename']}.replicator", 
    33'exporter_staging2live_check_approvals_for' => array 
  • branches/MidCOM_2_8/midcom.helper.replicator/exporter/mirror.php

    r15913 r16096  
    3131    function is_exportable_by_metadata(&$object) 
    3232    { 
    33         $GLOBALS['midcom_helper_replicator_logger']->log_object($object, "is_exportable_by_metadata called"); 
     33        //$GLOBALS['midcom_helper_replicator_logger']->log_object($object, "is_exportable_by_metadata called"); 
     34        //TODO: Is there a more graceful way to do this ? (see also manager.php) 
     35        $check_exported = true; 
     36        if (   isset($GLOBALS['midcom_helper_replicator_exporter_retry_mode']) 
     37            && !empty($GLOBALS['midcom_helper_replicator_exporter_retry_mode'])) 
     38        { 
     39            $GLOBALS['midcom_helper_replicator_logger']->log_object($object, "Retry mode, not checking metadata->exported"); 
     40            return true; 
     41        } 
    3442        if (   $object->metadata->deleted 
    3543            || (   isset($this->_serialize_rewrite_to_delete[$object->guid]) 
     
    7482        { 
    7583            // This has been exported already 
    76             $GLOBALS['midcom_helper_replicator_logger']->log_object($object, "has alrady been exported ({$exported_unixtime} >= {$revised_unixtime}), returning false", MIDCOM_LOG_INFO); 
     84            $GLOBALS['midcom_helper_replicator_logger']->log_object($object, "has alrady been exported", MIDCOM_LOG_INFO); 
    7785            return false; 
    7886        } 
  • branches/MidCOM_2_8/midcom.helper.replicator/exporter/staging2live.php

    r16092 r16096  
    4343 
    4444    /** 
    45      * This is the main entry point of the exporter. Since we're mirroring 
    46      * all content this will always return true. 
     45     * This is the main entry point of the exporter, we'll do some approval and scheduling checks 
    4746     * 
    4847     * @param midgard_object $object The Object to export parameters of 
     48     * @param boolean $check_exported check if the object has already been exported or not 
    4949     * @return boolean Whether the object may be exported with this exporter 
     50     * @todo log the debug messages to generic debug log and log only more informative reasons to object replication log 
    5051     */ 
    5152    function is_exportable(&$object, $check_exported = true) 
     
    8586        { 
    8687            // CAVEAT: may cause issues with multiple subscriptions 
    87             $GLOBALS['midcom_helper_replicator_logger']->log_object($object, "BEFORE is_exportable_by_metadata check: exportability = " . (int)$this->exportability[$object->guid]); 
     88            //$GLOBALS['midcom_helper_replicator_logger']->log_object($object, "BEFORE is_exportable_by_metadata check: exportability = " . (int)$this->exportability[$object->guid]); 
    8889            $this->exportability[$object->guid] = parent::is_exportable_by_metadata(&$object); 
    89             $GLOBALS['midcom_helper_replicator_logger']->log_object($object, "AFTER is_exportable_by_metadata check: exportability = " . (int)$this->exportability[$object->guid]); 
     90            //$GLOBALS['midcom_helper_replicator_logger']->log_object($object, "AFTER is_exportable_by_metadata check: exportability = " . (int)$this->exportability[$object->guid]); 
    9091        } 
    9192 
    9293        // Approvals checks 
    93         $GLOBALS['midcom_helper_replicator_logger']->log_object($object, "BEFORE approval check: exportability = " . (int)$this->exportability[$object->guid]); 
     94        //$GLOBALS['midcom_helper_replicator_logger']->log_object($object, "BEFORE approval check: exportability = " . (int)$this->exportability[$object->guid]); 
    9495        $this->_check_approval($object); 
    95         $GLOBALS['midcom_helper_replicator_logger']->log_object($object, "AFTER approval check: exportability = " . (int)$this->exportability[$object->guid]); 
     96        //$GLOBALS['midcom_helper_replicator_logger']->log_object($object, "AFTER approval check: exportability = " . (int)$this->exportability[$object->guid]); 
    9697 
    9798        /** 
     
    135136            } 
    136137        } 
    137         $GLOBALS['midcom_helper_replicator_logger']->log_object($object, "BEFORE schedule check: \$schedule_action = {$schedule_action}, exportability = " . (int)$this->exportability[$object->guid]); 
     138        //$GLOBALS['midcom_helper_replicator_logger']->log_object($object, "BEFORE schedule check: \$schedule_action = {$schedule_action}, exportability = " . (int)$this->exportability[$object->guid]); 
    138139        switch ($schedule_action) 
    139140        { 
     
    175176                break; 
    176177        } 
    177         $GLOBALS['midcom_helper_replicator_logger']->log_object($object, "AFTER schedule check: exportability = " . (int)$this->exportability[$object->guid]); 
    178  
    179         $GLOBALS['midcom_helper_replicator_logger']->log_object($object, "is_exportable checks done, returning " . (int)$this->exportability[$object->guid]); 
     178        //$GLOBALS['midcom_helper_replicator_logger']->log_object($object, "AFTER schedule check: exportability = " . (int)$this->exportability[$object->guid]); 
     179 
     180        //$GLOBALS['midcom_helper_replicator_logger']->log_object($object, "is_exportable checks done, returning " . (int)$this->exportability[$object->guid]); 
    180181        $GLOBALS['midcom_helper_replicator_logger']->pop_prefix(); 
    181182        return $this->exportability[$object->guid]; 
     
    187188        debug_push_class(__CLASS__, __FUNCTION__); 
    188189        debug_add("Called for {$object->guid}"); 
    189         $GLOBALS['midcom_helper_replicator_logger']->log_object($object, "_check_approval called"); 
     190        //$GLOBALS['midcom_helper_replicator_logger']->log_object($object, "_check_approval called"); 
    190191 
    191192        // Do not check approvals for deletes 
     
    196197            $msg = 'Object is deleted, do not check approvals, setting exportability explicitly to true'; 
    197198            $this->exportability[$object->guid] = true; 
    198             $GLOBALS['midcom_helper_replicator_logger']->log_object($object, $msg); 
     199            $GLOBALS['midcom_helper_replicator_logger']->log_object($object, $msg, MIDCOM_LOG_INFO); 
    199200            debug_add($msg); 
    200201            debug_pop(); 
     
    226227        { 
    227228            // Child articles don't currently have any approval UI, skip approval for them (but do check parent below) 
    228             $GLOBALS['midcom_helper_replicator_logger']->log_object($object, 'Child article, not checking approval status'); 
     229            $GLOBALS['midcom_helper_replicator_logger']->log_object($object, 'Reply article, not checking approval status', MIDCOM_LOG_INFO); 
    229230            $this->exportability[$object->guid] = true; 
    230231        } 
     
    233234            // FIXME: use metadata service (?) 
    234235            // Not approved since last update 
    235             $GLOBALS['midcom_helper_replicator_logger']->log_object($object, 'Not approved, skipping'); 
     236            $GLOBALS['midcom_helper_replicator_logger']->log_object($object, 'Object could not be exported for replication because it\'s not approved', MIDCOM_LOG_WARN); 
    236237            $this->exportability[$object->guid] = false; 
    237238        } 
     
    250251                if (!$this->exportability[$object->guid]) 
    251252                { 
    252                     $GLOBALS['midcom_helper_replicator_logger']->log_object($object, 'Parent not approved, skipping'); 
     253                    //$GLOBALS['midcom_helper_replicator_logger']->log_object($object, 'Parent not approved, skipping'); 
    253254                    if (empty($parent_check_stack)) 
    254255                    { 
    255256                        // Empty stack means we're  not inside parent recursion, thus we can raise an UIMessage 
    256                         $_MIDCOM->load_library('midcom.helper.reflector'); 
    257257                        $ref = new midcom_helper_reflector($object); 
    258258                        $_MIDCOM->uimessages->add 
     
    267267                            'warning' 
    268268                        ); 
     269                        unset($ref); 
     270                        $GLOBALS['midcom_helper_replicator_logger']->log_object($object, 'Object could not be exported for replication because one of its parents is not approved', MIDCOM_LOG_WARN); 
    269271                    } 
    270272                } 
  • branches/MidCOM_2_8/midcom.helper.replicator/logger.php

    r14775 r16096  
    77* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License 
    88*/ 
     9 
     10$_MIDCOM->load_library('midcom.helper.reflector'); 
    911 
    1012/** 
     
    1820    } 
    1921 
    20     function _resolve_object_title($object
     22    function log_object(&$object, $action, $loglevel = MIDCOM_LOG_DEBUG
    2123    { 
    22         $vars = get_object_vars($object); 
    23          
    24         if (is_a($object, 'midgard_parameter')) 
    25         { 
    26             return "{$object->domain}/{$object->name}"; 
    27         } 
    28         elseif (is_a($object, 'midgard_topic')) 
    29         { 
    30             return $object->extra; 
    31         } 
    32         elseif (   array_key_exists('title', $vars) 
    33             && !empty($object->title)) 
    34         { 
    35             return $object->title; 
    36         }  
    37         elseif (   array_key_exists('name', $vars) 
    38                 && !empty($object->name))  
    39         { 
    40             return $object->name; 
    41         } 
    42         else 
    43         { 
    44             return "#{$object->id}"; 
    45         } 
    46     }   
    47      
    48     function log_object($object, $action, $loglevel = MIDCOM_LOG_DEBUG) 
    49     { 
     24        $ref = new midcom_helper_reflector($object); 
    5025        $message = $action; 
    5126        $message .= " {$object->guid}"; 
    52         $message .= ', ' . get_class($object); 
    53         $message .= ' "' . $this->_resolve_object_title($object) . '"'; 
     27        $message .= ', ' . $ref->get_class_label(); 
     28        $message .= ' "' . $ref->get_object_label($object) . '"'; 
     29        unset($ref); 
    5430         
    5531        $this->log($message, $loglevel); 
  • branches/MidCOM_2_8/midcom.helper.replicator/manager.php

    r16080 r16096  
    439439        } 
    440440 
     441        if (isset($_POST['midcom_helper_replicator_requeue'])) 
     442        { 
     443            $qmanager =& midcom_helper_replicator_queuemanager::get(); 
     444            //TODO: Is there a more graceful way to do this ? (see also mirror.php) 
     445            $GLOBALS['midcom_helper_replicator_exporter_retry_mode'] = true; 
     446            if (!$qmanager->add_to_queue($data['object'])) 
     447            { 
     448                $_MIDCOM->uimessages->add 
     449                ( 
     450                    $this->_l10n->get('midcom.helper.replicator'), 
     451                    $this->_l10n->get('re-queuing failed'),  
     452                    'warning' 
     453                ); 
     454            } 
     455            unset($GLOBALS['midcom_helper_replicator_exporter_retry_mode']); 
     456        } 
    441457 
    442458        if ($bind_toolbar) 
     
    460476        ); 
    461477 
     478        $data['queue_root_dir'] = preg_replace('%/{2,}|/$%', '', $this->_local_config->get('queue_root_dir')); 
     479 
    462480        return true; 
    463481    } 
  • branches/MidCOM_2_8/midcom.helper.replicator/queuemanager.php

    r16086 r16096  
    133133            } 
    134134            if (   !isset($this->file_counts[$subscription->guid]) 
    135                 || !is_array($this->file_counts[$subscription->guid])) 
    136             { 
    137                 $this->file_counts[$subscription->guid] = array()
     135                || !is_numeric($this->file_counts[$subscription->guid])) 
     136            { 
     137                $this->file_counts[$subscription->guid] = 1
    138138            } 
    139139            $i =& $this->file_counts[$subscription->guid]; 
     
    198198 
    199199                unset($key, $data); 
    200                 $i++
     200                ++$i
    201201            } 
    202202            unset($exporter_serializations); 
     
    243243    function _get_subscription_basedir(&$subscription) 
    244244    { 
    245         $global_base = $this->_config->get('queue_root_dir'); 
     245        // Normalize basedir, no trailing slash and no consecutive slashes 
     246        $global_base = preg_replace('%/{2,}|/$%', '', $this->_config->get('queue_root_dir')); 
    246247        if (!is_dir($global_base)) 
    247248        { 
  • branches/MidCOM_2_8/midcom.helper.replicator/style/midcom-helper-replicator-object.php

    r5757 r16096  
    2929        <td>&(exported);</td> 
    3030    </tr> 
     31    <tr> 
     32        <td colspan=2> 
     33            <form method="post" class="midcom_helper_replicator_requeue_form"> 
     34                <input type="submit" class="button" name="midcom_helper_replicator_requeue" value="<?php echo $_MIDCOM->i18n->get_string('re-queue object', 'midcom.helper.replicator'); ?>" /> 
     35            </form> 
     36        </td> 
     37    </tr> 
    3138</table> 
    3239 
     
    3744exec("grep '{$data['object']->guid}' '{$GLOBALS['midcom_helper_replicator_logger']->_filename}'", $output); 
    3845 
     46$path_regex = "%{$data['queue_root_dir']}.*?/[0-9a-f]{32,80}(-quarantine)?/[0-9]+/%"; 
    3947echo "<ul class=\"midcom_helper_replicator_object\">\n"; 
    4048foreach ($output as $line) 
     
    5563    $component = str_replace('midcom_helper_replicator_importer', 'importer', str_replace('Queue Manager', 'queuemanager', $item_component)); 
    5664    $message = str_replace($data['object']->guid, "<abbr title=\"{$data['object']->guid}\">&lt;GUID&gt;</abbr>", $item_content); 
     65    $message = preg_replace($path_regex, '<abbr title="\\0">&lt;PATH&gt;</abbr>/', $message); 
    5766     
    5867    echo "<li class=\"{$item_class} {$component}\">";