Changeset 16086

Show
Ignore:
Timestamp:
04/15/08 13:32:34 (6 months ago)
Author:
rambo
Message:

minor refactoring, added some todos, snippet tree now by default require approvals

Files:

Legend:

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

    r15913 r16086  
    77    'midgard_style', 
    88    'midgard_element', // Style-elements 
     9    'midgard_snippetdir', 
     10    'midgard_snippet', 
    911), 
    1012'exporter_staging2live_typefilter_pass_types' => array 
  • branches/MidCOM_2_8/midcom.helper.replicator/exporter/staging2live.php

    r15913 r16086  
    224224            && !empty($object->up)) 
    225225        { 
    226             // Child articles don't currently have any approval UI, skip approval 
    227             $GLOBALS['midcom_helper_replicator_logger']->log_object($object, 'Child article, no approval checks to be made'); 
     226            // Child articles don't currently have any approval UI, skip approval for them (but do check parent below) 
     227            $GLOBALS['midcom_helper_replicator_logger']->log_object($object, 'Child article, not checking approval status'); 
    228228            $this->exportability[$object->guid] = true; 
    229             debug_pop(); 
    230             return; 
    231229        } 
    232230        elseif ($object->metadata->revised > $object->metadata->approved) 
     
    248246                if (!$this->exportability[$object->guid]) 
    249247                { 
     248                    // TODO: Uimessage, but how to give only one ?? 
    250249                    $GLOBALS['midcom_helper_replicator_logger']->log_object($object, 'Parent not approved, skipping'); 
    251250                } 
  • branches/MidCOM_2_8/midcom.helper.replicator/queuemanager.php

    r15780 r16086  
    1717    var $started = 0; 
    1818    /** 
    19      * @todo this should be per-subscription 
    20      */ 
    21     var $file_count = 0
     19     * file counts keyed by subscription guid 
     20     */ 
     21    var $file_counts = array()
    2222 
    2323    /** 
     
    132132                continue; 
    133133            } 
    134             $i =& $this->file_count; 
     134            if (   !isset($this->file_counts[$subscription->guid]) 
     135                || !is_array($this->file_counts[$subscription->guid])) 
     136            { 
     137                $this->file_counts[$subscription->guid] = array(); 
     138            } 
     139            $i =& $this->file_counts[$subscription->guid]; 
    135140            debug_add('about to queue ' . count($exporter_serializations) . ' keys'); 
    136141            reset($exporter_serializations); 
     
    253258            debug_pop(); 
    254259        } 
     260 
     261        // Append sitegroup name 
     262        $sitegroup_base = "{$global_base}/" . $this->safe_sg_name($subscription->sitegroup); 
     263        if (!is_dir($sitegroup_base)) 
     264        { 
     265            // The configuration key might have dynamic part to it 
     266            debug_push_class(__CLASS__, __FUNCTION__);     
     267            debug_add("directory {$sitegroup_base} does not exist, creating", MIDCOM_LOG_DEBUG); 
     268            if (!mkdir($sitegroup_base)) 
     269            { 
     270                // TODO: Error reporting 
     271                debug_add("could not create directory {$sitegroup_base}", MIDCOM_LOG_ERROR); 
     272                debug_pop(); 
     273                return false; 
     274            } 
     275            debug_pop(); 
     276        } 
     277 
     278        $subscription_path = "{$sitegroup_base}/{$subscription->guid}"; 
     279        if (!is_dir($subscription_path)) 
     280        { 
     281            debug_push_class(__CLASS__, __FUNCTION__);     
     282            debug_add("directory {$subscription_path} does not exist, creating", MIDCOM_LOG_DEBUG); 
     283            if (!mkdir($subscription_path)) 
     284            { 
     285                // TODO: Error reporting 
     286                debug_add("could not create directory {$subscription_path}", MIDCOM_LOG_ERROR); 
     287                debug_pop(); 
     288                return false; 
     289            } 
     290            debug_pop(); 
     291        } 
     292        return $subscription_path; 
     293    } 
     294 
     295    function _get_subscription_quarantine_basedir(&$subscription) 
     296    { 
     297        $global_base = $this->_config->get('queue_root_dir'); 
     298        if (!is_dir($global_base)) 
     299        { 
     300            // The configuration key might have dynamic part to it 
     301            debug_push_class(__CLASS__, __FUNCTION__);     
     302            debug_add("directory {$global_base} does not exist, creating", MIDCOM_LOG_DEBUG); 
     303            if (!mkdir($global_base)) 
     304            { 
     305                // TODO: Error reporting 
     306                debug_add("could not create directory {$global_base}", MIDCOM_LOG_ERROR); 
     307                debug_pop(); 
     308                return false; 
     309            } 
     310            debug_pop(); 
     311        } 
    255312         
    256313        // Append sitegroup name 
     
    269326            } 
    270327            debug_pop(); 
    271         } 
    272          
    273         $subscription_path = "{$sitegroup_base}/{$subscription->guid}"; 
     328        }         
     329        $subscription_path = "{$sitegroup_base}/{$subscription->guid}-quarantine"; 
    274330        if (!is_dir($subscription_path)) 
    275331        { 
     
    288344    } 
    289345 
    290     function _get_subscription_quarantine_basedir(&$subscription) 
    291     { 
    292         $global_base = $this->_config->get('queue_root_dir'); 
    293         if (!is_dir($global_base)) 
    294         { 
    295             // The configuration key might have dynamic part to it 
    296             debug_push_class(__CLASS__, __FUNCTION__);     
    297             debug_add("directory {$global_base} does not exist, creating", MIDCOM_LOG_DEBUG); 
    298             if (!mkdir($global_base)) 
    299             { 
    300                 // TODO: Error reporting 
    301                 debug_add("could not create directory {$global_base}", MIDCOM_LOG_ERROR); 
    302                 debug_pop(); 
    303                 return false; 
    304             } 
    305             debug_pop(); 
    306         } 
    307          
    308         // Append sitegroup name 
    309         $sitegroup_base = "{$global_base}/" . $this->safe_sg_name($subscription->sitegroup); 
    310         if (!is_dir($sitegroup_base)) 
    311         { 
    312             // The configuration key might have dynamic part to it 
    313             debug_push_class(__CLASS__, __FUNCTION__);     
    314             debug_add("directory {$sitegroup_base} does not exist, creating", MIDCOM_LOG_DEBUG); 
    315             if (!mkdir($sitegroup_base)) 
    316             { 
    317                 // TODO: Error reporting 
    318                 debug_add("could not create directory {$sitegroup_base}", MIDCOM_LOG_ERROR); 
    319                 debug_pop(); 
    320                 return false; 
    321             } 
    322             debug_pop(); 
    323         }         
    324         $subscription_path = "{$sitegroup_base}/{$subscription->guid}-quarantine"; 
    325         if (!is_dir($subscription_path)) 
    326         { 
    327             debug_push_class(__CLASS__, __FUNCTION__);     
    328             debug_add("directory {$subscription_path} does not exist, creating", MIDCOM_LOG_DEBUG); 
    329             if (!mkdir($subscription_path)) 
    330             { 
    331                 // TODO: Error reporting 
    332                 debug_add("could not create directory {$subscription_path}", MIDCOM_LOG_ERROR); 
    333                 debug_pop(); 
    334                 return false; 
    335             } 
    336             debug_pop(); 
    337         } 
    338         return $subscription_path; 
    339     } 
    340  
    341346    function _get_subscription_quarantine_queuedir(&$subscription) 
    342347    { 
     
    416421 
    417422    /** 
    418      * Helper for process_queue, quarantines failed items 
     423     * Helper for process_queue, moves quarantined items to correct directory 
     424     */ 
     425    function _quarantine_items(&$q_items, &$items_paths, &$subscription) 
     426    { 
     427        if (!is_array($q_items)) 
     428        { 
     429            return false; 
     430        } 
     431        if (empty($q_items)) 
     432        { 
     433            return true; 
     434        } 
     435        $quarantine_path = $this->_get_subscription_quarantine_queuedir($subscription); 
     436        if (!is_dir($quarantine_path)) 
     437        { 
     438            // Could not get valid dir 
     439            return false; 
     440        } 
     441        foreach ($q_items as $item_key => $item_path) 
     442        { 
     443            // Reset time limit counter while processing files 
     444            set_time_limit(30); 
     445            $quarantine_filepath = $quarantine_path . '/' . basename($item_path); 
     446            debug_add("Quarantineing '{$item_key}' as '{$quarantine_filepath}'", MIDCOM_LOG_DEBUG); 
     447            $output = array(); 
     448            $code = 0; 
     449            exec("mv {$item_path} {$quarantine_filepath}", $output, $code); 
     450            if ($code != 0) 
     451            { 
     452                debug_add("Failed to quarantine '{$item_path}' as '{$quarantine_filepath}'", MIDCOM_LOG_ERROR); 
     453                continue; 
     454            } 
     455 
     456            // TODO: write per-item error if available to some index file. 
     457 
     458            unset($q_items[$item_key], $items_paths[$item_key]); 
     459        } 
     460        return true; 
     461    } 
     462 
     463 
     464    /** 
     465     * Helper for process_queue, removes processed items, quarantines failed ones 
    419466     */ 
    420467    function _process_queue_quarantines(&$items, &$items_paths, &$subscription) 
    421468    { 
    422469        debug_push_class(__CLASS__, __FUNCTION__); 
     470        $q_items = array(); 
    423471        foreach ($items_paths as $item_key => $item_path) 
    424472        { 
     
    428476            { 
    429477                // Item still in array (transporter should remove each key as it's transported properly) 
    430                 debug_add("Transporter left key '{$item_key}' into items, quarantineing '{$item_path}'", MIDCOM_LOG_INFO); 
    431                 $quarantine_path = $this->_get_subscription_quarantine_queuedir($subscription); 
    432                 if (!is_dir($quarantine_path)) 
    433                 { 
    434                     // Could not get valid dir 
    435                     continue; 
    436                 } 
    437                 $quarantine_filepath = $quarantine_path . '/' . basename($item_path); 
    438                 $output = array(); 
    439                 $code = 0; 
    440                 exec("mv {$item_path} {$quarantine_filepath}", $output, $code); 
    441                 if ($code != 0) 
    442                 { 
    443                     debug_add("Failed to quarantine '{$item_path}' as '{$quarantine_filepath}'", MIDCOM_LOG_ERROR); 
    444                 } 
    445                 else 
    446                 { 
    447                     debug_add("Quarantined '{$item_path}' as '{$quarantine_filepath}'", MIDCOM_LOG_INFO); 
    448                 } 
    449                 // TODO: create notice 
     478                debug_add("Transporter left key '{$item_key}' into items, marking for quarantineing", MIDCOM_LOG_INFO); 
     479                $q_items[$item_key] = $item_path; 
    450480                continue; 
    451481            } 
     
    456486            } 
    457487            $GLOBALS['midcom_helper_replicator_logger']->log("File {$item_path} removed from queue \"{$subscription->title}\""); 
    458         } 
     488            unset($items_paths[$item_key]); 
     489        } 
     490        $this->_quarantine_items(&$q_items, &$items_paths, &$subscription); 
     491        unset($q_items); 
    459492        // Restore to original value 
    460493        set_time_limit(ini_get('max_execution_time')); 
  • branches/MidCOM_2_8/midcom.helper.replicator/transporter.php

    r15780 r16086  
    2222 
    2323    /** 
    24      * Possible processing error
     24     * Possible processing error (single message)
    2525     * 
    2626     * @var string 
    27      * @access protected 
     27     * @access read-only 
    2828     */ 
    2929    var $error = ''; 
     30 
     31    /** 
     32     * Possible processing errors (per key) 
     33     * 
     34     * @var string 
     35     * @access read-only 
     36     */ 
     37    var $item_errors = array(); 
    3038 
    3139    /** 
  • branches/MidCOM_2_8/midcom.helper.replicator/transporter/http.php

    r15544 r16086  
    142142 
    143143        // Log the failure details 
     144        $this->item_errors[$key] = $error_string; 
    144145        $msg = "Failed to send key {$key}, error: {$error_string}"; 
     146        // PONDER: use the replicator log instead ? 
    145147        debug_push_class(__CLASS__, __FUNCTION__); 
    146148        debug_add($msg, MIDCOM_LOG_WARN); 
     
    167169                 continue; 
    168170            } 
    169             $GLOBALS['midcom_helper_replicator_logger']->log("Succesfully sent key {$key}", MIDCOM_LOG_INFO); 
     171            $GLOBALS['midcom_helper_replicator_logger']->log("Succesfully sent key {$key}", MIDCOM_LOG_DEBUG); 
    170172            unset($items[$key]); 
     173            if (isset($this->item_errors[$key])) 
     174            { 
     175                unset($this->item_errors[$key]); 
     176            } 
    171177        } 
    172178        unset($key, $data);