Changeset 2663

Show
Ignore:
Timestamp:
06/30/08 22:52:33 (12 months ago)
Author:
mpaschal
Message:

Upgrade category and folder data separately from the column metadata types (at least for now)
BugzID: 80404

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/release-41/lib/MT/Upgrade.pm

    r2661 r2663  
    935935            code => \&core_upgrade_meta, 
    936936        }, 
     937        'core_upgrade_category_meta' => { 
     938            version_limit => 4.0057, 
     939            priority => 3.2, 
     940            code => \&core_upgrade_category_meta, 
     941        }, 
    937942 
    938943        # Helper upgrade routines for core_upgrade_meta 
     
    945950            code => \&core_upgrade_meta_for_table, 
    946951        }, 
     952        'core_upgrade_plugindata_meta_for_table' => { 
     953            priority => 1.5, 
     954            code => \&core_upgrade_plugindata_meta_for_table, 
     955        }, 
    947956        'core_drop_meta_for_table' => { 
    948957            priority => 3.4, 
     
    10051014    my $types = MT->registry('object_types'); 
    10061015    my %added_step; 
    1007     TYPE: while (my ($type, $reg_class) = each %$types) { 
    1008         next TYPE if $type eq 'plugin' && ref $reg_class;  # plugin reference 
    1009  
    1010         my $class = MT->model($type); 
     1016    TYPE: while (my ($registry_type, $reg_class) = each %$types) { 
     1017        next TYPE if $registry_type eq 'plugin' && ref $reg_class;  # plugin reference 
     1018 
     1019        my $class = MT->model($registry_type); 
    10111020        next TYPE if !$class->has_meta();  # nothing to upgrade 
    10121021 
    1013         # TODO: what is this supposed to mean? 
    1014         my $t = $type; 
     1022        # If this is a class-based package, find its super-most superclass with the same table. 
    10151023        my $class_type = $class->properties->{class_type}; 
    10161024        if ($class_type && $class_type ne $class->datasource) { 
    1017             $t = $class_type; 
    10181025            if (my $super_class = MT->model($class->datasource)) { 
    10191026                $class = $super_class 
     
    10221029            # If there's no appropriate superclass, go to update with the class 
    10231030            # we have, not the class we want. 
    1024             # TODO: if we're checking against the registry type without modifying it, why are we looking for a better object class first? 
    1025             next TYPE if $added_step{$type};  # already got that one 
    1026         } 
    1027         else { 
    1028             next TYPE if $added_step{$class->datasource};  # already got that one 
    1029         } 
    1030  
    1031         # TODO: why is this no longer the representative type for a table? that makes us upgrade tables multiple times 
    1032         my %step_param = ( type => $t ); 
    1033         # TODO: can't we just make this a different upgrade step? 
    1034         $step_param{plugindata} = 1 
    1035             if ( $class eq 'MT::Category' ) || ( $class eq 'MT::Folder' ); 
     1031        } 
     1032 
     1033        # Don't add another step for this table if we already made one. 
     1034        next TYPE if $added_step{$class->datasource}; 
     1035 
     1036        # Categories' and Folders' metadata are only custom fields, which are stored 
     1037        # in plugindata anyway. They're converted in their own upgrade step. So don't 
     1038        # handle them here. 
     1039        next TYPE if $class->isa('MT::Category'); 
     1040 
     1041        my %step_param = ( type => $registry_type ); 
    10361042        $step_param{meta_column} = $class->properties->{meta_column} 
    10371043            if $class->properties->{meta_column}; 
    10381044        $self->add_step('core_upgrade_meta_for_table', %step_param); 
    1039         # TODO: wait, then we set it based on the class? we're adding a step for every object_types entry then!! 
    1040         $added_step{$class} = 1; 
     1045 
     1046        # Yay, we added a step for this table. 
     1047        $added_step{$class->datasource} = 1; 
    10411048    } 
    10421049    return 0; 
     
    10781085} 
    10791086 
    1080 sub core_upgrade_meta_for_table { 
     1087sub core_upgrade_category_meta { 
     1088    my $self = shift; 
     1089    $self->add_step('core_upgrade_plugindata_meta_for_table', type => 'category'); 
     1090    $self->add_step('core_upgrade_plugindata_meta_for_table', type => 'folder'); 
     1091    return 0; 
     1092} 
     1093 
     1094sub core_upgrade_plugindata_meta_for_table { 
    10811095    my $self = shift; 
    10821096    return 0 if $Installing; 
     
    10861100    my $class = MT->model($type); 
    10871101    return 0 unless $class; 
     1102 
    10881103    my $cfclass = MT->model('field'); 
    1089     my $plugindata = $param{plugindata} || 0; 
    1090  
    1091     if ($cfclass) { 
    1092         # this looks weird, but it winds up invoking 
    1093         # the loading of custom field types and the 
    1094         # installation of their meta properties 
    1095         MT->registry('tags'); 
    1096     } 
     1104    return 0 if !$cfclass; 
     1105 
     1106    # this looks weird, but it winds up invoking 
     1107    # the loading of custom field types and the 
     1108    # installation of their meta properties 
     1109    MT->registry('tags'); 
    10971110 
    10981111    # special case for types that use CustomField plugindata 
    10991112    # for storing their custom field metadata instead of a 'meta' 
    11001113    # column. 
    1101     if ($cfclass && $plugindata) { 
    1102         require CustomFields::Upgrade; 
    1103         $self->progress($self->translate_escape('Moving metadata storage for categories...')); 
    1104         CustomFields::Upgrade::customfields_move_meta($self, $type); 
    1105         return 0; 
    1106     } 
    1107     if ($plugindata) { 
    1108         return 0; 
    1109     } 
     1114    require CustomFields::Upgrade; 
     1115    # TODO: really this should vary on $type but it's already translated for "categories" 
     1116    $self->progress($self->translate_escape('Moving metadata storage for categories...')); 
     1117    CustomFields::Upgrade::customfields_move_meta($self, $type); 
     1118 
     1119    return 0; 
     1120} 
     1121 
     1122sub core_upgrade_meta_for_table { 
     1123    my $self = shift; 
     1124    return 0 if $Installing; 
     1125    my (%param) = @_; 
     1126    my $type = $param{type}; 
     1127    return 0 unless $type; 
     1128    my $class = MT->model($type); 
     1129    return 0 unless $class; 
    11101130 
    11111131    my $offset = int($param{offset} || 0); 
     
    11871207                            my $metavalue = $metadata->{$metaname}; 
    11881208                            if ($metaname eq 'customfields') { 
     1209                                my $cfclass = MT->model('field'); 
    11891210                                next unless $cfclass; 
    11901211