From 0b280f98054da74f79cbc9fdb3e9f4c23326be53 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 16 May 2007 15:13:20 +0000 Subject: [PATCH] =?utf8?q?Administration:=20Die=20Funktion=20zur=20Aktuali?= =?utf8?q?sierung=20von=20nicht=20aktuellen=20Datenbanken=20neu=20geschrie?= =?utf8?q?ben=20und=20wieder=20aktiviert.=20Unterst=C3=BCtzt=20auch=20die?= =?utf8?q?=20Scripte=20in=20Pg-upgrade2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/User.pm | 99 +++++---------- bin/mozilla/admin.pl | 120 ++++-------------- locale/de/admin | 4 - locale/de/all | 4 +- templates/webpages/admin/dbadmin_de.html | 2 +- templates/webpages/admin/dbadmin_master.html | 2 +- .../webpages/admin/dbupgrade_all_done_de.html | 19 +++ .../admin/dbupgrade_all_done_master.html | 19 +++ .../admin/dbupgrade_all_header_de.html | 2 + .../admin/dbupgrade_all_header_master.html | 2 + .../webpages/admin/dbupgrade_footer_de.html | 1 + .../admin/dbupgrade_footer_master.html | 1 + .../webpages/admin/dbupgrade_header_de.html | 1 + .../admin/dbupgrade_header_master.html | 1 + .../webpages/admin/update_dataset_de.html | 55 ++++++++ .../webpages/admin/update_dataset_master.html | 55 ++++++++ 16 files changed, 218 insertions(+), 169 deletions(-) create mode 100644 templates/webpages/admin/dbupgrade_all_done_de.html create mode 100644 templates/webpages/admin/dbupgrade_all_done_master.html create mode 100644 templates/webpages/admin/dbupgrade_all_header_de.html create mode 100644 templates/webpages/admin/dbupgrade_all_header_master.html create mode 100644 templates/webpages/admin/dbupgrade_footer_de.html create mode 100644 templates/webpages/admin/dbupgrade_footer_master.html create mode 100644 templates/webpages/admin/dbupgrade_header_de.html create mode 100644 templates/webpages/admin/dbupgrade_header_master.html create mode 100644 templates/webpages/admin/update_dataset_de.html create mode 100644 templates/webpages/admin/update_dataset_master.html diff --git a/SL/User.pm b/SL/User.pm index 0fb72d9fa..d2e914f7a 100644 --- a/SL/User.pm +++ b/SL/User.pm @@ -40,6 +40,7 @@ use Fcntl qw(:seek); use SL::DBUpgrade2; use SL::DBUtils; use SL::Iconv; +use SL::Inifile; sub new { $main::lxdebug->enter_sub(); @@ -666,84 +667,43 @@ sub dbneedsupdate { my ($self, $form) = @_; - my %dbsources = (); - my $query; - - $form->{sid} = $form->{dbdefault}; - &dbconnect_vars($form, $form->{dbdefault}); - - my $dbh = - DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}) - or $form->dberror; - - if ($form->{dbdriver} eq 'Pg') { + my $members = Inifile->new($main::memberfile); + my $controls = parse_dbupdate_controls($form, $form->{dbdriver}); - $query = - qq|SELECT d.datname FROM pg_database d, pg_user u | . - qq|WHERE d.datdba = u.usesysid AND u.usename = ?|; - my $sth = prepare_execute_query($form, $dbh, $query, $form->{dbuser}); + my ($query, $sth, %dbs_needing_updates); - while (my ($db) = $sth->fetchrow_array) { + foreach my $login (grep /[a-z]/, keys %{ $members }) { + my $member = $members->{$login}; - next if ($db =~ /^template/); + map { $form->{$_} = $member->{$_} } qw(dbname dbuser dbpasswd dbhost dbport); + dbconnect_vars($form, $form->{dbname}); + $main::lxdebug->dump(0, "form", $form); + my $dbh = DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}); - &dbconnect_vars($form, $db); + next unless $dbh; - my $dbh2 = - DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}) - or $form->dberror; + my $version; - $query = - qq|SELECT tablename FROM pg_tables | . - qq|WHERE tablename = 'defaults'|; - my $sth2 = prepare_execute_query($form, $dbh, $query); - - if ($sth2->fetchrow_array) { - $query = qq|SELECT version FROM defaults|; - my ($version) = selectrow_query($form, $dbh2, $query); - $dbsources{$db} = $version; - } - $sth2->finish; - $dbh2->disconnect; + $query = qq|SELECT version FROM defaults|; + $sth = prepare_query($form, $dbh, $query); + if ($sth->execute()) { + ($version) = $sth->fetchrow_array(); } - $sth->finish; - } - - if ($form->{dbdriver} eq 'Oracle') { - $query = - qq|SELECT owner FROM dba_objects |. - qq|WHERE object_name = 'DEFAULTS' AND object_type = 'TABLE'|; - - $sth = $dbh->prepare($query); - $sth->execute || $form->dberror($query); - - while (my ($db) = $sth->fetchrow_array) { - - $form->{dbuser} = $db; - &dbconnect_vars($form, $db); - - my $dbh = - DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}) - or $form->dberror; + $sth->finish(); + $dbh->disconnect(); - $query = qq|SELECT version FROM defaults|; - my $sth = $dbh->prepare($query); - $sth->execute; + next unless $version; - if (my ($version) = $sth->fetchrow_array) { - $dbsources{$db} = $version; - } - $sth->finish; - $dbh->disconnect; + if (update_available($form->{dbdriver}, $version) || update2_available($form, $controls)) { + my $dbinfo = {}; + map { $dbinfo->{$_} = $member->{$_} } grep /^db/, keys %{ $member }; + $dbs_needing_updates{$member->{dbhost} . "::" . $member->{dbname}} = $dbinfo; } - $sth->finish; } - $dbh->disconnect; - $main::lxdebug->leave_sub(); - return %dbsources; + return values %dbs_needing_updates; } sub calc_version { @@ -793,12 +753,9 @@ sub update_available { local *SQLDIR; - opendir(SQLDIR, "sql/${dbdriver}-upgrade") - or &error("", "sql/${dbdriver}-upgrade: $!"); - my @upgradescripts = - grep(/$form->{dbdriver}-upgrade-\Q$cur_version\E.*\.(sql|pl)$/, - readdir(SQLDIR)); - closedir(SQLDIR); + opendir SQLDIR, "sql/${dbdriver}-upgrade" || error("", "sql/${dbdriver}-upgrade: $!"); + my @upgradescripts = grep /${dbdriver}-upgrade-\Q$cur_version\E.*\.(sql|pl)$/, readdir SQLDIR; + closedir SQLDIR; return ($#upgradescripts > -1); } @@ -940,6 +897,8 @@ sub dbupdate2 { map({ $_->{"applied"} = 0; } @upgradescripts); + $self->create_schema_info_table($form, $dbh); + $query = qq|SELECT tag FROM schema_info|; $sth = $dbh->prepare($query); $sth->execute() || $form->dberror($query); diff --git a/bin/mozilla/admin.pl b/bin/mozilla/admin.pl index 37ac193c2..f3edde8e8 100644 --- a/bin/mozilla/admin.pl +++ b/bin/mozilla/admin.pl @@ -41,6 +41,7 @@ use SL::Form; use SL::User; use SL::Common; use SL::Inifile; +use SL::DBUpgrade2; require "bin/mozilla/common.pl"; @@ -570,117 +571,52 @@ sub continue { } sub update_dataset { - - %needsupdate = User->dbneedsupdate(\%$form); - $form->{title} = "Lx-Office ERP " . $locale->text('Database Administration') . " / " . $locale->text('Update Dataset'); - $form->header; - - print qq| - - - -
-

$form->{title}

-|; - my $field_id = 0; - foreach $key (sort keys %needsupdate) { - if ($needsupdate{$key} ne $form->{dbversion}) { - $upd .= qq| $key\n|; - $form->{dbupdate} .= "db$key "; - $field_id++; - } - } - - chop $form->{dbupdate}; - - if ($form->{dbupdate}) { - - print qq| - -{script}> - - - - - - + my @need_updates = User->dbneedsupdate($form); + $form->{NEED_UPDATES} = \@need_updates; + $form->{ALL_UPDATED} = !scalar @need_updates; - - - - - - - - -
| . $locale->text('The following Datasets need to be updated') . qq|
- -$upd + $form->header(); + print $form->parse_html_template("admin/update_dataset"); +} -
+sub dbupdate { + $form->{stylesheet} = "lx-office-erp.css"; + $form->{title} = $locale->text("Dataset upgrade"); + $form->header(); - + my $rowcount = $form->{rowcount} * 1; + my @update_rows = grep { $form->{"update_$_"} } (1 .. $rowcount); + $form->{NOTHING_TO_DO} = !scalar @update_rows; + my $saved_form = save_form(); - + $| = 1; -{rpw}> + print $form->parse_html_template("admin/dbupgrade_all_header"); - + foreach my $i (@update_rows) { + restore_form($saved_form); -
+ map { $form->{$_} = $form->{"${_}_${i}"} } qw(dbname dbdriver dbhost dbport dbuser dbpasswd); -
- + my $controls = parse_dbupdate_controls($form, $form->{dbdriver}); -
- -|; + print $form->parse_html_template("admin/dbupgrade_header"); - } else { + $form->{dbupdate} = $form->{dbname}; + $form->{$form->{dbname}} = 1; - print $locale->text('All Datasets up to date!'); + User->dbupdate($form); + User->dbupdate2($form, $controls); + print $form->parse_html_template("admin/dbupgrade_footer"); } - print qq| - - - -|; - -} - -sub dbupdate { - $form->{"stylesheet"} = "lx-office-erp.css"; - $form->{"title"} = $main::locale->text("Dataset upgrade"); - $form->header(); - my $dbname = - join(" ", - map({ s/\s//g; s/^db//; $_; } - grep({ $form->{$_} } - split(/\s+/, $form->{"dbupdate"})))); - print($form->parse_html_template("dbupgrade/header", - { "dbname" => $dbname })); - - User->dbupdate(\%$form); - - print qq| -
- -| . $locale->text('Dataset updated!') . qq| - -
- -| . $locale->text("Continue") . qq||; - + print $form->parse_html_template("admin/dbupgrade_all_done"); } sub create_dataset { diff --git a/locale/de/admin b/locale/de/admin index a718e9653..47c4af013 100644 --- a/locale/de/admin +++ b/locale/de/admin @@ -3,14 +3,12 @@ $self->{texts} = { 'Add User' => 'Benutzer erfassen', 'Address' => 'Adresse', 'Administration' => 'Administration', - 'All Datasets up to date!' => 'Alle Datenbanken sind auf aktuellem Stand.', 'Attempt to call an undefined sub named \'%s\'' => 'Es wurde versucht, eine nicht definierte Unterfunktion namens \'%s\' aufzurufen.', 'Bin List' => 'Lagerliste', 'CANCELED' => 'Storniert', 'Cannot create Lock!' => 'System kann nicht gesperrt werden!', 'Change Admin Password' => 'Administratorpasswort ändern', 'Confirmation' => 'Auftragsbestätigung', - 'Continue' => 'Weiter', 'Create Dataset' => 'Datenbank anlegen', 'Credit Note' => 'Gutschrift', 'Customer Number' => 'Kundennummer', @@ -20,7 +18,6 @@ $self->{texts} = { 'Database Administration' => 'Datenbankadministration', 'Database User missing!' => 'Datenbankbenutzer fehlt!', 'Dataset missing!' => 'Datenbank fehlt!', - 'Dataset updated!' => 'Datenbank erneuert!', 'Dataset upgrade' => 'Datenbankaktualisierung', 'Delete Dataset' => 'Datenbank löschen', 'Dependency loop detected:' => 'Schleife in den Abhängigkeiten entdeckt:', @@ -77,7 +74,6 @@ $self->{texts} = { 'Storno Packing List' => 'Stornolieferschein', 'The \'tag\' field must only consist of alphanumeric characters or the carachters - _ ( )' => 'Das Feld \'tag\' darf nur aus alphanumerischen Zeichen und den Zeichen - _ ( ) bestehen.', 'The directory %s does not exist.' => 'Das Verzeichnis %s existiert nicht.', - 'The following Datasets need to be updated' => 'Folgende Datenbanken müssen aktualisiert werden', 'The login is missing.' => 'Das Login fehlt.', 'The passwords do not match.' => 'Die Passwörter stimmen nicht überein.', 'Trying to call a sub without a name' => 'Es wurde versucht, eine Unterfunktion ohne Namen aufzurufen.', diff --git a/locale/de/all b/locale/de/all index 8a5821272..fe8853332 100644 --- a/locale/de/all +++ b/locale/de/all @@ -128,6 +128,7 @@ $self->{texts} = { 'All Accounts' => 'Alle Konten', 'All Datasets up to date!' => 'Alle Datenbanken sind auf aktuellem Stand.', 'All changes in that file have been reverted.' => 'Alle Änderungen in dieser Datei wurden rückgängig gemacht.', + 'All database upgrades have been applied.' => 'Alle Datenbankupdates wurden eingespielt.', 'Amended Advance Turnover Tax Return' => 'Berichtigte Anmeldung', 'Amended Advance Turnover Tax Return (Nr. 10)' => 'Ist dies eine berichtigte Anmeldung? (Nr. 10/Zeile 15 Steuererklärung)', 'Amount' => 'Betrag', @@ -323,7 +324,6 @@ aktualisieren wollen?', 'Database update error:' => 'Fehler beim Datenbankupgrade:', 'Dataset' => 'Datenbank', 'Dataset missing!' => 'Datenbank fehlt!', - 'Dataset updated!' => 'Datenbank erneuert!', 'Dataset upgrade' => 'Datenbankaktualisierung', 'Date' => 'Datum', 'Date Format' => 'Datumsformat', @@ -699,6 +699,7 @@ gestartet', 'No Dataset selected!' => 'Keine Datenbank ausgewählt!', 'No Vendor was found matching the search parameters.' => 'Zu dem Suchbegriff wurde kein Händler gefunden', 'No customer has been selected yet.' => 'Es wurde noch kein Kunde ausgewählt.', + 'No datasets have been selected.' => 'Es wurden keine Datenbanken ausgewählt.', 'No employee was found matching the search parameters.' => 'Es wurde kein Angestellter gefunden, auf den die Suchparameter zutreffen.', 'No entries were found which had no unit assigned to them.' => 'Es wurden keine Einträge gefunden, denen keine Einheit zugeordnet war.', 'No licenses were found that match the search criteria.' => 'Es wurden keine Lizenzen gefunden, auf die die Suchkriterien zutreffen.', @@ -1123,6 +1124,7 @@ gestartet', 'Update Prices' => 'Preise aktualisieren', 'Update complete' => 'Update beendet.', 'Update prices' => 'Preise aktualisieren', + 'Update?' => 'Aktualisieren?', 'Updated' => 'Erneuert am', 'Use As Template' => 'Als Vorlage verwenden', 'Use Templates' => 'benutze Vorlagen', diff --git a/templates/webpages/admin/dbadmin_de.html b/templates/webpages/admin/dbadmin_de.html index 1ce19fa2c..7830c31b2 100644 --- a/templates/webpages/admin/dbadmin_de.html +++ b/templates/webpages/admin/dbadmin_de.html @@ -54,7 +54,7 @@
- + diff --git a/templates/webpages/admin/dbadmin_master.html b/templates/webpages/admin/dbadmin_master.html index e6c316e50..6e05c3c4f 100644 --- a/templates/webpages/admin/dbadmin_master.html +++ b/templates/webpages/admin/dbadmin_master.html @@ -54,7 +54,7 @@
- + diff --git a/templates/webpages/admin/dbupgrade_all_done_de.html b/templates/webpages/admin/dbupgrade_all_done_de.html new file mode 100644 index 000000000..d89f889f1 --- /dev/null +++ b/templates/webpages/admin/dbupgrade_all_done_de.html @@ -0,0 +1,19 @@ + +

Es wurden keine Datenbanken ausgewählt.

+ + + +
+ +

Alle Datenbankupdates wurden eingespielt.

+
+ +
+ + + + +
+ + + diff --git a/templates/webpages/admin/dbupgrade_all_done_master.html b/templates/webpages/admin/dbupgrade_all_done_master.html new file mode 100644 index 000000000..0b7127724 --- /dev/null +++ b/templates/webpages/admin/dbupgrade_all_done_master.html @@ -0,0 +1,19 @@ + +

No datasets have been selected.

+ + + +
+ +

All database upgrades have been applied.

+
+ +
+ + + + +
+ + + diff --git a/templates/webpages/admin/dbupgrade_all_header_de.html b/templates/webpages/admin/dbupgrade_all_header_de.html new file mode 100644 index 000000000..68c7ecaee --- /dev/null +++ b/templates/webpages/admin/dbupgrade_all_header_de.html @@ -0,0 +1,2 @@ + + diff --git a/templates/webpages/admin/dbupgrade_all_header_master.html b/templates/webpages/admin/dbupgrade_all_header_master.html new file mode 100644 index 000000000..68c7ecaee --- /dev/null +++ b/templates/webpages/admin/dbupgrade_all_header_master.html @@ -0,0 +1,2 @@ + + diff --git a/templates/webpages/admin/dbupgrade_footer_de.html b/templates/webpages/admin/dbupgrade_footer_de.html new file mode 100644 index 000000000..3d31bbf7e --- /dev/null +++ b/templates/webpages/admin/dbupgrade_footer_de.html @@ -0,0 +1 @@ +

...fertig

diff --git a/templates/webpages/admin/dbupgrade_footer_master.html b/templates/webpages/admin/dbupgrade_footer_master.html new file mode 100644 index 000000000..9ac4e8abb --- /dev/null +++ b/templates/webpages/admin/dbupgrade_footer_master.html @@ -0,0 +1 @@ +

...done

diff --git a/templates/webpages/admin/dbupgrade_header_de.html b/templates/webpages/admin/dbupgrade_header_de.html new file mode 100644 index 000000000..dff3423a2 --- /dev/null +++ b/templates/webpages/admin/dbupgrade_header_de.html @@ -0,0 +1 @@ +
Datenbankaktualisierung ()
diff --git a/templates/webpages/admin/dbupgrade_header_master.html b/templates/webpages/admin/dbupgrade_header_master.html new file mode 100644 index 000000000..b25c7bd5c --- /dev/null +++ b/templates/webpages/admin/dbupgrade_header_master.html @@ -0,0 +1 @@ +
Dataset upgrade ()
diff --git a/templates/webpages/admin/update_dataset_de.html b/templates/webpages/admin/update_dataset_de.html new file mode 100644 index 000000000..badb29032 --- /dev/null +++ b/templates/webpages/admin/update_dataset_de.html @@ -0,0 +1,55 @@ + + +

+ + + Alle Datenbanken sind auf aktuellem Stand. + + + +
+ +

Folgende Datenbanken müssen aktualisiert werden:

+ + + + + + + + + + + + + + + + + + + + + + + + + +
Aktualisieren?DatenbankTreiberDatenbankcomputerPortBenutzer
PostgreSQL
+ + + + + +
+ +
+ + + +
+ +
+ + + diff --git a/templates/webpages/admin/update_dataset_master.html b/templates/webpages/admin/update_dataset_master.html new file mode 100644 index 000000000..6e1acff03 --- /dev/null +++ b/templates/webpages/admin/update_dataset_master.html @@ -0,0 +1,55 @@ + + +

+ + + All Datasets up to date! + + + +
+ +

The following Datasets need to be updated:

+ + + + + + + + + + + + + + + + + + + + + + + + + +
Update?DatasetDriverHostPortUser
PostgreSQL
+ + + + + +
+ +
+ + + +
+ +
+ + + -- 2.20.1