OpenInteract2/Action/CommonUpdate.pm

filter: Statementstmt 22.6% 22 / 97 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 50.0% 6 / 12 Podpod 0.0% 0 / 2 totaltotal 17.7% 28 / 158 CC 18 SCAR 46.5
CC
18
Cov
16%
update
210.0
display_form
20.0
_update_init_param
6.0
CRAP 105.0
« OpenInteract2/Controller/MainTemplate.pm ↑ Summary OpenInteract2/FullTextRules.pm »
1 package OpenInteract2::Action::CommonUpdate;
2  
3 # $Id: CommonUpdate.pm,v 1.23 2005/03/18 04:09:49 lachoy Exp $
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use base qw( OpenInteract2::Action::Common );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Log::Log4perl qw( get_logger );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use OpenInteract2::Constants qw( :log );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use OpenInteract2::Context qw( CTX );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use SPOPS::Secure qw( SEC_LEVEL_WRITE );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 $OpenInteract2::Action::CommonUpdate::VERSION = sprintf("%d.%02d", q$Revision: 1.23 $ =~ /(\d+)\.(\d+)/);
13  
14 1 my ( $log );
15  
16 0 ▶sub display_form {
Subroutine display_form: not called CC=4 SCAR=30.0
Pod undocumented
17 0 my ( $self ) = @_;
18 0 $self->param( c_task => 'display_form' );
19 0 $self->_update_init_param;
20 0 ▶ $log ||= get_logger( LOG_ACTION );
Condition0%0/3
$log ||= get_logger("OI2.ACTION")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.ACTION")
$log get_logger("OI2.ACTION")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.ACTION")
ABresult
1X1
011
000
21  
22 0 my $fail_task = $self->param( 'c_display_form_fail_task' );
23 0 my $object_class = $self->param( 'c_object_class' );
24 0 my $object = $self->param( 'c_object' );
25 0 ▶ unless ( $object ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($object) 0 0 0
26 0 my $id = $self->param( 'c_id' );
27 0 $object = eval { $object_class->fetch( $id ) };
28 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
29 0 $log->warn( "Failed to fetch object [$object_class: $id]: $@" );
30 0 $self->add_error_key( 'action.error.fetch_for_update', $@ );
31 0 return $self->execute({ task => $fail_task });
32 }
33 }
34  
35 0 my $object_type = $self->param( 'c_object_type' );
36 0 my %template_params = ( object => $object,
37 $object_type => $object );
38 0 $self->_display_form_customize( \%template_params );
39  
40 0 my $template = $self->param( 'c_display_form_template' );
41 0 $self->param( c_object => $object );
42 0 return $self->generate_content(
43 \%template_params, { name => $template } );
44 }
45  
46 0 ▶sub update {
Subroutine update: not called CC=14 SCAR=53.5
Pod undocumented
47 0 my ( $self ) = @_;
48 0 $self->param( c_task => 'update' );
49 0 $self->_update_init_param;
50  
51 0 ▶ $log ||= get_logger( LOG_ACTION );
Condition0%0/3
$log ||= get_logger("OI2.ACTION")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.ACTION")
$log get_logger("OI2.ACTION")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.ACTION")
ABresult
1X1
011
000
52 0 CTX->response->return_url( $self->param( 'c_update_return_url' ) );
53 0 my $fail_task = $self->param( 'c_update_fail_task' );
54 0 my $object = eval { $self->_common_fetch_object };
55 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
56 0 return $self->execute({ task => $fail_task });
57 }
58  
59 0 ▶ unless ( $object and $object->is_saved ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($object and $object->is_saved) 0 0 0
Condition0%0/3
$object and $object->is_saved
!ll&&!rl&&r
000
MC/DC0%0/2
$object and $object->is_saved
$object $object->is_saved
Truth table0%0/3
A and B
A= $objectB= $object->is_saved
ABresult
0X0
100
111
60 0 $log->warn( "Object does not exist or is not saved, cannot update" );
61 0 $self->add_error_key( 'action.error.update_not_saved' );
62 0 return $self->execute({ task => $fail_task });
63 }
64  
65 # TODO: - assumption: SEC_LEVEL_WRITE is necessary to update. (Probably ok.)
66  
67 0 ▶ if ( $object->{tmp_security_level} < SEC_LEVEL_WRITE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->{"tmp_security_level"} < 8) 0 0 0
68 0 ▶ my $sec_fail_task = $self->param( 'c_update_security_fail_task' )
Condition0%0/3
$self->param('c_update_security_fail_task') || $fail_task
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->param('c_update_security_fail_task') || $fail_task
$self->param('c_update_security_fail_task') $fail_task
Truth table0%0/3
A || B
A= $self->param('c_update_security_fail_task')B= $fail_task
ABresult
1X1
011
000
69 || $fail_task;
70 0 $self->add_error_key( 'action.error.update_security' );
71 0 return $self->execute({ task => $sec_fail_task });
72 }
73  
74 0 $self->param( c_object => $object );
75  
76 # We pass this to the customization routine so you can do
77 # comparisons, set off triggers based on changes, etc.
78  
79 0 my $old_data = $object->as_data_only;
80  
81 0 $self->_common_assign_properties(
82 $object,
83 { standard => scalar $self->param( 'c_update_fields' ),
84 toggled => scalar $self->param( 'c_update_fields_toggled' ),
85 boolean => scalar $self->param( 'c_update_fields_boolean' ),
86 date => scalar $self->param( 'c_update_fields_date' ),
87 datetime => scalar $self->param( 'c_update_fields_datetime' ),
88 date_format => scalar $self->param( 'c_update_date_format' ),
89 datetime_format => scalar $self->param( 'c_update_datetime_format' ), } );
90  
91 0 my $object_spec = join( '', '[', ref $object, ': ', $object->id, ']' );
92  
93 0 my %save_options = ();
94 0 $self->_update_customize( $object, $old_data, \%save_options );
95 0 $self->notify_observers( 'pre update', $object, $old_data, \%save_options );
96  
97 0 eval { $object->save( \%save_options ) };
98 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
99 0 $log->warn( "Update of $object_spec failed: $@" );
100 0 $self->add_error_key( 'action.error.update', $@ );
101 0 return $self->execute({ task => $fail_task });
102 }
103 0 ▶ $log->is_debug && $log->debug( "object updated ok" );
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("object updated ok") 0 0 0
104  
105 0 $self->param( c_object_old_data => $old_data );
106  
107 0 ▶ my $title = "'" . $object->object_description->{title} . "'" || 'Object';
Condition0%0/2
q['] . $object->object_description->{'title'} . q['] || 'Object'
l!l
00
MC/DC0%0/1
q['] . $object->object_description->{'title'} . q['] || 'Object'
q['] . $object->object_description->{'title'} . q[']
Truth table0%0/2
A
A= q['] . $object->object_description->{'title'} . q[']
Aresult
11
00
108 0 $self->add_status_key( 'action.status.update', $title );
109 0 ▶ $log->is_debug && $log->debug( "generated status messge ok" );
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("generated status messge ok") 0 0 0
110  
111 0 $self->_update_post_action( $object, $old_data );
112 0 ▶ $log->is_debug && $log->debug( "_update_post_action() ran ok" );
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("_update_post_action() ran ok") 0 0 0
113  
114 0 $self->notify_observers( 'post update', $object, $old_data );
115 0 ▶ $log->is_debug && $log->debug( "'post update' notification ok" );
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("'post update' notification ok") 0 0 0
116  
117 0 my $success_task = $self->param( 'c_update_task' );
118 0 ▶ $log->is_debug && $log->debug( "get task '$success_task' content" );
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("get task '${success_task}' content") 0 0 0
119 0 return $self->execute({ task => $success_task });
120 }
121  
122 1 my %DEFAULTS = (
123 c_display_form_fail_task => 'common_error',
124 c_update_fail_task => 'display_form',
125 c_update_task => 'display_form',
126 );
127  
128 0 ▶sub _update_init_param {
Subroutine _update_init_param: not called CC=2 SCAR=17.9
129 0 my ( $self ) = @_;
130 0 $self->_common_set_defaults(
131 { %DEFAULTS,
132 c_update_return_url => $self->create_url({ TASK => undef }) });
133  
134 0 my $has_error = $self->_common_check_object_class;
135 0 $has_error += $self->_common_check_id_field;
136 0 $has_error += $self->_common_check_id;
137 0 $has_error +=
138 $self->_common_check_template_specified( 'c_display_form_template' );
139 0 ▶ if ( $has_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_error) 0 0 0
140 0 die $self->execute({ task => 'common_error' });
141 }
142 }
143  
144 ########################################
145 # OVERRIDABLE
146  
147 0 ▶sub _display_form_customize { return undef }
Subroutine _display_form_customize: not called CC=1 SCAR=6.9
148 0 ▶sub _update_customize { return undef }
Subroutine _update_customize: not called CC=1 SCAR=6.9
149 0 ▶sub _update_post_action { return undef }
Subroutine _update_post_action: not called CC=1 SCAR=6.9
150  
151 1 1;
152  
153 __END__
« OpenInteract2/Controller/MainTemplate.pm ↑ Summary OpenInteract2/FullTextRules.pm »