Revision db797d8f
Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt
SL/DBUpgrade2.pm | ||
---|---|---|
133 | 133 |
my ($self, $dbh, $filename, $version_or_control) = @_; |
134 | 134 |
|
135 | 135 |
my $form = $self->{form}; |
136 |
my $fh = IO::File->new($filename, "r") or $form->error("$filename : $!\n");
|
|
136 |
my $fh = IO::File->new($filename, "r"); |
|
137 | 137 |
my $query = ""; |
138 | 138 |
my $sth; |
139 | 139 |
my @quote_chars; |
140 | 140 |
|
141 |
if (!$fh) { |
|
142 |
return "No such file: $filename" if $self->{return_on_error}; |
|
143 |
$form->error("$filename : $!\n"); |
|
144 |
} |
|
145 |
|
|
141 | 146 |
$dbh->begin_work(); |
142 | 147 |
|
143 | 148 |
while (<$fh>) { |
... | ... | |
182 | 187 |
$sth = $dbh->prepare($query); |
183 | 188 |
if (!$sth->execute()) { |
184 | 189 |
my $errstr = $dbh->errstr; |
190 |
return $errstr // '<unknown database error>' if $self->{return_on_error}; |
|
185 | 191 |
$sth->finish(); |
186 | 192 |
$dbh->rollback(); |
187 | 193 |
$form->dberror("The database update/creation did not succeed. " . |
... | ... | |
217 | 223 |
$fh->close(); |
218 | 224 |
|
219 | 225 |
$::lxdebug->leave_sub(); |
226 |
|
|
227 |
# Signal "no error" |
|
228 |
return undef; |
|
220 | 229 |
} |
221 | 230 |
|
222 | 231 |
# Process a Perl script which updates the database. |
... | ... | |
248 | 257 |
|
249 | 258 |
$dbh->rollback if 1 != ($result // -1); |
250 | 259 |
|
260 |
return $error if $self->{return_on_error} && (1 != ($result // -1)); |
|
261 |
|
|
251 | 262 |
if (!defined($result)) { |
252 | 263 |
print $::form->parse_html_template("dbupgrade/error", { file => $filename, error => $error }); |
253 | 264 |
::end_of_request(); |
... | ... | |
261 | 272 |
} elsif ($version_or_control) { |
262 | 273 |
$dbh->do("UPDATE defaults SET version = " . $dbh->quote($version_or_control)); |
263 | 274 |
} |
264 |
$dbh->commit(); |
|
275 |
|
|
276 |
$dbh->commit if $dbh->{AutoCommit} && $dbh->{BegunWork}; |
|
265 | 277 |
|
266 | 278 |
# Clear $::form of values that may have been set so that following |
267 | 279 |
# Perl upgrade scripts won't have to work with old data (think of |
... | ... | |
271 | 283 |
$::form->{$_} = $form_values{$_} for keys %form_values; |
272 | 284 |
|
273 | 285 |
$::lxdebug->leave_sub(); |
286 |
|
|
287 |
return undef; |
|
274 | 288 |
} |
275 | 289 |
|
276 | 290 |
sub process_file { |
277 | 291 |
my ($self, $dbh, $filename, $version_or_control) = @_; |
278 | 292 |
|
279 |
if ($filename =~ m/sql$/) { |
|
280 |
$self->process_query($dbh, $filename, $version_or_control); |
|
281 |
} else { |
|
282 |
$self->process_perl_script($dbh, $filename, $version_or_control); |
|
283 |
} |
|
293 |
return $filename =~ m/sql$/ ? $self->process_query( $dbh, $filename, $version_or_control) |
|
294 |
: $self->process_perl_script($dbh, $filename, $version_or_control); |
|
284 | 295 |
} |
285 | 296 |
|
286 | 297 |
sub update2_available { |
Auch abrufbar als: Unified diff
DBUpgrade2: Option zum Zurückgeben eines Fehlers bei DB-Upgrades anstelle von print&exit