Changeset 22819
- Timestamp:
- 09/09/10 10:28:40 (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/mnw21/pathquery_refactor/intermine/perl/lib/IMUtils/UpdatePath.pm
r21940 r22819 9 9 10 10 our @EXPORT= qw/changed dead update_path update_query check_class_name/; 11 11 12 12 my ($model, $changes, $log); 13 13 our $prefix = 'org.intermine.model.bio.'; 14 14 15 15 sub set_up { 16 # args: model, changes, 16 # args: model, changes, 17 17 my $class = shift; 18 18 my %args = @_; … … 21 21 22 22 # Read the details of the model changes from the .json config file 23 die 'No model change details supplied - please list a file with the --changesfile flag ' 23 die 'No model change details supplied - please list a file with the --changesfile flag ' 24 24 unless $args{changes}; 25 25 open my $changesFH, '<', $args{changes} or die "Could not open $args{changes}, $!"; 26 26 my $content = join('', <$changesFH>); 27 27 close $changesFH or die "could not close $args{changes}, $!"; 28 28 29 29 # Decode it into a hash reference 30 30 my $json = new JSON; … … 37 37 } 38 38 39 sub dead { 39 sub dead { 40 40 my $key = shift; 41 41 $key =~ s/$prefix//; … … 49 49 50 50 # otherwise you get @dbl_array[0,0], ie. doubling. 51 return @dbl_array if (@dbl_array == 1); 51 return @dbl_array if (@dbl_array == 1); 52 52 53 53 # find the length of the first array (ie. half the total) 54 my $midpoint = @dbl_array / 2; 54 my $midpoint = @dbl_array / 2; 55 55 56 56 # pair up the elements 57 return @dbl_array[ map { $_, $_ + $midpoint } 0 .. $midpoint - 1 ]; 57 return @dbl_array[ map { $_, $_ + $midpoint } 0 .. $midpoint - 1 ]; 58 58 } 59 59 … … 65 65 return $class; 66 66 } 67 67 68 68 my %processed; 69 69 70 70 sub update_path { 71 71 my $path = shift; … … 80 80 $prefixed++; # but remember that we did so 81 81 } 82 82 83 83 my $query = shift; 84 84 85 85 my $query_name = (ref $query) ? $query->get_name : $query; 86 86 87 87 88 88 my @new_bits; … … 92 92 93 93 my $class_name = shift @bits; 94 94 95 95 my $class = check_class_name($class_name); 96 96 … … 103 103 } 104 104 else { 105 $log->warning($query_name, qq{Unexpected deletion of class "$class_name"}) 105 $log->warning($query_name, qq{Unexpected deletion of class "$class_name"}) 106 106 unless dead($class_name); 107 107 return; 108 108 } 109 109 } 110 110 111 111 my $current_class = $class; 112 112 my $current_field = undef; 113 113 114 114 my @path_so_far = ($class_name,); 115 115 FIELD: for my $bit (@bits) { … … 117 117 if ($bit eq 'id' and $bit eq $bits[-1]) { # id is an internal attribute for all tables 118 118 push @new_bits, $bit; 119 $current_class = undef; # id must be the final attribute 119 $current_class = undef; # id must be the final attribute 120 120 # - this will catch it if it isn't 121 121 } … … 132 132 } 133 133 } 134 if (not UNIVERSAL::can($current_class, 'isa') 134 if (not UNIVERSAL::can($current_class, 'isa') 135 135 or not $current_class->isa('InterMine::Model::ClassDescriptor')) { 136 136 croak "Could not find class of $new_bits[-1] when searching for $bit in $path"; … … 140 140 } 141 141 if (!defined $current_field) { 142 142 143 143 # Maybe this field is declared in a parent class? 144 my @ parents = map {$_->name} $current_class->get_parents;145 146 foreach my $ parent (@parents) {147 my $key = "$ parent.$bit";144 my @ancestors = map {$_->name} $current_class->get_ancestors; 145 146 foreach my $ancestor (@ancestors) { 147 my $key = "$ancestor.$bit"; 148 148 if (my $translation = changed($key)) { 149 149 if ($current_field = $current_class->get_field_by_name($translation)){ … … 151 151 push @new_bits, $translation; 152 152 push @path_so_far, $bit; 153 153 154 154 $current_class = next_class($current_field); 155 155 next FIELD; 156 156 } 157 157 } 158 158 159 159 } 160 160 if (!defined $current_field) { # still! … … 198 198 } 199 199 } 200 200 201 201 sub update_query { 202 202 my $query = shift; 203 203 my $origin = shift; 204 204 205 205 my ($is_broken, $is_changed); 206 206 … … 209 209 confess "$query is not a reference" unless (ref $query); 210 210 $log->info('Processing', $query->{type}, '"'.$query->get_name. '"'); 211 211 212 212 if ($query->type_hash) { 213 213 while (my ($key, $path) = each %{$query->type_hash}) { … … 227 227 } 228 228 # to prevent undefined in string errors 229 $translation = '' unless $translation; 229 $translation = '' unless $translation; 230 230 231 231 $log->info(eval $change) unless ($path eq $translation); … … 247 247 } 248 248 $query->{view} = \@new_views; 249 249 250 250 if ($query->sort_order) { 251 251 my ($sort_order, $direction) = split(/\s/, $query->sort_order); … … 262 262 } 263 263 } 264 $query->{sort_order} = $sort_order . 264 $query->{sort_order} = $sort_order . 265 265 (($direction) ? ' ' . $direction : ''); 266 266 } … … 293 293 } 294 294 else { 295 $log->info(eval $deletion, ' (with its '. 295 $log->info(eval $deletion, ' (with its '. 296 296 scalar(@{$query->{constraints}{$path}}). 297 297 ' constraints)'); … … 315 315 $query->type_hash(\%new_typehash); 316 316 } 317 318 if ($is_broken) { 317 318 if ($is_broken) { 319 319 $log->warning($origin, $query->{type}, '"'.$query->get_name.'"', '"is broken'); 320 320 }
Note: See TracChangeset
for help on using the changeset viewer.
