convert list validate functions to run asynchronously
[sgn.git] / db / 00151 / RemoveFieldbookImageCvterm.pm
blob37f02cc905adb6ea2b65930c24f28cc656e97a14
1 #!/usr/bin/env perl
4 =head1 NAME
6 RemoveFieldbookImageCvterm
8 =head1 SYNOPSIS
10 mx-run RemoveFieldbookImageCvterm [options] -H hostname -D dbname -u username [-F]
12 this is a subclass of L<CXGN::Metadata::Dbpatch>
13 see the perldoc of parent class for more details.
15 =head1 DESCRIPTION
16 This patch removes the fieldbook_image cvterm from the cassavs_trait ontology. This term is not used by the Fieldbook App, and if it is needed in the future should be linked to stock_prop or a "local" cv.
17 This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>
19 =head1 AUTHOR
21 =head1 COPYRIGHT & LICENSE
23 Copyright 2010 Boyce Thompson Institute for Plant Research
25 This program is free software; you can redistribute it and/or modify
26 it under the same terms as Perl itself.
28 =cut
31 package RemoveFieldbookImageCvterm;
33 use Moose;
34 use Bio::Chado::Schema;
35 use Try::Tiny;
36 use SGN::Model::Cvterm;
37 extends 'CXGN::Metadata::Dbpatch';
40 has '+description' => ( default => <<'' );
41 This patch removes the fieldbook_image cvterm from the ontology.
43 has '+prereq' => (
44 default => sub {
45 [],
50 sub patch {
51 my $self=shift;
53 print STDOUT "Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
55 print STDOUT "\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
57 print STDOUT "\nExecuting the SQL commands.\n";
58 my $schema = Bio::Chado::Schema->connect( sub { $self->dbh->clone } );
60 print STDERR "Removing CVTERM fieldbook_image...\n";
62 my $coderef = sub {
65 my $subject_id;
66 my $subject = SGN::Model::Cvterm->get_cvterm_row($schema, 'fieldbook_image', 'cassava_trait');
67 if ($subject) {
68 $subject_id = $subject->cvterm_id ;
69 } else {
70 print STDERR "Cvterm fieldbook_image does not exist in the database. Exiting\n";
71 return 0;
74 #my $object_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'CGIAR cassava trait ontology', 'cassava_trait')->cvterm_id();
75 my $cvterm_relationship_rs = $schema->resultset("Cv::CvtermRelationship")->search( { subject_id => $subject_id });
76 $cvterm_relationship_rs->delete();
78 my $cvterm = $schema->resultset( "Cv::Cvterm" )->find({ cvterm_id => $subject_id });
79 $cvterm->delete();
83 try {
84 $schema->txn_do($coderef);
85 } catch {
86 die "Load failed! " . $_ . "\n" ;
89 print "You're done!\n";
93 ####
94 1; #
95 ####