| | 391 | continue; |
|---|
| | 392 | */ |
|---|
| | 393 | if (!class_exists('midgard_query_builder')) |
|---|
| | 394 | { |
|---|
| | 395 | echo "ERROR: Collections can only be converted under 1.8\n"; |
|---|
| | 396 | continue; |
|---|
| | 397 | } |
|---|
| | 398 | $parent_object_guid = mgd_get_att_parent_guid($att); |
|---|
| | 399 | $object = mgd_get_object_by_guid($parent_object_guid); |
|---|
| | 400 | if (!$object->id) |
|---|
| | 401 | { |
|---|
| | 402 | echo "ERROR: could not fetch storage object GUID {$parent_object_guid} (parent to attachment #{$att->id})\n"; |
|---|
| | 403 | continue; |
|---|
| | 404 | } |
|---|
| | 405 | $qb_catt = new midgard_query_builder('midgard_attachment'); |
|---|
| | 406 | $qb_catt->add_constraint('parameter.domain', '=', 'midcom.helper.datamanager.datatype.collection'); |
|---|
| | 407 | $qb_catt->add_constraint('pid', '=', $object->id); |
|---|
| | 408 | $qb_catt->add_constraint('ptable', '=', $object->__table__); |
|---|
| | 409 | $collections = $qb_catt->execute(); |
|---|
| | 410 | $collections_sorted = array(); |
|---|
| | 411 | foreach ($collections as $tmp_att) |
|---|
| | 412 | { |
|---|
| | 413 | $att = mgd_get_attachment($tmp_att->id); |
|---|
| | 414 | $fieldname = $att->parameter('midcom.helper.datamanager.datatype.collection', 'fieldname'); |
|---|
| | 415 | $id = $att->parameter('midcom.helper.datamanager.datatype.collection', 'id'); |
|---|
| | 416 | if (!isset($collections_sorted[$fieldname])) |
|---|
| | 417 | { |
|---|
| | 418 | $collections_sorted[$fieldname] = array(); |
|---|
| | 419 | } |
|---|
| | 420 | $collections_sorted[$fieldname][$id] = $att; |
|---|
| | 421 | $seen_att[$att->id] = true; |
|---|
| | 422 | } |
|---|
| | 423 | |
|---|
| | 424 | /* |
|---|
| | 425 | echo "DEBUG: collections_sorted\n===\n"; |
|---|
| | 426 | print_r($collections_sorted); |
|---|
| | 427 | echo "===\n"; |
|---|
| | 428 | */ |
|---|
| | 429 | |
|---|
| | 430 | foreach ($collections_sorted as $fieldname => $attachments) |
|---|
| | 431 | { |
|---|
| | 432 | $guid_list = ''; |
|---|
| | 433 | ksort($attachments); |
|---|
| | 434 | foreach ($attachments as $id => $att) |
|---|
| | 435 | { |
|---|
| | 436 | $identifier = md5("midcom.helper.datamanager.datatype.collection:{$id}:{$att->guid}"); |
|---|
| | 437 | $guid_list .= ",{$identifier}:{$att->guid}"; |
|---|
| | 438 | $att->parameter('midcom.helper.datamanager2.type.blobs', 'identifier', $identifier); |
|---|
| | 439 | $att->parameter('midcom.helper.datamanager2.type.blobs', 'fieldname', $fieldname); |
|---|
| | 440 | mgd_param_domain_replace($att, 'midcom.helper.datamanager.datatype.collection', 'deleteme-midcom.helper.datamanager.datatype.collection'); |
|---|
| | 441 | mgd_param_domain_replace($att, 'midcom.helper.datamanager.datatype.blob', 'midcom.helper.datamanager2.type.blobs'); |
|---|
| | 442 | } |
|---|
| | 443 | $guid_list = substr($guid_list, 1); |
|---|
| | 444 | $object->parameter('midcom.helper.datamanager2.type.blobs', "guids_{$fieldname}", $guid_list); |
|---|
| | 445 | echo "INFO: saved following collection: {$guid_list}\n"; |
|---|
| | 446 | } |
|---|
| | 447 | // Collection handled |
|---|