Revision 486fe464
Von Moritz Bunkus vor fast 14 Jahren hinzugefügt
SL/DBUpgrade2.pm | ||
---|---|---|
329 | 329 |
sub unapplied_upgrade_scripts { |
330 | 330 |
my ($self, $dbh) = @_; |
331 | 331 |
|
332 |
$::lxdebug->dump(0, "self", $self); |
|
333 |
|
|
332 | 334 |
my @all_scripts = map { $_->{applied} = 0; $_ } $self->sort_dbupdate_controls; |
333 | 335 |
|
334 | 336 |
my $query = qq|SELECT tag FROM | . $self->{schema} . qq|schema_info|; |
... | ... | |
342 | 344 |
return grep { !$_->{applied} } @all_scripts; |
343 | 345 |
} |
344 | 346 |
|
347 |
sub apply_admin_dbupgrade_scripts { |
|
348 |
my ($self, $called_from_admin) = @_; |
|
349 |
|
|
350 |
return if !$self->{auth}; |
|
351 |
|
|
352 |
my $dbh = $::auth->dbconnect; |
|
353 |
my @unapplied_scripts = $self->unapplied_upgrade_scripts($dbh); |
|
354 |
|
|
355 |
return if !@unapplied_scripts; |
|
356 |
|
|
357 |
my $db_charset = $main::dbcharset || Common::DEFAULT_CHARSET; |
|
358 |
$self->{form}->{login} ||= 'admin'; |
|
359 |
|
|
360 |
map { $_->{description} = SL::Iconv::convert($_->{charset}, $db_charset, $_->{description}) } values %{ $self->{all_controls} }; |
|
361 |
|
|
362 |
$self->{form}->{title} = $::locale->text('Dataset upgrade'); |
|
363 |
$self->{form}->header; |
|
364 |
print $self->{form}->parse_html_template("dbupgrade/header", { dbname => $::auth->{DB_config}->{db} }); |
|
365 |
|
|
366 |
foreach my $control (@unapplied_scripts) { |
|
367 |
$::lxdebug->message(LXDebug->DEBUG2(), "Applying Update $control->{file}"); |
|
368 |
print $self->{form}->parse_html_template("dbupgrade/upgrade_message2", $control); |
|
369 |
|
|
370 |
$self->process_file($dbh, "sql/$self->{dbdriver}-upgrade2-auth/$control->{file}", $control, $db_charset); |
|
371 |
} |
|
372 |
|
|
373 |
print $self->{form}->parse_html_template("dbupgrade/footer", { is_admin => $called_from_admin }); |
|
374 |
::end_of_request(); |
|
375 |
} |
|
376 |
|
|
345 | 377 |
sub _check_for_loops { |
346 | 378 |
my ($form, $file_name, $controls, $tag, @path) = @_; |
347 | 379 |
|
... | ... | |
395 | 427 |
sub sort_dbupdate_controls { |
396 | 428 |
my $self = shift; |
397 | 429 |
|
430 |
$self->parse_dbupdate_controls unless $self->{all_controls}; |
|
431 |
|
|
398 | 432 |
return sort { ($a->{depth} <=> $b->{depth}) || ($a->{priority} <=> $b->{priority}) || ($a->{tag} cmp $b->{tag}) } values %{ $self->{all_controls} }; |
399 | 433 |
} |
400 | 434 |
|
bin/mozilla/admin.pl | ||
---|---|---|
1167 | 1167 |
} |
1168 | 1168 |
|
1169 | 1169 |
sub _apply_dbupgrade_scripts { |
1170 |
my $dbh = $::auth->dbconnect; |
|
1171 |
my $dbdriver = 'Pg'; |
|
1172 |
my $dbupdater = SL::DBUpgrade2->new(form => $::form, dbdriver => $dbdriver, auth => 1)->parse_dbupdate_controls; |
|
1173 |
my @unapplied_scripts = $dbupdater->unapplied_upgrade_scripts($dbh); |
|
1174 |
|
|
1175 |
return if !@unapplied_scripts; |
|
1176 |
|
|
1177 |
my $db_charset = $main::dbcharset || Common::DEFAULT_CHARSET; |
|
1178 |
$form->{login} = 'admin'; |
|
1179 |
|
|
1180 |
map { $_->{description} = SL::Iconv::convert($_->{charset}, $db_charset, $_->{description}) } values %{ $dbupdater->{all_controls} }; |
|
1181 |
|
|
1182 |
$form->{title} = $::locale->text('Dataset upgrade'); |
|
1183 |
$form->header; |
|
1184 |
print $form->parse_html_template("dbupgrade/header", { dbname => $::auth->{DB_config}->{db} }); |
|
1185 |
|
|
1186 |
foreach my $control (@unapplied_scripts) { |
|
1187 |
$::lxdebug->message(LXDebug->DEBUG2(), "Applying Update $control->{file}"); |
|
1188 |
print $form->parse_html_template("dbupgrade/upgrade_message2", $control); |
|
1189 |
|
|
1190 |
$dbupdater->process_file($dbh, "sql/${dbdriver}-upgrade2-auth/$control->{file}", $control, $db_charset); |
|
1191 |
} |
|
1192 |
|
|
1193 |
print $form->parse_html_template("dbupgrade/footer", { is_admin => 1, menufile => 'admin.pl' }); |
|
1194 |
::end_of_request(); |
|
1170 |
SL::DBUpgrade2->new(form => $::form, dbdriver => 'Pg', auth => 1)->parse_dbupdate_controls->apply_admin_dbupgrade_scripts(1); |
|
1195 | 1171 |
} |
1196 | 1172 |
|
1197 | 1173 |
1; |
templates/webpages/dbupgrade/footer.html | ||
---|---|---|
1 | 1 |
[%- USE T8 %] |
2 | 2 |
[% USE HTML %]<p>[% '...done' | $T8 %]</p> |
3 | 3 |
|
4 |
<form action="[% menufile %]">
|
|
4 |
<form action="[% IF is_admin %]admin.pl[% ELSE %][% menufile %][% END %]">
|
|
5 | 5 |
|
6 | 6 |
<input type="hidden" name="action" value="[% IF is_admin %]login[% ELSE %]display[% END %]"> |
7 | 7 |
|
Auch abrufbar als: Unified diff
Admin-DB-Upgrade-Funktion nach DBUpgrade2 verschoben