Revision ae1b5cba
Von Moritz Bunkus vor etwa 18 Jahren hinzugefügt
SL/User.pm | ||
---|---|---|
409 | 409 |
|
410 | 410 |
$dbh->begin_work(); |
411 | 411 |
|
412 |
my %dbup_myconfig = (); |
|
413 |
map({ $dbup_myconfig{$_} = $form->{$_}; } |
|
414 |
qw(dbname dbuser dbpasswd dbhost dbport dbconnect)); |
|
415 |
|
|
416 |
my $nls_file = $filename; |
|
417 |
$nls_file =~ s|.*/||; |
|
418 |
$nls_file =~ s|.pl$||; |
|
419 |
my $dbup_locale = Locale->new($main::language, $nls_file); |
|
420 |
|
|
412 | 421 |
my $result = eval($contents); |
413 | 422 |
|
414 | 423 |
if (1 != $result) { |
locale/de/Pg-upgrade-2.2.0.25-2.2.0.26 | ||
---|---|---|
1 |
$self{texts} = { |
|
2 |
'A unit with this name does already exist.' => 'Eine Einheit mit diesem Namen existiert bereits.', |
|
3 |
'Database update error:' => 'Database update error:', |
|
4 |
'The base unit does not exist.' => 'Die Basiseinheit existiert nicht.', |
|
5 |
'The factor is missing.' => 'Der Faktor fehlt.', |
|
6 |
'The name is missing.' => 'Der Name fehlt.', |
|
7 |
'The unit has been saved.' => 'Die Einheit wurde gespeichert.', |
|
8 |
}; |
|
9 |
|
|
10 |
$self{subs} = { |
|
11 |
'mydberror' => 'mydberror', |
|
12 |
'myshowerror' => 'myshowerror', |
|
13 |
'update_units' => 'update_units', |
|
14 |
'update_units_add_unit' => 'update_units_add_unit', |
|
15 |
'update_units_assign_known' => 'update_units_assign_known', |
|
16 |
'update_units_assign_units' => 'update_units_assign_units', |
|
17 |
'update_units_set_default' => 'update_units_set_default', |
|
18 |
'update_units_step_3' => 'update_units_step_3', |
|
19 |
'update_units_steps_1_2' => 'update_units_steps_1_2', |
|
20 |
'einheit_hinzufügen' => 'add_unit', |
|
21 |
'einheiten_zuweisen' => 'assign_units', |
|
22 |
}; |
|
23 |
|
|
24 |
1; |
locale/de/dbupgrade | ||
---|---|---|
1 |
$self{texts} = { |
|
2 |
'A unit with this name does already exist.' => 'Eine Einheit mit diesem Namen existiert bereits.', |
|
3 |
'Database update error:' => 'Database update error:', |
|
4 |
'The base unit does not exist.' => 'Die Basiseinheit existiert nicht.', |
|
5 |
'The factor is missing.' => 'Der Faktor fehlt.', |
|
6 |
'The name is missing.' => 'Der Name fehlt.', |
|
7 |
'The unit has been saved.' => 'Die Einheit wurde gespeichert.', |
|
8 |
}; |
|
9 |
|
|
10 |
$self{subs} = { |
|
11 |
'mydberror' => 'mydberror', |
|
12 |
'myshowerror' => 'myshowerror', |
|
13 |
'update_units' => 'update_units', |
|
14 |
'update_units_add_unit' => 'update_units_add_unit', |
|
15 |
'update_units_assign_known' => 'update_units_assign_known', |
|
16 |
'update_units_assign_units' => 'update_units_assign_units', |
|
17 |
'update_units_set_default' => 'update_units_set_default', |
|
18 |
'update_units_step_3' => 'update_units_step_3', |
|
19 |
'update_units_steps_1_2' => 'update_units_steps_1_2', |
|
20 |
'einheit_hinzufügen' => 'add_unit', |
|
21 |
'einheiten_zuweisen' => 'assign_units', |
|
22 |
}; |
|
23 |
|
|
24 |
1; |
locale/de/locales.pl | ||
---|---|---|
105 | 105 |
} |
106 | 106 |
} |
107 | 107 |
|
108 |
my $localefile = $dir eq $bindir ? $file : "dbupgrade"; |
|
109 |
open FH, ">$localefile" or die "$! : $localefile"; |
|
108 |
open FH, ">$file" or die "$! : $file"; |
|
110 | 109 |
|
111 | 110 |
print FH q|$self{texts} = { |
112 | 111 |
|; |
sql/Pg-upgrade/Pg-upgrade-2.2.0.25-2.2.0.26.pl | ||
---|---|---|
4 | 4 |
|
5 | 5 |
use SL::AM; |
6 | 6 |
|
7 |
%dbup_myconfig = (); |
|
8 |
map({ $dbup_myconfig{$_} = $main::form->{$_}; } |
|
9 |
qw(dbname dbuser dbpasswd dbhost dbport dbconnect)); |
|
10 |
|
|
11 | 7 |
sub mydberror { |
12 |
my ($dbup_locale, $msg) = @_;
|
|
8 |
my ($msg) = @_; |
|
13 | 9 |
die($dbup_locale->text("Database update error:") . |
14 | 10 |
"<br>$msg<br>" . $DBI::errstr); |
15 | 11 |
} |
... | ... | |
23 | 19 |
} |
24 | 20 |
|
25 | 21 |
sub update_units_add_unit { |
26 |
my ($dbup_locale, $dbh) = @_; |
|
27 |
|
|
28 | 22 |
my $form = $main::form; |
29 | 23 |
|
30 | 24 |
return 0 unless ($form->{"new_name"}); |
... | ... | |
54 | 48 |
"VALUES (?, ?, ?, ?)"; |
55 | 49 |
$dbh->do($query, undef, $form->{"new_name"}, $base_unit, $factor, |
56 | 50 |
$form->{"unit_type"}) || |
57 |
mydberror($dbup_locale, $query .
|
|
51 |
mydberror($query . |
|
58 | 52 |
" ($form->{new_name}, $base_unit, $factor, $form->{unit_type})"); |
59 | 53 |
$dbh->commit(); |
60 | 54 |
$dbh->begin_work(); |
... | ... | |
65 | 59 |
} |
66 | 60 |
|
67 | 61 |
sub update_units_assign_units { |
68 |
my ($dbup_locale, $dbh) = @_; |
|
69 |
|
|
70 | 62 |
my ($query, $sth, @values); |
71 | 63 |
|
72 | 64 |
my $form = $main::form; |
... | ... | |
79 | 71 |
next unless ($form->{"new_unit_$i"} && $form->{"old_unit_$i"}); |
80 | 72 |
@values = ($form->{"new_unit_$i"}, lc($form->{"old_unit_$i"})); |
81 | 73 |
$sth->execute(@values) || |
82 |
mydberror($dbup_locale, $query . " (" . join(", ", @values) . ")");
|
|
74 |
mydberror($query . " (" . join(", ", @values) . ")"); |
|
83 | 75 |
} |
84 | 76 |
} |
85 | 77 |
|
... | ... | |
89 | 81 |
} |
90 | 82 |
|
91 | 83 |
sub update_units_assign_known { |
92 |
my ($dbup_locale, $dbh) = @_; |
|
93 |
|
|
94 | 84 |
my $form = $main::form; |
95 | 85 |
|
96 | 86 |
my %unit_name_mapping = ( |
... | ... | |
109 | 99 |
} |
110 | 100 |
$form->{"rowcount"} = scalar(keys(%unit_name_mapping)); |
111 | 101 |
|
112 |
update_units_assign_units($dbup_locale, $dbh);
|
|
102 |
update_units_assign_units(); |
|
113 | 103 |
} |
114 | 104 |
|
115 | 105 |
sub update_units_steps_1_2 { |
116 |
my ($dbup_locale, $dbh) = @_; |
|
117 |
|
|
118 | 106 |
my (%unknown_dimension_units, %unknown_service_units); |
119 | 107 |
|
120 | 108 |
my $form = $main::form; |
... | ... | |
135 | 123 |
" t.unit IN (SELECT name FROM units))"; |
136 | 124 |
} |
137 | 125 |
$sth = $dbh->prepare($query); |
138 |
$sth->execute() || mydberror($dbup_locale, $query);
|
|
126 |
$sth->execute() || mydberror($query); |
|
139 | 127 |
|
140 | 128 |
while ($ref = $sth->fetchrow_hashref()) { |
141 | 129 |
if ($ref->{"inventory_accno_id"}) { |
... | ... | |
191 | 179 |
} |
192 | 180 |
|
193 | 181 |
sub update_units_step_3 { |
194 |
my ($dbup_locale, $dbh) = @_; |
|
195 |
|
|
196 | 182 |
my $form = $main::form; |
197 | 183 |
|
198 | 184 |
my $query = "SELECT "; |
... | ... | |
223 | 209 |
} |
224 | 210 |
|
225 | 211 |
sub update_units_set_default { |
226 |
my ($dbup_locale, $dbh) = @_; |
|
227 |
|
|
228 | 212 |
my $form = $main::form; |
229 | 213 |
|
230 | 214 |
foreach my $table (qw(parts invoice orderitems rmaitems)) { |
... | ... | |
244 | 228 |
"parts_id IN (SELECT id FROM parts WHERE (inventory_accno_id > 0))"; |
245 | 229 |
} |
246 | 230 |
|
247 |
$dbh->do($query) || mydberror($dbup_locale, $query);
|
|
231 |
$dbh->do($query) || mydberror($query); |
|
248 | 232 |
|
249 | 233 |
if ($table eq "parts") { |
250 | 234 |
$query = "UPDATE $table SET unit = " . |
... | ... | |
259 | 243 |
"WHERE (inventory_accno_id ISNULL) OR (inventory_accno_id = 0))"; |
260 | 244 |
} |
261 | 245 |
|
262 |
$dbh->do($query) || mydberror($dbup_locale, $query);
|
|
246 |
$dbh->do($query) || mydberror($query); |
|
263 | 247 |
} |
264 | 248 |
} |
265 | 249 |
|
266 | 250 |
sub update_units { |
267 |
my (@dbh) = @_; |
|
268 |
|
|
269 | 251 |
my $form = $main::form; |
270 | 252 |
|
271 | 253 |
my $res; |
272 | 254 |
|
273 |
my $dbup_locale = Locale->new($main::language, "dbupgrade"); |
|
274 |
|
|
275 | 255 |
print($form->parse_html_template("dbupgrade/units_header")); |
276 | 256 |
|
277 | 257 |
if ($form->{"action2"} eq "add_unit") { |
278 |
$res = update_units_add_unit($dbup_locale, $dbh);
|
|
258 |
$res = update_units_add_unit(); |
|
279 | 259 |
return $res if ($res); |
280 | 260 |
|
281 | 261 |
} elsif ($form->{"action2"} eq "assign_units") { |
282 |
update_units_assign_units($dbup_locale, $dbh);
|
|
262 |
update_units_assign_units(); |
|
283 | 263 |
|
284 | 264 |
} elsif ($form->{"action2"} eq "set_default") { |
285 |
update_units_set_default($dbup_locale, $dbh);
|
|
265 |
update_units_set_default(); |
|
286 | 266 |
|
287 | 267 |
} |
288 | 268 |
|
289 |
update_units_assign_known($dbup_locale, $dbh);
|
|
269 |
update_units_assign_known(); |
|
290 | 270 |
|
291 |
$res = update_units_steps_1_2($dbup_locale, $dbh);
|
|
271 |
$res = update_units_steps_1_2(); |
|
292 | 272 |
return $res if ($res); |
293 | 273 |
|
294 |
return update_units_step_3($dbup_locale, $dbh);
|
|
274 |
return update_units_step_3(); |
|
295 | 275 |
} |
296 | 276 |
|
297 |
update_units($dbh); |
|
277 |
update_units(); |
Auch abrufbar als: Unified diff
Die Übersetzungen für die Perl-Datenbankupgradescripte werden nun in jeweils einer eigenen Datei gespeichert. Zusätzlich werden direkt die beiden Variablen %dbup_myconfig und $dbup_locale zur Verfügung gestellt, damit nicht jedes Datenbankupgradescript sie selber anlegen muss.