Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision ce30a8c3

Von Moritz Bunkus vor etwa 18 Jahren hinzugefügt

  • ID ce30a8c3009f132b5a86d84e578bf56cc7897881
  • Vorgänger 6534db92
  • Nachfolger 1cd7d05f

Datenbankupgradescripte dürfen keine Funktionen aus den Lx-Office-Modulen benutzen.

Unterschiede anzeigen:

sql/Pg-upgrade/Pg-upgrade-2.2.0.25-2.2.0.26.pl
4 4

  
5 5
die("This script cannot be run from the command line.") unless ($main::form);
6 6

  
7
use SL::AM;
8

  
9 7
sub mydberror {
10 8
  my ($msg) = @_;
11 9
  die($dbup_locale->text("Database update error:") .
......
20 18
  return 2;
21 19
}
22 20

  
21
sub get_base_unit {
22
  my ($units, $unit_name, $factor) = @_;
23

  
24
  $factor = 1 unless ($factor);
25

  
26
  my $unit = $units->{$unit_name};
27

  
28
  if (!defined($unit) || !$unit->{"base_unit"} ||
29
      ($unit_name eq $unit->{"base_unit"})) {
30
    return ($unit_name, $factor);
31
  }
32

  
33
  return get_base_unit($units, $unit->{"base_unit"}, $factor * $unit->{"factor"});
34
}
35

  
36
sub retrieve_units {
37
  my ($myconfig, $form, $type, $prefix) = @_;
38

  
39
  my $query = "SELECT *, base_unit AS original_base_unit FROM units";
40
  my @values;
41
  if ($type) {
42
    $query .= " WHERE (type = ?)";
43
    @values = ($type);
44
  }
45

  
46
  my $sth = $dbh->prepare($query);
47
  $sth->execute(@values) || $form->dberror($query . " (" . join(", ", @values) . ")");
48

  
49
  my $units = {};
50
  while (my $ref = $sth->fetchrow_hashref()) {
51
    $units->{$ref->{"name"}} = $ref;
52
  }
53
  $sth->finish();
54

  
55
  my $query_lang = "SELECT id, template_code FROM language ORDER BY description";
56
  $sth = $dbh->prepare($query_lang);
57
  $sth->execute() || $form->dberror($query_lang);
58
  my @languages;
59
  while ($ref = $sth->fetchrow_hashref()) {
60
    push(@languages, $ref);
61
  }
62
  $sth->finish();
63

  
64
  foreach my $unit (values(%{$units})) {
65
    ($unit->{"${prefix}base_unit"}, $unit->{"${prefix}factor"}) = get_base_unit($units, $unit->{"name"});
66
  }
67

  
68
  return $units;
69
}
70

  
71
sub unit_select_data {
72
  my ($units, $selected, $empty_entry) = @_;
73

  
74
  my $select = [];
75

  
76
  if ($empty_entry) {
77
    push(@{$select}, { "name" => "", "base_unit" => "", "factor" => "", "selected" => "" });
78
  }
79

  
80
  foreach my $unit (sort({ lc($a) cmp lc($b) } keys(%{$units}))) {
81
    push(@{$select}, { "name" => $unit,
82
                       "base_unit" => $units->{$unit}->{"base_unit"},
83
                       "factor" => $units->{$unit}->{"factor"},
84
                       "selected" => ($unit eq $selected) ? "selected" : "" });
85
  }
86

  
87
  return $select;
88
}
89

  
23 90
sub update_units_add_unit {
24 91
  my $form = $main::form;
25 92

  
......
27 94

  
28 95
  return myshowerror($dbup_locale->text("The name is missing."))
29 96
    if ($form->{"new_name"} eq "");
30
  my $units = AM->retrieve_units(\%dbup_myconfig, $form);
97
  my $units = retrieve_units(\%dbup_myconfig, $form);
31 98
  return myshowerror($dbup_locale->text("A unit with this name does already exist."))
32 99
    if ($units->{$form->{"new_name"}});
33
  $units = AM->retrieve_units(\%dbup_myconfig, $form, $form->{"unit_type"});
100
  $units = retrieve_units(\%dbup_myconfig, $form, $form->{"unit_type"});
34 101

  
35 102
  my ($base_unit, $factor);
36 103
  if ($form->{"new_base_unit"}) {
......
145 212
  }
146 213

  
147 214
  if (scalar(keys(%unknown_dimension_units)) != 0) {
148
    my $units = AM->retrieve_units(\%dbup_myconfig, $form, "dimension");
149
    my $ddbox = AM->unit_select_data($units, undef, 1);
215
    my $units = retrieve_units(\%dbup_myconfig, $form, "dimension");
216
    my $ddbox = unit_select_data($units, undef, 1);
150 217

  
151 218
    my @unknown_parts;
152 219
    map({ push(@unknown_parts, { "name" => $_, "NEW_UNITS" => $ddbox }); }
......
164 231
  }
165 232

  
166 233
  if (scalar(keys(%unknown_service_units)) != 0) {
167
    my $units = AM->retrieve_units(\%dbup_myconfig, $form, "service");
168
    my $ddbox = AM->unit_select_data($units, undef, 1);
234
    my $units = retrieve_units(\%dbup_myconfig, $form, "service");
235
    my $ddbox = unit_select_data($units, undef, 1);
169 236

  
170 237
    my @unknown_services;
171 238
    map({ push(@unknown_services, { "name" => $_, "NEW_UNITS" => $ddbox }); }
......
197 264
  my ($has_unassigned) = $dbh->selectrow_array($query);
198 265

  
199 266
  if ($has_unassigned) {
200
    my $dimension_units = AM->retrieve_units(\%dbup_myconfig, $form,
267
    my $dimension_units = retrieve_units(\%dbup_myconfig, $form,
201 268
                                             "dimension");
202
    my $dimension_ddbox = AM->unit_select_data($dimension_units);
269
    my $dimension_ddbox = unit_select_data($dimension_units);
203 270

  
204
    my $service_units = AM->retrieve_units(\%dbup_myconfig, $form, "service");
205
    my $service_ddbox = AM->unit_select_data($service_units);
271
    my $service_units = retrieve_units(\%dbup_myconfig, $form, "service");
272
    my $service_ddbox = unit_select_data($service_units);
206 273

  
207 274
    print($form->parse_html_template("dbupgrade/units_set_default",
208 275
                                     { "DIMENSION_DDBOX" => $dimension_ddbox,

Auch abrufbar als: Unified diff