5 RenameObsoleteStocks.pm
9 mx-run RenameObsoleteStocks [options] -H hostname -D dbname -u username [-F]
11 this is a subclass of L<CXGN::Metadata::Dbpatch>
12 see the perldoc of parent class for more details.
16 This patch renames obsolete stocks by adding _OBSOLETED and a timestamp to the end of the uniquename and name. This then allows new stocks to be added with the same name as the obsoleted stock.
20 Bryan Ellerbrock<bje24@cornell.edu>
22 =head1 COPYRIGHT & LICENSE
24 Copyright 2010 Boyce Thompson Institute for Plant Research
26 This program is free software; you can redistribute it and/or modify
27 it under the same terms as Perl itself.
32 package RenameObsoleteStocks
;
35 use Bio
::Chado
::Schema
;
37 extends
'CXGN::Metadata::Dbpatch';
40 has
'+description' => ( default => <<'' );
41 This patch renames obsolete stocks by adding _OBSOLETED
and a timestamp to the end of the uniquename
and name
. This then allows new stocks to be added with the same name as the obsoleted stock
.
47 print STDOUT
"Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
49 print STDOUT
"\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
51 print STDOUT
"\nExecuting the SQL commands.\n";
53 my $schema = Bio
::Chado
::Schema
->connect( sub { $self->dbh->clone } );
56 print STDERR
"Updating names of obsolete stocks . . .\n";
58 my $obsolete_stocks = $schema->resultset("Stock::Stock")->search({is_obsolete
=> 't'});
60 while (my $stock = $obsolete_stocks->next) {
61 my $obsolete_string = '_OBSOLETED_' . localtime();
62 my $name = $stock->name();
63 my $uniquename = $stock->uniquename();
65 unless ($name =~ /OBSOLETE/ || $uniquename =~ /OBSOLETE/) { # skip if already renamed
66 $stock->update( { name
=> $name . $obsolete_string, uniquename
=> $uniquename . $obsolete_string }, );
67 print STDERR
"Set stock $name name to $name$obsolete_string and uniquename to $uniquename$obsolete_string . . .\n";
74 $schema->txn_do($coderef);
76 die "RenameObsoleteStocks patch failed! " . $_ . "\n" ;
79 print "You're done!\n";