Revision 347f2cff
Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt
sql/Pg-upgrade2/umstellung_eur.pl | ||
---|---|---|
1 | 1 |
# @tag: umstellung_eur |
2 | 2 |
# @description: Variable eur umstellen: bitte in doc/dokumentation.pdf das entsprechende Kapitel zur Konfiguration von EUR lesen |
3 | 3 |
# @depends: release_2_6_3 |
4 |
# @charset: utf-8 |
|
5 |
|
|
6 |
# this script relies on $eur still being set in kivitendo.conf, and the |
|
7 |
# variable available in $::lx_office_conf{system}->{eur} |
|
4 |
package SL::DBUpgrade2::umstellung_eur; |
|
8 | 5 |
|
6 |
use strict; |
|
9 | 7 |
use utf8; |
10 |
#use strict; |
|
11 |
use Data::Dumper; |
|
12 |
die("This script cannot be run from the command line.") unless ($main::form); |
|
13 |
|
|
14 |
sub mydberror { |
|
15 |
my ($msg) = @_; |
|
16 |
die($dbup_locale->text("Database update error:") . |
|
17 |
"<br>$msg<br>" . $DBI::errstr); |
|
18 |
} |
|
19 | 8 |
|
20 |
sub do_query { |
|
21 |
my ($query, $may_fail) = @_; |
|
9 |
use parent qw(SL::DBUpgrade2::Base); |
|
22 | 10 |
|
23 |
if (!$dbh->do($query)) { |
|
24 |
mydberror($query) unless ($may_fail); |
|
25 |
$dbh->rollback(); |
|
26 |
$dbh->begin_work(); |
|
27 |
} |
|
28 |
} |
|
11 |
# this script relies on $eur still being set in kivitendo.conf, and the |
|
12 |
# variable available in $::lx_office_conf{system}->{eur} |
|
29 | 13 |
|
30 |
sub do_update { |
|
14 |
sub run { |
|
15 |
my ($self) = @_; |
|
31 | 16 |
|
32 | 17 |
# check if accounting_method has already been set (new database), if so return |
33 | 18 |
# only set variables according to eur for update of existing database |
... | ... | |
35 | 20 |
|
36 | 21 |
foreach my $column (qw(accounting_method inventory_system profit_determination)) { |
37 | 22 |
# this query will fail if columns already exist (new database) |
38 |
do_query(qq|ALTER TABLE defaults ADD COLUMN ${column} TEXT|, 1);
|
|
23 |
$self->db_query(qq|ALTER TABLE defaults ADD COLUMN ${column} TEXT|, 1);
|
|
39 | 24 |
} |
40 | 25 |
|
41 | 26 |
my $accounting_method; |
... | ... | |
65 | 50 |
my $update_eur = "UPDATE defaults set accounting_method = '$accounting_method' where accounting_method is null;" . |
66 | 51 |
"UPDATE defaults set inventory_system = '$inventory_system' where inventory_system is null; " . |
67 | 52 |
"UPDATE defaults set profit_determination = '$profit_determination' where profit_determination is null;"; |
68 |
do_query($update_eur);
|
|
53 |
$self->db_query($update_eur);
|
|
69 | 54 |
|
70 | 55 |
return 1; |
71 | 56 |
} |
72 | 57 |
|
73 |
return do_update(); |
|
74 |
|
|
58 |
1; |
Auch abrufbar als: Unified diff
Perl-Datenbank-Upgradescripte auf Objektorientierung & strict umgestellt