Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision ae1b5cba

Von Moritz Bunkus vor etwa 18 Jahren hinzugefügt

  • ID ae1b5cbad92eb30f55747d2aa986b9a0b7a433b5
  • Vorgänger 824d0673
  • Nachfolger 89c9d0aa

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.

Unterschiede anzeigen:

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