line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Changeset::App::Command::update; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
7074
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
61
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
64
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
11
|
use base qw/DBIx::Changeset::App::BaseCommand/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
174
|
|
7
|
2
|
|
|
2
|
|
11
|
use DBIx::Changeset::Collection; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
15
|
|
8
|
2
|
|
|
2
|
|
700
|
use DBIx::Changeset::Loader; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
27
|
|
9
|
2
|
|
|
2
|
|
69
|
use DBIx::Changeset::Exception; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
39
|
|
10
|
2
|
|
|
2
|
|
11
|
use Term::Report; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
91
|
|
11
|
2
|
|
|
2
|
|
10
|
use Term::Prompt; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
148
|
|
12
|
2
|
|
|
2
|
|
2544
|
use Data::Dumper; |
|
2
|
|
|
|
|
13253
|
|
|
2
|
|
|
|
|
171
|
|
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
19
|
use vars qw{$VERSION}; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
101
|
|
15
|
|
|
|
|
|
|
BEGIN { |
16
|
2
|
|
|
2
|
|
2555
|
$VERSION = '1.11'; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 NAME |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
DBIx::Changeset::App::Command::update - display a list of outstanding changesets |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 METHODS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head2 run |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
sub run { |
31
|
0
|
|
|
0
|
1
|
0
|
my ($self, $opt, $args) = @_; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
0
|
my $coll = DBIx::Changeset::Collection->new($opt->{'type'}, { |
34
|
|
|
|
|
|
|
changeset_location => $opt->{'location'}, |
35
|
|
|
|
|
|
|
}); |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
0
|
eval { $coll->retrieve_all(); }; |
|
0
|
|
|
|
|
0
|
|
38
|
0
|
|
|
|
|
0
|
my $e; |
39
|
0
|
0
|
|
|
|
0
|
if ( $e = Exception::Class->caught() ) { |
40
|
0
|
|
|
|
|
0
|
warn $e->error, "\n"; |
41
|
0
|
0
|
|
|
|
0
|
warn $e->trace->as_string, "\n" if defined $opt->{'debug'}; |
42
|
0
|
|
|
|
|
0
|
exit; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
0
|
$self->determine_outstanding($opt,$coll); |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
0
|
my $rep = Term::Report->new( |
48
|
|
|
|
|
|
|
startRow => 4, |
49
|
|
|
|
|
|
|
numFormat => 0, |
50
|
|
|
|
|
|
|
statusBar => [ |
51
|
|
|
|
|
|
|
label => 'Changeset Checking:', |
52
|
|
|
|
|
|
|
subText => 'determining outstanding changesets', |
53
|
|
|
|
|
|
|
subTextAlign => 'center', |
54
|
|
|
|
|
|
|
showTime => 1, |
55
|
|
|
|
|
|
|
], |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
### deal with status bar |
59
|
0
|
|
|
|
|
0
|
$rep->{'statusBar'}->setItems($coll->total_outstanding); |
60
|
0
|
|
|
|
|
0
|
$rep->{'statusBar'}->start; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
$rep->savePoint('total', "Total changesets: ", 1); |
63
|
0
|
|
|
|
|
0
|
$rep->savePoint('applied', "\nApplied changesets: ", 1); |
64
|
0
|
|
|
|
|
0
|
$rep->savePoint('forced', "\nForced changesets: ", 1); |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
0
|
my $total = 0; |
67
|
0
|
|
|
|
|
0
|
my $applied = 0; |
68
|
0
|
|
|
|
|
0
|
my $forced = 0; |
69
|
|
|
|
|
|
|
### create the loader object |
70
|
0
|
|
|
|
|
0
|
my $loader = DBIx::Changeset::Loader->new($opt->{'loader'}, { db_host => $opt->{'db_host'}, db_name => $opt->{'db_name'}, db_pass => $opt->{'db_password'}, db_user => $opt->{'db_user'} }); |
71
|
0
|
|
|
|
|
0
|
$coll->reset; |
72
|
0
|
|
|
|
|
0
|
while ( my $record = $coll->next_outstanding ) { |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
0
|
$rep->finePrint('applied',0,++$total); |
75
|
0
|
|
|
|
|
0
|
$rep->{'statusBar'}->subText($record->uri); |
76
|
0
|
|
|
|
|
0
|
eval { $loader->apply_changeset($record); }; |
|
0
|
|
|
|
|
0
|
|
77
|
0
|
0
|
|
|
|
0
|
if ( $e = Exception::Class->caught('DBIx::Changeset::Exception::LoaderException') ) { |
|
|
0
|
|
|
|
|
|
78
|
0
|
|
|
|
|
0
|
$rep->clear(); |
79
|
0
|
|
|
|
|
0
|
$rep->printLine("Details of Changeset with Problems:\n"); |
80
|
0
|
|
|
|
|
0
|
$rep->printLine(sprintf("Id: %s\n", $record->id)); |
81
|
0
|
|
|
|
|
0
|
$rep->printLine(sprintf("md5: %s\n", uc($record->md5))); |
82
|
0
|
|
|
|
|
0
|
$rep->printLine(sprintf("Changeset Location: %s%s\n\n", $record->changeset_location, $record->uri)); |
83
|
0
|
0
|
|
|
|
0
|
if ( $opt->{'prompt'} ) { |
84
|
0
|
|
|
|
|
0
|
printf STDERR ("Could not apply Changeset %s because: %s\n\n", $record->uri, $e->error); |
85
|
0
|
|
|
|
|
0
|
my $result = &prompt("y", "Mark changeset as Applied ?", "(y/N)", "N"); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
### reset report |
88
|
0
|
|
|
|
|
0
|
$rep->clear(); |
89
|
0
|
|
|
|
|
0
|
$rep->{'statusBar'}->start; |
90
|
0
|
|
|
|
|
0
|
$rep->savePoint('total', "Total changesets: ", 1); |
91
|
0
|
|
|
|
|
0
|
$rep->savePoint('applied', "\nApplied changesets: ", 1); |
92
|
0
|
|
|
|
|
0
|
$rep->savePoint('forced', "\nForced changesets: ", 1); |
93
|
|
|
|
|
|
|
|
94
|
0
|
0
|
|
|
|
0
|
if ( $result == 1 ) { |
95
|
0
|
|
|
|
|
0
|
$record->forced(1); |
96
|
0
|
|
|
|
|
0
|
$rep->finePrint('forced',0,++$forced); |
97
|
|
|
|
|
|
|
} else { |
98
|
0
|
|
|
|
|
0
|
$rep->{'statusBar'}->update; |
99
|
0
|
|
|
|
|
0
|
next; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} else { |
102
|
0
|
|
|
|
|
0
|
$rep->finish(); |
103
|
0
|
|
|
|
|
0
|
warn $e->error, "\n"; |
104
|
0
|
0
|
|
|
|
0
|
warn $e->trace->as_string, "\n" if defined $opt->{'debug'}; |
105
|
0
|
|
|
|
|
0
|
exit; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} elsif ( $e = Exception::Class->caught() ) { |
108
|
0
|
|
|
|
|
0
|
$rep->clear(); |
109
|
0
|
|
|
|
|
0
|
$rep->finish(); |
110
|
0
|
|
|
|
|
0
|
warn $e->error, "\n"; |
111
|
0
|
0
|
|
|
|
0
|
warn $e->trace->as_string, "\n" if defined $opt->{'debug'}; |
112
|
0
|
|
|
|
|
0
|
exit; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
0
|
$rep->finePrint('applied',0,++$applied); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
### update/create the history record |
118
|
0
|
|
|
|
|
0
|
my $hrec = DBIx::Changeset::HistoryRecord->new({ |
119
|
|
|
|
|
|
|
history_db_dsn => $opt->{'history_db_dsn'}, |
120
|
|
|
|
|
|
|
history_db_user => $opt->{'history_db_user'}, |
121
|
|
|
|
|
|
|
history_db_password => $opt->{'history_db_password'}, |
122
|
|
|
|
|
|
|
}); |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
0
|
eval { $hrec->write($record); }; |
|
0
|
|
|
|
|
0
|
|
125
|
|
|
|
|
|
|
|
126
|
0
|
0
|
|
|
|
0
|
if ( $e = Exception::Class->caught() ) { |
127
|
0
|
|
|
|
|
0
|
$rep->clear(); |
128
|
0
|
|
|
|
|
0
|
$rep->finish(); |
129
|
0
|
|
|
|
|
0
|
warn $e->error, "\n"; |
130
|
0
|
0
|
|
|
|
0
|
warn $e->trace->as_string, "\n" if defined $opt->{'debug'}; |
131
|
0
|
|
|
|
|
0
|
exit; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
0
|
$rep->{'statusBar'}->update; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
$rep->printBarReport( |
139
|
0
|
|
|
|
|
0
|
"\n\n\n\n Outstanding Changeset Summary:\n\n", |
140
|
|
|
|
|
|
|
{ |
141
|
|
|
|
|
|
|
" Total: " => $coll->total_outstanding, |
142
|
|
|
|
|
|
|
" Applied: " => $applied, |
143
|
|
|
|
|
|
|
" Forced: " => $forced, |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
); |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
0
|
$rep->finish(); |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
0
|
return; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 options |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
define the options for the create command |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub options { |
160
|
4
|
|
|
4
|
1
|
14
|
my ($self, $app) = @_; |
161
|
|
|
|
|
|
|
return ( |
162
|
4
|
|
50
|
|
|
417
|
[ 'location=s' => 'Path to changeset files', { default => $app->{'config'}->{'location'} || $app->{'config'}->{'update'}->{'location'} || undef, required => 1 } ], |
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
163
|
|
|
|
|
|
|
[ 'type=s' => 'Which factory to use (default disk)', { default => $app->{'config'}->{'type'} || $app->{'config'}->{'update'}->{'type'} || 'disk' } ], |
164
|
|
|
|
|
|
|
[ 'loader=s' => 'Which loader factory to use (default mysql)', { default => $app->{'config'}->{'loader'} || $app->{'config'}->{'update'}->{'loader'} || 'mysql' } ], |
165
|
|
|
|
|
|
|
[ 'like=s' => 'only types matching regex', { default => $app->{'config'}->{'like'} || $app->{'config'}->{'update'}->{'like'} || undef } ], |
166
|
|
|
|
|
|
|
[ 'history_db_dsn=s' => 'DBI DSN for the history db', { default => $app->{'config'}->{'history_db_dsn'} || $app->{'config'}->{'update'}->{'history_db_dsn'} || undef, required => 1 } ], |
167
|
|
|
|
|
|
|
[ 'history_db_user=s' => 'db user for history db', { default => $app->{'config'}->{'history_db_user'} || $app->{'config'}->{'update'}->{'history_db_user'} || undef } ], |
168
|
|
|
|
|
|
|
[ 'history_db_password=s' => 'db password for the history db user', { default => $app->{'config'}->{'history_db_password'} || $app->{'config'}->{'update'}->{'history_db_password'} || undef } ], |
169
|
|
|
|
|
|
|
[ 'db_name=s' => 'db name for update db', { default => $app->{'config'}->{'db_name'} || $app->{'config'}->{'update'}->{'db_name'} || undef } ], |
170
|
|
|
|
|
|
|
[ 'db_host=s' => 'db host for update db', { default => $app->{'config'}->{'db_host'} || $app->{'config'}->{'update'}->{'db_host'} || undef } ], |
171
|
|
|
|
|
|
|
[ 'db_user=s' => 'db user for update db', { default => $app->{'config'}->{'db_user'} || $app->{'config'}->{'update'}->{'db_user'} || undef } ], |
172
|
|
|
|
|
|
|
[ 'db_password=s' => 'db password for the update db user', { default => $app->{'config'}->{'db_password'} || $app->{'config'}->{'update'}->{'db_password'} || undef } ], |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
); |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head2 validate |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
define the options validation for the compare command |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub validate { |
185
|
3
|
|
|
3
|
1
|
7
|
my ($self,$opt,$args) = @_; |
186
|
3
|
100
|
100
|
|
|
98
|
$self->usage_error('This command requires a valid changeset location') unless ( ( defined $opt->{'location'} ) && ( -d $opt->{'location'} ) ); |
187
|
1
|
50
|
|
|
|
11
|
$self->usage_error('This command requires a history_db_dsn') unless ( defined $opt->{'history_db_dsn'} ); |
188
|
1
|
50
|
|
|
|
10
|
$self->usage_error('This command requires a db_name for the db to apply changesets too') unless ( defined $opt->{'db_name'} ); |
189
|
0
|
|
|
|
|
|
return; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Copyright 2004-2008 Grox Pty Ltd. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
197
|
|
|
|
|
|
|
under the same terms as Perl itself. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
The full text of the license can be found in the LICENSE file included with this module. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=cut |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
1; # End of DBIx::Changeset |