| 900 | | # we could possibly determine the list of types to process |
| 901 | | # programmatically, but this will do... |
| 902 | | $self->add_step('core_upgrade_meta_for_table', type => 'entry'); |
| 903 | | $self->add_step('core_upgrade_meta_for_table', type => 'author'); |
| 904 | | $self->add_step('core_upgrade_meta_for_table', type => 'blog'); |
| 905 | | $self->add_step('core_upgrade_meta_for_table', type => 'template'); |
| 906 | | $self->add_step('core_upgrade_meta_for_table', type => 'asset'); |
| 907 | | $self->add_step('core_upgrade_meta_for_table', type => 'category', |
| 908 | | plugindata => 1); |
| | 900 | my $types = MT->registry('object_types'); |
| | 901 | my %added_step; |
| | 902 | TYPE: while (my ($type, $reg_class) = each %$types) { |
| | 903 | next TYPE if $type eq 'plugin' && ref $reg_class; # plugin reference |
| | 904 | |
| | 905 | my $class = MT->model($type); |
| | 906 | next TYPE if !$class->has_meta(); # nothing to upgrade |
| | 907 | |
| | 908 | next TYPE if $added_step{$class->datasource}; # already got that one |
| | 909 | |
| | 910 | my $class_type = $class->properties->{class_type}; |
| | 911 | if ($class_type && $class_type ne $class->datasource) { |
| | 912 | if (my $super_class = MT->model($class->datasource)) { |
| | 913 | $class = $super_class |
| | 914 | if $super_class->datasource eq $class->datasource; |
| | 915 | } |
| | 916 | # If there's no appropriate superclass, go to update with the class |
| | 917 | # we have, not the class we want. |
| | 918 | } |
| | 919 | |
| | 920 | my %step_param = ( type => $type ); |
| | 921 | $step_param{plugindata} = 1 if $type eq 'category'; |
| | 922 | $step_param{meta_column} = $class->properties->{meta_column} |
| | 923 | if $class->properties->{meta_column}; |
| | 924 | $self->add_step('core_upgrade_meta_for_table', %step_param); |
| | 925 | $added_step{$class->datasource} = 1; |
| | 926 | } |
| | 928 | } |
| | 929 | |
| | 930 | sub _save_meta { |
| | 931 | my $self = shift; |
| | 932 | my ($obj, $type, $value) = @_; |
| | 933 | |
| | 934 | my $meta_obj = $obj->meta_pkg->new; |
| | 935 | |
| | 936 | my @class_keys = @{ $obj->primary_key_tuple }; |
| | 937 | my @meta_keys = @{ $meta_obj->primary_key_tuple }; |
| | 938 | for my $i (0..$#class_keys) { |
| | 939 | my $class_field = $class_keys[$i]; |
| | 940 | my $meta_field = $meta_keys[$i]; |
| | 941 | $meta_obj->$meta_field($obj->$class_field()); |
| | 942 | } |
| | 943 | |
| | 944 | # Set the type without checking if it's defined, unlike real meta(). |
| | 945 | $meta_obj->type($type); |
| | 946 | |
| | 947 | # Does this meta type have a data type defined? |
| | 948 | my $datatype; |
| | 949 | if (my $field = MT::Meta->metadata_by_name(ref $obj || $obj, $type)) { |
| | 950 | if (my $type_id = $field->{type_id}) { |
| | 951 | $datatype = $MT::Meta::Types{$type_id}; |
| | 952 | } |
| | 953 | } |
| | 954 | $datatype ||= 'vblob'; |
| | 955 | |
| | 956 | $meta_obj->$datatype($value); |
| | 957 | |
| | 958 | my $meta_col_def = $meta_obj->column_def($datatype); |
| | 959 | my $meta_is_blob = $meta_col_def ? $meta_col_def->{type} eq 'blob' : 0; |
| | 960 | MT::Meta::Proxy::serialize_blob(undef, $meta_obj) if $meta_is_blob; |
| | 961 | $meta_obj->save(); |
| | 962 | MT::Meta::Proxy::unserialize_blob($meta_obj) if $meta_is_blob; |