@@ -265,7 +265,7 @@ sub get_year {
265265 my $rs = $self -> bcs_schema-> resultset(' Project::Project' )-> search( { ' me.project_id' => $self -> get_trial_id() })-> search_related(' projectprops' , { ' projectprops.type_id' => $type_id } );
266266
267267 if ($rs -> count() == 0) {
268- return undef ;
268+ return ;
269269 }
270270 else {
271271 return $rs -> first()-> value();
@@ -944,7 +944,7 @@ sub get_project_type {
944944 }
945945 }
946946 }
947- return undef ;
947+ return ;
948948
949949}
950950
@@ -1029,21 +1029,21 @@ sub get_breeding_program {
10291029 my $self = shift ;
10301030
10311031 my $rs = $self -> bcs_schema()-> resultset(" Project::ProjectRelationship" )-> search({
1032- subject_project_id => $self -> get_trial_id(),
1033- type_id => $self -> get_breeding_program_trial_relationship_cvterm_id(),
1034- });
1032+ subject_project_id => $self -> get_trial_id(),
1033+ type_id => $self -> get_breeding_program_trial_relationship_cvterm_id(),
1034+ });
10351035 if ($rs -> count() == 0) {
1036- return undef ;
1036+ return ;
10371037 }
10381038
10391039 my $bp_rs = $self -> bcs_schema()-> resultset(" Project::Project" )-> search({
1040- project_id => $rs -> first()-> object_project_id()
1041- });
1040+ project_id => $rs -> first()-> object_project_id()
1041+ });
10421042 if ($bp_rs -> count > 0) {
1043- return $bp_rs -> first()-> name();
1043+ return $bp_rs -> first()-> name();
10441044 }
10451045
1046- return undef ;
1046+ return ;
10471047}
10481048
10491049sub set_breeding_program {
@@ -1344,7 +1344,7 @@ sub get_transplanting_date {
13441344 if ($row ){
13451345 my $harvest_date = $calendar_funcs -> display_start_date($row -> value());
13461346 return $harvest_date ;
1347- }
1347+ }
13481348 else {
13491349 return ;
13501350 }
@@ -1363,7 +1363,7 @@ sub set_transplanting_date {
13631363 });
13641364 $row -> value($transplanting_event );
13651365 $row -> update();
1366- }
1366+ }
13671367 else {
13681368 print STDERR " date format did not pass check while preparing to set transplanting date: $transplanting_date \n " ;
13691369 }
@@ -1377,14 +1377,14 @@ sub remove_transplanting_date {
13771377 my $transplanting_date_cvterm_id = $self -> get_transplanting_date_cvterm_id();
13781378 my $row = $self -> bcs_schema-> resultset(' Project::Projectprop' )-> find_or_create({
13791379 project_id => $self -> get_trial_id(),
1380- type_id => $transplanting_date_cvterm_id ,
1380+ type_id => $transplanting_date_cvterm_id ,
13811381 value => $transplanting_event ,
13821382 });
13831383 if ($row ){
13841384 print STDERR " Removing transplanting date $transplanting_event from trial " .$self -> get_trial_id()." \n " ;
13851385 $row -> delete ();
1386- }
1387- }
1386+ }
1387+ }
13881388 else {
13891389 print STDERR " date format did not pass check while preparing to delete transplanting date: $transplanting_date \n " ;
13901390 }
@@ -5385,6 +5385,71 @@ sub genotyping_protocol_count {
53855385}
53865386
53875387
5388+ =head2 function delete_empty_transformation_project()
5389+
5390+ Usage:
5391+ Desc:
5392+ Ret:
5393+ Args:
5394+ Side Effects:
5395+ Example:
5396+
5397+ =cut
5398+
5399+ sub delete_empty_transformation_project {
5400+ my $self = shift ;
5401+ my $project_id = $self -> get_trial_id();
5402+
5403+ if ($self -> transformation_id_count() > 0) {
5404+ return ' Cannot delete transformation project with associated transformation IDs.' ;
5405+ }
5406+
5407+ my $project_owner_schema = CXGN::Phenome::Schema-> connect ( sub {$self -> bcs_schema-> storage-> dbh()},{on_connect_do => [' SET search_path TO public,phenome;' ]});
5408+ my $project_owner_row = $project_owner_schema -> resultset(' ProjectOwner' )-> find( { project_id => $project_id });
5409+ if ($project_owner_row ) {
5410+ $project_owner_row -> delete ();
5411+ }
5412+
5413+ eval {
5414+ my $row = $self -> bcs_schema-> resultset(" Project::Project" )-> find( { project_id => $project_id });
5415+ $row -> delete ();
5416+ print STDERR " deleted project " .$project_id ." \n " ;
5417+ };
5418+ if ($@ ) {
5419+ print STDERR " An error occurred during deletion: $@ \n " ;
5420+ return $@ ;
5421+ }
5422+ }
5423+
5424+ =head2 function transformation_id_count()
5425+
5426+ Usage:
5427+ Desc: The number of transformation ids associated with this transformation project
5428+ Ret:
5429+ Args:
5430+ Side Effects:
5431+ Example:
5432+
5433+ =cut
5434+
5435+ sub transformation_id_count {
5436+ my $self = shift ;
5437+ my $schema = $self -> bcs_schema;
5438+ my $project_id = $self -> get_trial_id();
5439+ my $transformation_experiment_type_id = SGN::Model::Cvterm-> get_cvterm_row($schema , " transformation_experiment" , " experiment_type" )-> cvterm_id();
5440+
5441+ my $q = " SELECT count(nd_experiment_project.nd_experiment_id)
5442+ FROM nd_experiment_project
5443+ JOIN nd_experiment on (nd_experiment_project.nd_experiment_id = nd_experiment.nd_experiment_id)
5444+ WHERE nd_experiment.type_id = ?
5445+ AND nd_experiment_project.project_id = ?" ;
5446+ my $h = $self -> bcs_schema-> storage-> dbh()-> prepare($q );
5447+ $h -> execute($transformation_experiment_type_id , $project_id );
5448+ my ($count ) = $h -> fetchrow_array();
5449+ return $count ;
5450+ }
5451+
5452+
53885453
53895454
539054551;
0 commit comments