| | 240 | |
|---|
| | 241 | // Convert DM1 attachment types to DM2 |
|---|
| | 242 | function mgd_param_domain_replace($obj, $from, $to) |
|---|
| | 243 | { |
|---|
| | 244 | $params = $obj->listparameters($from); |
|---|
| | 245 | if (!$params) |
|---|
| | 246 | { |
|---|
| | 247 | return; |
|---|
| | 248 | } |
|---|
| | 249 | while ($params->fetch()) |
|---|
| | 250 | { |
|---|
| | 251 | if ( !$obj->parameter($to, $params->name, $params->value) |
|---|
| | 252 | || !$obj->parameter($from, $params->name, '')) |
|---|
| | 253 | { |
|---|
| | 254 | echo "ERROR: could not move parameter('{$to}', '{$params->name}', '{$params->value}'), from '{$from}' (in object {$obj->guid})\n"; |
|---|
| | 255 | continue; |
|---|
| | 256 | } |
|---|
| | 257 | echo "INFO: moved parameter('{$to}', '{$params->name}', '{$params->value}'), from '{$from}' (in object {$obj->guid})\n"; |
|---|
| | 258 | } |
|---|
| | 259 | } |
|---|
| | 260 | $qb_dm1p = new MidgardQueryBuilder('midgard_parameter'); |
|---|
| | 261 | $qb_dm1p->add_constraint('domain', '=', 'midcom.helper.datamanager.datatype.blob'); |
|---|
| | 262 | $qb_dm1p->add_constraint('name', '=', 'fieldname'); |
|---|
| | 263 | $qb_dm1p->add_constraint('tablename', '=', 'record_extension'); |
|---|
| | 264 | $qb_dm1p->add_order('oid', 'ASC'); |
|---|
| | 265 | $att_params = $qb_dm1p->execute(); |
|---|
| | 266 | $seen_att = array(); |
|---|
| | 267 | foreach ($att_params as $param) |
|---|
| | 268 | { |
|---|
| | 269 | if (isset($seen_att[$param->oid])) |
|---|
| | 270 | { |
|---|
| | 271 | continue; |
|---|
| | 272 | } |
|---|
| | 273 | $att = new midgard_attachment(); |
|---|
| | 274 | $att->get_by_id($param->oid); |
|---|
| | 275 | if (!$att->id) |
|---|
| | 276 | { |
|---|
| | 277 | echo "ERROR: could not fetch attachment object id #{$param->oid}\n"; |
|---|
| | 278 | continue; |
|---|
| | 279 | } |
|---|
| | 280 | $seen_att[$att->id] = true; |
|---|
| | 281 | $type = 'blobs'; |
|---|
| | 282 | $dm1_parent_guid = $att->parameter('midcom.helper.datamanager.datatype.image', 'parent_guid'); |
|---|
| | 283 | $dm1_thumb_guid = $att->parameter('midcom.helper.datamanager.datatype.image', 'thumbguid'); |
|---|
| | 284 | // Image type needs special treatment. |
|---|
| | 285 | if ( $dm1_parent_guid |
|---|
| | 286 | || $dm1_thumb_guid) |
|---|
| | 287 | { |
|---|
| | 288 | $type = 'image'; |
|---|
| | 289 | // Juggle parent_att vs att based on which att was (thumbnail or main ?) |
|---|
| | 290 | if ($dm1_parent_guid) |
|---|
| | 291 | { |
|---|
| | 292 | $parent_att = new midgard_attachment(); |
|---|
| | 293 | $parent_att->get_by_guid($dm1_parent_guid); |
|---|
| | 294 | if (!$parent_att->id) |
|---|
| | 295 | { |
|---|
| | 296 | echo "ERROR: could not fetch attachment object GUID {$dm1_parent_guid} ('parent' to #{$att->id})\n"; |
|---|
| | 297 | continue; |
|---|
| | 298 | } |
|---|
| | 299 | } |
|---|
| | 300 | else if ($dm1_thumb_guid) |
|---|
| | 301 | { |
|---|
| | 302 | // PHP5-TODO: Must be copy by value |
|---|
| | 303 | $parent_att = $att; |
|---|
| | 304 | unset($att); |
|---|
| | 305 | $att = new midgard_attachment(); |
|---|
| | 306 | $att->get_by_guid($dm1_thumb_guid); |
|---|
| | 307 | if (!$att->id) |
|---|
| | 308 | { |
|---|
| | 309 | echo "ERROR: could not fetch attachment object GUID {$dm1_thumb_guid} ('child' to #{$parent_att->id})\n"; |
|---|
| | 310 | continue; |
|---|
| | 311 | } |
|---|
| | 312 | } |
|---|
| | 313 | else |
|---|
| | 314 | { |
|---|
| | 315 | // We should not hit this |
|---|
| | 316 | echo "ERROR: Something utterly weird happened when trying to handle image datatype attachment #{$att->id}, skipping\n"; |
|---|
| | 317 | continue; |
|---|
| | 318 | } |
|---|
| | 319 | $seen_att[$att->id] = true; |
|---|
| | 320 | $seen_att[$parent_att->id] = true; |
|---|
| | 321 | |
|---|
| | 322 | // Set fieldname and identifier parameters |
|---|
| | 323 | $fieldname = $parent_att->parameter('midcom.helper.datamanager.datatype.blob', 'fieldname'); |
|---|
| | 324 | $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'); |
|---|
| | 327 | // Clear old parent/thumb parameters |
|---|
| | 328 | $att->parameter('midcom.helper.datamanager.datatype.image', 'parent_guid', ''); |
|---|
| | 329 | $parent_att->parameter('midcom.helper.datamanager.datatype.image', 'thumbguid', ''); |
|---|
| | 330 | // 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'); |
|---|
| | 333 | |
|---|
| | 334 | // 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"; |
|---|
| | 339 | continue; |
|---|
| | 340 | } |
|---|
| | 341 | $guid_list = "thumbnail:{$att->guid},main:{$parent_att->guid}"; |
|---|
| | 342 | $object->parameter('midcom.helper.datamanager2.datatype.blobs', "guids_{$fieldname}", $guid_list); |
|---|
| | 343 | // We have done everything for the two attachments, so skip to next unseen one |
|---|
| | 344 | continue; |
|---|
| | 345 | } |
|---|
| | 346 | // 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'); |
|---|
| | 348 | // 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); |
|---|
| | 351 | |
|---|
| | 352 | // 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}"); |
|---|
| | 360 | } |
|---|
| | 361 | |
|---|