Merge pull request #5230 from solgenomics/topic/open_pollinated
[sgn.git] / db / 00121 / FixDroneImageryPartialTemplates.pm
blob6762e126c4c56a4993d1149d4581c3dbab5037c5
1 #!/usr/bin/env perl
4 =head1 NAME
6 FixDroneImageryPartialTemplates
8 =head1 SYNOPSIS
10 mx-run FixDroneImageryPartialTemplates [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 fixes the drone imagery partial template storage info to contain a template name and the image_id.
17 This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>
19 =head1 AUTHOR
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.
29 =cut
32 package FixDroneImageryPartialTemplates;
34 use Moose;
35 use Bio::Chado::Schema;
36 use CXGN::People::Schema;
37 use Try::Tiny;
38 use CXGN::Genotype::Search;
39 use JSON;
40 extends 'CXGN::Metadata::Dbpatch';
43 has '+description' => ( default => <<'' );
44 This patch fixes the drone imagery partial template storage info to contain a template name and the image_id.
46 has '+prereq' => (
47 default => sub {
48 [],
53 sub patch {
54 my $self=shift;
56 print STDOUT "Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
58 print STDOUT "\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
60 print STDOUT "\nExecuting the SQL commands.\n";
61 my $schema = Bio::Chado::Schema->connect( sub { $self->dbh->clone } );
62 my $people_schema = CXGN::People::Schema->connect( sub { $self->dbh->clone } );
64 my $manual_plot_polygon_template_partial = SGN::Model::Cvterm->get_cvterm_row($schema, 'drone_run_band_plot_polygons_partial', 'project_property')->cvterm_id();
66 my $previous_plot_polygons_rs = $schema->resultset('Project::Projectprop')->search({type_id=>$manual_plot_polygon_template_partial});
68 while (my $p = $previous_plot_polygons_rs->next) {
69 my @previous_stock_polygons = @{decode_json $p->value};
70 my @new_stock_polygons;
71 foreach (@previous_stock_polygons) {
72 push @new_stock_polygons, {
73 template_name => "NA",
74 image_id => 0,
75 polygon => $_
79 my $drone_run_band_plot_polygons = $schema->resultset('Project::Projectprop')->update_or_create({
80 type_id=>$manual_plot_polygon_template_partial,
81 project_id=>$p->project_id(),
82 rank=>0,
83 value=> encode_json(\@new_stock_polygons)
86 key=>'projectprop_c1'
87 });
90 print "You're done!\n";
94 ####
95 1; #
96 ####