File Coverage

blib/lib/App/bif/update/task.pm
Criterion Covered Total %
statement 12 31 38.7
branch 0 10 0.0
condition 0 3 0.0
subroutine 4 5 80.0
pod 1 1 100.0
total 17 50 34.0


line stmt bran cond sub pod time code
1             package App::bif::update::task;
2 1     1   4547 use strict;
  1         2  
  1         35  
3 1     1   5 use warnings;
  1         0  
  1         28  
4 1     1   4 use Bif::Mo;
  1         5  
  1         7  
5              
6             our $VERSION = '0.1.5_5';
7             extends 'App::bif';
8              
9             sub run {
10 1     1 1 1 my $self = shift;
11 1         4 my $opts = $self->opts;
12 1         5 my $dbw = $self->dbw;
13 0           my $info = $self->get_node( $self->uuid2id( $opts->{id} ), 'task' );
14              
15 0           my ( $status_ids, $invalid );
16 0 0         if ( $opts->{status} ) {
17             my $project_id = $dbw->xval(
18             select => 'task_status.project_id',
19             from => 'tasks',
20             inner_join => 'task_status',
21             on => 'task_status.id = tasks.task_status_id',
22             where => { 'tasks.id' => $info->{id} },
23 0           );
24              
25             ( $status_ids, $invalid ) =
26 0           $dbw->status_ids( $project_id, 'task', $opts->{status} );
27              
28 0 0         return $self->err( 'InvalidStatus',
29             'unknown status(s): ' . join( ', ', @$invalid ) )
30             if @$invalid;
31             }
32              
33 0 0         if ( $opts->{reply} ) {
34             my $uinfo =
35 0           $self->get_change( $opts->{reply}, $info->{first_change_id} );
36 0           $opts->{parent_uid} = $uinfo->{id};
37             }
38             else {
39 0           $opts->{parent_uid} = $info->{first_change_id};
40             }
41              
42             $dbw->txn(
43             sub {
44             $self->start_work(
45             node_id => $info->{id},
46 0     0     start => time,
47             start_comment => "update task",
48             billable => 1,
49             save => 1,
50             );
51              
52 0   0       $opts->{message} ||= $self->prompt_edit( opts => $self );
53              
54             $opts->{change_id} =
55 0           $self->new_change( parent_id => $opts->{parent_uid}, );
56              
57             $dbw->xdo(
58             insert_into => 'func_update_task',
59             values => {
60             id => $info->{id},
61             change_id => $opts->{change_id},
62 0 0         $opts->{title} ? ( title => $opts->{title} ) : (),
    0          
63             $status_ids ? ( task_status_id => $status_ids->[0] ) : (),
64             },
65             );
66              
67 0           $self->stop_work(
68             stop => time,
69             restore => 1,
70             );
71              
72             $self->save_work(
73             node_id => $info->{id},
74             change_id => $opts->{change_id}
75 0           );
76              
77             $self->end_change(
78             id => $opts->{change_id},
79             action_format => "update task %s",
80             action_node_id_1 => $info->{id},
81             message => $opts->{message},
82 0           );
83              
84             }
85 0           );
86              
87 0           return $self->ok('ChangeTask');
88             }
89              
90             1;
91             __END__