From ae1b5cbad92eb30f55747d2aa986b9a0b7a433b5 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 4 Dec 2006 11:23:49 +0000 Subject: [PATCH] =?utf8?q?Die=20=C3=9Cbersetzungen=20f=C3=BCr=20die=20Perl?= =?utf8?q?-Datenbankupgradescripte=20werden=20nun=20in=20jeweils=20einer?= =?utf8?q?=20eigenen=20Datei=20gespeichert.=20Zus=C3=A4tzlich=20werden=20d?= =?utf8?q?irekt=20die=20beiden=20Variablen=20%dbup=5Fmyconfig=20und=20$dbu?= =?utf8?q?p=5Flocale=20zur=20Verf=C3=BCgung=20gestellt,=20damit=20nicht=20?= =?utf8?q?jedes=20Datenbankupgradescript=20sie=20selber=20anlegen=20muss.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/User.pm | 9 ++++ ...dbupgrade => Pg-upgrade-2.2.0.25-2.2.0.26} | 0 locale/de/locales.pl | 3 +- .../Pg-upgrade-2.2.0.25-2.2.0.26.pl | 48 ++++++------------- 4 files changed, 24 insertions(+), 36 deletions(-) rename locale/de/{dbupgrade => Pg-upgrade-2.2.0.25-2.2.0.26} (100%) diff --git a/SL/User.pm b/SL/User.pm index d756a2ac8..24774db20 100644 --- a/SL/User.pm +++ b/SL/User.pm @@ -409,6 +409,15 @@ sub process_perl_script { $dbh->begin_work(); + my %dbup_myconfig = (); + map({ $dbup_myconfig{$_} = $form->{$_}; } + qw(dbname dbuser dbpasswd dbhost dbport dbconnect)); + + my $nls_file = $filename; + $nls_file =~ s|.*/||; + $nls_file =~ s|.pl$||; + my $dbup_locale = Locale->new($main::language, $nls_file); + my $result = eval($contents); if (1 != $result) { diff --git a/locale/de/dbupgrade b/locale/de/Pg-upgrade-2.2.0.25-2.2.0.26 similarity index 100% rename from locale/de/dbupgrade rename to locale/de/Pg-upgrade-2.2.0.25-2.2.0.26 diff --git a/locale/de/locales.pl b/locale/de/locales.pl index 119dfe92b..36d0e4785 100755 --- a/locale/de/locales.pl +++ b/locale/de/locales.pl @@ -105,8 +105,7 @@ sub handle_file { } } - my $localefile = $dir eq $bindir ? $file : "dbupgrade"; - open FH, ">$localefile" or die "$! : $localefile"; + open FH, ">$file" or die "$! : $file"; print FH q|$self{texts} = { |; diff --git a/sql/Pg-upgrade/Pg-upgrade-2.2.0.25-2.2.0.26.pl b/sql/Pg-upgrade/Pg-upgrade-2.2.0.25-2.2.0.26.pl index 1d7f9a1d6..cf109b70c 100644 --- a/sql/Pg-upgrade/Pg-upgrade-2.2.0.25-2.2.0.26.pl +++ b/sql/Pg-upgrade/Pg-upgrade-2.2.0.25-2.2.0.26.pl @@ -4,12 +4,8 @@ die("This script cannot be run from the command line.") unless ($main::form); use SL::AM; -%dbup_myconfig = (); -map({ $dbup_myconfig{$_} = $main::form->{$_}; } - qw(dbname dbuser dbpasswd dbhost dbport dbconnect)); - sub mydberror { - my ($dbup_locale, $msg) = @_; + my ($msg) = @_; die($dbup_locale->text("Database update error:") . "
$msg
" . $DBI::errstr); } @@ -23,8 +19,6 @@ sub myshowerror { } sub update_units_add_unit { - my ($dbup_locale, $dbh) = @_; - my $form = $main::form; return 0 unless ($form->{"new_name"}); @@ -54,7 +48,7 @@ sub update_units_add_unit { "VALUES (?, ?, ?, ?)"; $dbh->do($query, undef, $form->{"new_name"}, $base_unit, $factor, $form->{"unit_type"}) || - mydberror($dbup_locale, $query . + mydberror($query . " ($form->{new_name}, $base_unit, $factor, $form->{unit_type})"); $dbh->commit(); $dbh->begin_work(); @@ -65,8 +59,6 @@ sub update_units_add_unit { } sub update_units_assign_units { - my ($dbup_locale, $dbh) = @_; - my ($query, $sth, @values); my $form = $main::form; @@ -79,7 +71,7 @@ sub update_units_assign_units { next unless ($form->{"new_unit_$i"} && $form->{"old_unit_$i"}); @values = ($form->{"new_unit_$i"}, lc($form->{"old_unit_$i"})); $sth->execute(@values) || - mydberror($dbup_locale, $query . " (" . join(", ", @values) . ")"); + mydberror($query . " (" . join(", ", @values) . ")"); } } @@ -89,8 +81,6 @@ sub update_units_assign_units { } sub update_units_assign_known { - my ($dbup_locale, $dbh) = @_; - my $form = $main::form; my %unit_name_mapping = ( @@ -109,12 +99,10 @@ sub update_units_assign_known { } $form->{"rowcount"} = scalar(keys(%unit_name_mapping)); - update_units_assign_units($dbup_locale, $dbh); + update_units_assign_units(); } sub update_units_steps_1_2 { - my ($dbup_locale, $dbh) = @_; - my (%unknown_dimension_units, %unknown_service_units); my $form = $main::form; @@ -135,7 +123,7 @@ sub update_units_steps_1_2 { " t.unit IN (SELECT name FROM units))"; } $sth = $dbh->prepare($query); - $sth->execute() || mydberror($dbup_locale, $query); + $sth->execute() || mydberror($query); while ($ref = $sth->fetchrow_hashref()) { if ($ref->{"inventory_accno_id"}) { @@ -191,8 +179,6 @@ sub update_units_steps_1_2 { } sub update_units_step_3 { - my ($dbup_locale, $dbh) = @_; - my $form = $main::form; my $query = "SELECT "; @@ -223,8 +209,6 @@ sub update_units_step_3 { } sub update_units_set_default { - my ($dbup_locale, $dbh) = @_; - my $form = $main::form; foreach my $table (qw(parts invoice orderitems rmaitems)) { @@ -244,7 +228,7 @@ sub update_units_set_default { "parts_id IN (SELECT id FROM parts WHERE (inventory_accno_id > 0))"; } - $dbh->do($query) || mydberror($dbup_locale, $query); + $dbh->do($query) || mydberror($query); if ($table eq "parts") { $query = "UPDATE $table SET unit = " . @@ -259,39 +243,35 @@ sub update_units_set_default { "WHERE (inventory_accno_id ISNULL) OR (inventory_accno_id = 0))"; } - $dbh->do($query) || mydberror($dbup_locale, $query); + $dbh->do($query) || mydberror($query); } } sub update_units { - my (@dbh) = @_; - my $form = $main::form; my $res; - my $dbup_locale = Locale->new($main::language, "dbupgrade"); - print($form->parse_html_template("dbupgrade/units_header")); if ($form->{"action2"} eq "add_unit") { - $res = update_units_add_unit($dbup_locale, $dbh); + $res = update_units_add_unit(); return $res if ($res); } elsif ($form->{"action2"} eq "assign_units") { - update_units_assign_units($dbup_locale, $dbh); + update_units_assign_units(); } elsif ($form->{"action2"} eq "set_default") { - update_units_set_default($dbup_locale, $dbh); + update_units_set_default(); } - update_units_assign_known($dbup_locale, $dbh); + update_units_assign_known(); - $res = update_units_steps_1_2($dbup_locale, $dbh); + $res = update_units_steps_1_2(); return $res if ($res); - return update_units_step_3($dbup_locale, $dbh); + return update_units_step_3(); } -update_units($dbh); +update_units(); -- 2.20.1