Changeset 4967
- Timestamp:
- 01/16/07 15:13:54 (2 years ago)
- Files:
-
- trunk/src/midcom.helper.replicator/exporter.php (modified) (5 diffs)
- trunk/src/midcom.helper.replicator/exporter/mirror.php (modified) (3 diffs)
- trunk/src/midcom.helper.replicator/logger.php (modified) (1 diff)
- trunk/src/midcom.helper.replicator/queuemanager.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/midcom.helper.replicator/exporter.php
r4966 r4967 89 89 90 90 // Serialize blob (TODO: Check if we wish to do so) 91 $attachment_blob_serialized = midgard_replicator::serialize_blob($attachment); 91 //$attachment_blob_serialized = midgard_replicator::serialize_blob($attachment); 92 $attachment_blob_serialized = midgard_replicator::export_blob($attachment); 92 93 if ($attachment_blob_serialized === false) 93 94 { … … 140 141 return false; 141 142 } 143 $GLOBALS['midcom_helper_replicator_logger']->log_object($attachment, 'Exported'); 142 144 $serializations = array_merge($serializations, $attachment_serialized); 143 145 unset($attachment_serialized); … … 174 176 return false; 175 177 } 178 $GLOBALS['midcom_helper_replicator_logger']->log_object($parameter, 'Exported'); 176 179 $serializations[$parameter->guid] = $parameter_serialized; 177 180 unset($parameter_serialized); … … 190 193 * @return array Array of exported objects as XML indexed by GUID 191 194 */ 192 function serialize_object(&$object )195 function serialize_object(&$object, $skip_children = false) 193 196 { 194 197 $serializations = array(); … … 207 210 unset($object_serialized); 208 211 209 // Then objects parameters 210 $object_parameters = $this->serialize_parameters($object); 211 if ($object_parameters === false) 212 { 213 // TODO: Error handling 214 $GLOBALS['midcom_helper_replicator_logger']->pop_prefix(); 215 return false; 216 } 217 $serializations = array_merge($serializations, $object_parameters); 218 unset($object_parameters); 219 220 // And lastly objects attachments 221 $object_attachments = $this->serialize_attachments($object); 222 if ($object_attachments === false) 223 { 224 // TODO: Error handling 225 $GLOBALS['midcom_helper_replicator_logger']->pop_prefix(); 226 return false; 227 } 228 $serializations = array_merge($serializations, $object_attachments); 229 unset($object_attachments); 230 212 if (!$skip_children) 213 { 214 // Then objects parameters 215 $object_parameters = $this->serialize_parameters($object); 216 if ($object_parameters === false) 217 { 218 // TODO: Error handling 219 $GLOBALS['midcom_helper_replicator_logger']->pop_prefix(); 220 return false; 221 } 222 $serializations = array_merge($serializations, $object_parameters); 223 unset($object_parameters); 224 225 // And lastly objects attachments 226 $object_attachments = $this->serialize_attachments($object); 227 if ($object_attachments === false) 228 { 229 // TODO: Error handling 230 $GLOBALS['midcom_helper_replicator_logger']->pop_prefix(); 231 return false; 232 } 233 $serializations = array_merge($serializations, $object_attachments); 234 unset($object_attachments); 235 } 236 231 237 $GLOBALS['midcom_helper_replicator_logger']->pop_prefix(); 232 238 return $serializations; trunk/src/midcom.helper.replicator/exporter/mirror.php
r4955 r4967 137 137 * @return array Array of exported objects as XML indexed by GUID 138 138 */ 139 function serialize_object(&$object )139 function serialize_object(&$object, $skip_children = false) 140 140 { 141 141 if (array_key_exists($object->guid, $this->already_serialized)) … … 149 149 } 150 150 151 // TODO: Decide in which order we want to export parents and dependencies 152 153 $serializations = parent::serialize_object($object); 154 155 $this->already_serialized[$object->guid] = true; 156 157 // Traverse children as needed 158 $child_serializations = $this->serialize_children($object); 159 $serializations = array_merge($serializations, $child_serializations); 160 unset($child_serializations); 151 $serializations = array(); 161 152 162 153 // Traverse parent tree as well … … 164 155 if (is_object($parent)) 165 156 { 166 $parent_serializations = $this->serialize_object($parent); 157 // FIXME: Skipping children is harmful in staging2live situations 158 $parent_serialization = $this->serialize_object($parent, true); 167 159 $serializations = array_merge($serializations, $parent_serialization); 168 160 unset($parent_serialization); 161 } 162 163 $object_serialization = parent::serialize_object($object, $skip_children); 164 $serializations = array_merge($serializations, $object_serialization); 165 unset($object_serialization); 166 167 $this->already_serialized[$object->guid] = true; 168 169 if (!$skip_children) 170 { 171 // Traverse children as needed 172 $child_serializations = $this->serialize_children($object); 173 $serializations = array_merge($serializations, $child_serializations); 174 unset($child_serializations); 169 175 } 170 176 trunk/src/midcom.helper.replicator/logger.php
r4966 r4967 22 22 $vars = get_object_vars($object); 23 23 24 if (array_key_exists('title', $vars)) 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)) 25 34 { 26 35 return $object->title; 27 36 } 28 elseif (array_key_exists('name', $vars)) 37 elseif ( array_key_exists('name', $vars) 38 && !empty($object->name)) 29 39 { 30 40 return $object->name; trunk/src/midcom.helper.replicator/queuemanager.php
r4966 r4967 44 44 function add_to_queue(&$object) 45 45 { 46 $GLOBALS['midcom_helper_replicator_logger']->push_prefix('queuemanager'); 46 47 debug_push_class(__CLASS__, __FUNCTION__); 47 48 $qb = midcom_helper_replicator_subscription_dba::new_query_builder(); … … 70 71 // TODO: error handling 71 72 debug_add('could not get queue dir for subscription', MIDCOM_LOG_ERROR); 73 die("No queue dir"); 72 74 continue; 73 75 } … … 82 84 debug_add("file {$file} already exists", MIDCOM_LOG_ERROR); 83 85 debug_pop(); 86 $GLOBALS['midcom_helper_replicator_logger']->pop_prefix(); 87 die("File {$file} exists!"); 84 88 return false; 85 89 } … … 91 95 unset($exporter_serializations, $key, $data); 92 96 debug_pop(); 97 $GLOBALS['midcom_helper_replicator_logger']->pop_prefix(); 98 die("Couldnt write {$file}"); 93 99 return false; 94 100 } 95 101 fwrite($fp, $data, strlen($data)); 96 102 fclose($fp); 103 104 $GLOBALS['midcom_helper_replicator_logger']->log("Queued {$key} as {$file}"); 97 105 98 106 // TODO: How to call midgard_replicator::export() for all the objects exported ?? (and is this the correct place for that ?) … … 104 112 } 105 113 debug_pop(); 114 $GLOBALS['midcom_helper_replicator_logger']->pop_prefix(); 106 115 } 107 116
