Changeset 4453
- Timestamp:
- 10/23/06 18:21:07 (2 years ago)
- Files:
-
- trunk/support/migrate_26.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/support/migrate_26.php
r4451 r4453 238 238 } 239 239 240 241 240 // Convert DM1 attachment types to DM2 242 241 function mgd_param_domain_replace($obj, $from, $to) 243 242 { 244 243 $params = $obj->listparameters($from); 245 if (!$params)246 {247 return;248 }249 244 while ($params->fetch()) 250 245 { … … 258 253 } 259 254 } 255 function mgd_get_att_parent_guid($obj) 256 { 257 $att = new midgard_attachment(); 258 $att->get_by_id($obj->id); 259 if (isset($att->parentguid)) 260 { 261 // 1.8, life is simple 262 return $att->parentguid; 263 } 264 // not 1.8, try something 265 $class = "midgard_{$att->ptable}"; 266 if (!class_exists($class)) 267 { 268 return false; 269 } 270 $obj = new $class(); 271 $obj->get_by_id($att->pid); 272 if (!$obj->id) 273 { 274 return false; 275 } 276 return $obj->guid; 277 } 260 278 $qb_dm1p = new MidgardQueryBuilder('midgard_parameter'); 261 $qb_dm1p->add_constraint('domain', '=', 'midcom.helper.datamanager.datatype.blob'); 279 $qb_dm1p->begin_group('OR'); 280 $qb_dm1p->add_constraint('domain', '=', 'midcom.helper.datamanager.datatype.blob'); 281 //$qb_dm1p->add_constraint('domain', '=', 'midcom.helper.datamanager.datatype.blob'); 282 $qb_dm1p->end_group(); 262 283 $qb_dm1p->add_constraint('name', '=', 'fieldname'); 263 $qb_dm1p->add_constraint('tablename', '=', ' record_extension');284 $qb_dm1p->add_constraint('tablename', '=', 'blobs'); 264 285 $qb_dm1p->add_order('oid', 'ASC'); 265 286 $att_params = $qb_dm1p->execute(); 287 echo count($att_params) . "\n"; 266 288 $seen_att = array(); 267 289 foreach ($att_params as $param) … … 271 293 continue; 272 294 } 295 /* 273 296 $att = new midgard_attachment(); 274 297 $att->get_by_id($param->oid); 298 */ 299 $att = mgd_get_attachment($param->oid); 275 300 if (!$att->id) 276 301 { … … 278 303 continue; 279 304 } 305 /* 306 echo "DEBUG: got att\n===\n"; 307 print_r($att); 308 echo "===\n"; 309 exit(); 310 */ 311 echo "INFO: processing attachment #{$att->id}\n"; 280 312 $seen_att[$att->id] = true; 281 313 $type = 'blobs'; 282 314 $dm1_parent_guid = $att->parameter('midcom.helper.datamanager.datatype.image', 'parent_guid'); 283 315 $dm1_thumb_guid = $att->parameter('midcom.helper.datamanager.datatype.image', 'thumbguid'); 316 $collection_fieldname = $att->parameter('midcom.helper.datamanager.datatype.collection', 'fieldname'); 284 317 // Image type needs special treatment. 285 318 if ( $dm1_parent_guid … … 290 323 if ($dm1_parent_guid) 291 324 { 325 /* 292 326 $parent_att = new midgard_attachment(); 293 327 $parent_att->get_by_guid($dm1_parent_guid); 328 */ 329 $parent_att = mgd_get_object_by_guid($dm1_parent_guid); 294 330 if (!$parent_att->id) 295 331 { … … 303 339 $parent_att = $att; 304 340 unset($att); 341 /* 305 342 $att = new midgard_attachment(); 306 343 $att->get_by_guid($dm1_thumb_guid); 344 */ 345 $att = mgd_get_object_by_guid($dm1_thumb_guid); 307 346 if (!$att->id) 308 347 { … … 323 362 $fieldname = $parent_att->parameter('midcom.helper.datamanager.datatype.blob', 'fieldname'); 324 363 $att->parameter('midcom.helper.datamanager.datatype.blob', 'fieldname', $fieldname); 325 $att->parameter('midcom.helper.datamanager2. datatype.blobs', 'identifier', 'thumbnail');326 $parent_att->parameter('midcom.helper.datamanager2. datatype.blobs', 'identifier', 'main');364 $att->parameter('midcom.helper.datamanager2.type.blobs', 'identifier', 'thumbnail'); 365 $parent_att->parameter('midcom.helper.datamanager2.type.blobs', 'identifier', 'main'); 327 366 // Clear old parent/thumb parameters 328 367 $att->parameter('midcom.helper.datamanager.datatype.image', 'parent_guid', ''); 329 368 $parent_att->parameter('midcom.helper.datamanager.datatype.image', 'thumbguid', ''); 330 369 // Rest of the parameters and be converted with simple search/replace on the domain 331 mgd_param_domain_replace($att, 'midcom.helper.datamanager.datatype.blob', 'midcom.helper.datamanager2. datatype.blobs');332 mgd_param_domain_replace($parent_att, 'midcom.helper.datamanager.datatype.blob', 'midcom.helper.datamanager2. datatype.blobs');370 mgd_param_domain_replace($att, 'midcom.helper.datamanager.datatype.blob', 'midcom.helper.datamanager2.type.blobs'); 371 mgd_param_domain_replace($parent_att, 'midcom.helper.datamanager.datatype.blob', 'midcom.helper.datamanager2.type.blobs'); 333 372 334 373 // This requires 1.8 !! 335 $object = mgd_get_object_by_guid($att->parent_guid); 336 if (!$object->guid) 337 { 338 echo "ERROR: could not fetch storage object GUID {$att->parent_guid} (parent to attachment #{$att->id})\n"; 374 $parent_object_guid = mgd_get_att_parent_guid($att); 375 $object = mgd_get_object_by_guid($parent_object_guid); 376 if (!$object->id) 377 { 378 echo "ERROR: could not fetch storage object GUID {$parent_object_guid} (parent to attachment #{$att->id})\n"; 339 379 continue; 340 380 } 341 381 $guid_list = "thumbnail:{$att->guid},main:{$parent_att->guid}"; 342 $object->parameter('midcom.helper.datamanager2. datatype.blobs', "guids_{$fieldname}", $guid_list);382 $object->parameter('midcom.helper.datamanager2.type.blobs', "guids_{$fieldname}", $guid_list); 343 383 // We have done everything for the two attachments, so skip to next unseen one 344 384 continue; 345 385 } 386 // Collection type needs even more special treatment 387 else if ($collection_fieldname) 388 { 389 echo "ERROR: Collections not supported ATM\n"; 390 continue; 391 } 346 392 // Normal blob treatment continued, first rename common domain parameters 347 mgd_param_domain_replace($att, 'midcom.helper.datamanager.datatype.blob', 'midcom.helper.datamanager2. datatype.blobs');393 mgd_param_domain_replace($att, 'midcom.helper.datamanager.datatype.blob', 'midcom.helper.datamanager2.type.blobs'); 348 394 // Add a dummy identifier 349 $identifier = md5("midcom.helper.datamanager.datatype.blob->midcom.helper.datamanager2. datatype.blobs:{$att->guid}");350 $att->parameter('midcom.helper.datamanager2. datatype.blobs', 'identifier', $identifier);395 $identifier = md5("midcom.helper.datamanager.datatype.blob->midcom.helper.datamanager2.type.blobs:{$att->guid}"); 396 $att->parameter('midcom.helper.datamanager2.type.blobs', 'identifier', $identifier); 351 397 352 398 // This requires 1.8 !! 353 $object = mgd_get_object_by_guid($att->parent_guid); 354 if (!$object->guid) 355 { 356 echo "ERROR: could not fetch storage object GUID {$att->parent_guid} (parent to attachment #{$att->id})\n"; 357 continue; 358 } 359 $object->parameter('midcom.helper.datamanager2.datatype.blobs', "guids_{$fieldname}", "{$identifier}:{$att->guid}"); 399 $parent_object_guid = mgd_get_att_parent_guid($att); 400 $object = mgd_get_object_by_guid($parent_object_guid); 401 if (!$object->id) 402 { 403 echo "ERROR: could not fetch storage object GUID {$parent_object_guid} (parent to attachment #{$att->id})\n"; 404 continue; 405 } 406 $object->parameter('midcom.helper.datamanager2.type.blobs', "guids_{$fieldname}", "{$identifier}:{$att->guid}"); 360 407 } 361 408
