Changeset 4451

Show
Ignore:
Timestamp:
10/23/06 16:31:36 (2 years ago)
Author:
rambo
Message:

DM1 blob -> DM2 blobs conversion, n.s.photos migration mark

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/support/migrate_26.php

    r4313 r4451  
    1313    'de.linkm.taviewer' => 'net.nehmer.static', 
    1414    'de.linkm.newsticker' => 'net.nehmer.blog', 
     15    'net.siriux.photos' => 'net.siriux.photos-convertme-org.routamc.gallery', 
    1516); 
    1617 
     
    2324            'desc'  => 'Name of the midgard configuration file.', 
    2425            'default' => 'midgard.conf', 
    25         ); 
     26        );   
    2627$opts_config['user'] = array ( 
    2728            'short' => 'u', 
     
    237238} 
    238239 
     240 
     241// Convert DM1 attachment types to DM2 
     242function 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(); 
     267foreach ($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 
    239362// *** Site specific code below this line *** // 
    240363