File Coverage

blib/lib/App/bif/update/topic.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::topic;
2 1     1   6274 use strict;
  1         2  
  1         29  
3 1     1   5 use warnings;
  1         2  
  1         36  
4 1     1   5 use Bif::Mo;
  1         1  
  1         9  
5              
6             our $VERSION = '0.1.5_6';
7             extends 'App::bif';
8              
9             sub run {
10 1     1 1 2 my $self = shift;
11 1         4 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             $self->start_work(
45             node_id => $info->{id},
46 0     0     start => time,
47             start_comment => "update topic",
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_topic',
59             values => {
60             id => $info->{id},
61             change_id => $opts->{change_id},
62 0 0         $opts->{title} ? ( title => $opts->{title} ) : (),
    0          
63             $status_ids ? ( topic_status_id => $status_ids->[0] ) : (),
64             },
65             );
66              
67 0           $self->stop_work(
68             stop => time,
69             restore => 1,
70             );
71              
72             $self->record_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 $info->{tkind} %s",
80             action_node_id_1 => $info->{id},
81             message => $opts->{message},
82 0           );
83              
84             }
85 0           );
86              
87 0           return $self->ok( 'Change' . ucfirst( $info->{tkind} ) );
88             }
89              
90             1;
91             __END__