File Coverage

blib/lib/App/bif/update/topic.pm
Criterion Covered Total %
statement 12 32 37.5
branch 0 10 0.0
condition 0 3 0.0
subroutine 4 5 80.0
pod 1 1 100.0
total 17 51 33.3


line stmt bran cond sub pod time code
1             package App::bif::update::topic;
2 1     1   6433 use strict;
  1         2  
  1         25  
3 1     1   6 use warnings;
  1         2  
  1         34  
4 1     1   6 use Bif::Mo;
  1         1  
  1         8  
5              
6             our $VERSION = '0.1.5_7';
7             extends 'App::bif';
8              
9             sub run {
10 1     1 1 2 my $self = shift;
11 1         6 my $opts = $self->opts;
12 1         7 my $dbw = $self->dbw;
13 0           my $info = $self->get_node( $self->uuid2id( $opts->{id} ), 'topic' );
14              
15 0           my ( $status_ids, $invalid );
16 0 0         if ( $opts->{status} ) {
17             my $project_id = $dbw->xval(
18             select => 'ts.project_id',
19             from => 'topics t',
20             inner_join => 'topic_status ts',
21             on => 'ts.id = t.topic_status_id',
22             where => { 't.id' => $info->{id} },
23 0           );
24              
25             ( $status_ids, $invalid ) =
26 0           $dbw->status_ids( $project_id, 'topic', $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 0     0     $self->pause_work;
45 0           my $start = time;
46              
47 0   0       $opts->{message} ||= $self->prompt_edit( opts => $self );
48              
49             $opts->{change_id} =
50 0           $self->new_change( parent_id => $opts->{parent_uid}, );
51              
52             $dbw->xdo(
53             insert_into => 'func_update_topic',
54             values => {
55             id => $info->{id},
56             change_id => $opts->{change_id},
57 0 0         $opts->{title} ? ( title => $opts->{title} ) : (),
    0          
58             $status_ids ? ( topic_status_id => $status_ids->[0] ) : (),
59             },
60             );
61              
62             $self->save_new_work(
63             change_id => $opts->{change_id},
64             node_id => $info->{id},
65 0           start => $start,
66             stop => time,
67             bill => 1,
68             );
69              
70             $self->end_change(
71             id => $opts->{change_id},
72             action_format => "update $info->{tkind} %s",
73             action_node_id_1 => $info->{id},
74             message => $opts->{message},
75 0           );
76              
77 0           $self->resume_work;
78             }
79 0           );
80              
81 0           return $self->ok( 'Change' . ucfirst( $info->{tkind} ) );
82             }
83              
84             1;
85             __END__