Revision 59fd42b8
Von Moritz Bunkus vor etwa 14 Jahren hinzugefügt
sql/Pg-upgrade2/auth_enable_sales_all_edit.pl | ||
---|---|---|
13 | 13 |
"<br>$msg<br>" . $DBI::errstr); |
14 | 14 |
} |
15 | 15 |
|
16 |
sub do_query { |
|
17 |
my ($query, $may_fail) = @_; |
|
16 |
sub do_update { |
|
17 |
my $dbh = $main::auth->dbconnect(); |
|
18 |
my $query = <<SQL; |
|
19 |
SELECT id |
|
20 |
FROM auth."group" |
|
21 |
WHERE NOT EXISTS( |
|
22 |
SELECT group_id |
|
23 |
FROM auth.group_rights |
|
24 |
WHERE (auth.group_rights.group_id = auth."group".id) |
|
25 |
AND (auth.group_rights."right" = 'sales_all_edit') |
|
26 |
) |
|
27 |
SQL |
|
28 |
|
|
29 |
my @group_ids = selectall_array_query($form, $dbh, $query); |
|
30 |
if (@group_ids) { |
|
31 |
$query = <<SQL; |
|
32 |
INSERT INTO auth.group_rights (group_id, "right", granted) |
|
33 |
VALUES (?, 'sales_all_edit', TRUE) |
|
34 |
SQL |
|
35 |
my $sth = prepare_query($form, $dbh, $query); |
|
36 |
|
|
37 |
foreach my $id (@group_ids) { |
|
38 |
do_statement($form, $sth, $query, $id); |
|
39 |
} |
|
18 | 40 |
|
19 |
if (!$dbh->do($query)) { |
|
20 |
mydberror($query) unless ($may_fail); |
|
21 |
$dbh->rollback(); |
|
22 |
$dbh->begin_work(); |
|
41 |
$sth->finish(); |
|
42 |
$dbh->commit(); |
|
23 | 43 |
} |
24 |
} |
|
25 | 44 |
|
26 |
sub do_update { |
|
27 |
my @queries; |
|
28 |
|
|
29 |
# do_query("ALTER TABLE project ADD PRIMARY KEY (id);", 1); |
|
30 |
# map({ do_query($_, 0); } @queries); |
|
31 |
# print "hieryy"; |
|
32 |
# print (Dumper($main::form)); |
|
33 |
my $dbh = $main::auth->dbconnect(); |
|
34 |
my $query = qq|SELECT distinct group_id from auth.user_group|; |
|
35 |
my $sth_all_groups = prepare_execute_query($form, $dbh, $query); |
|
36 |
while (my $hash_ref = $sth_all_groups->fetchrow_hashref()) { # Schleife |
|
37 |
push @queries, "INSERT INTO auth.group_rights (group_id, \"right\", granted) VALUES (" . $hash_ref->{group_id} . ", 'sales_all_edit', 't')"; |
|
38 |
} |
|
39 |
# if in doubt use brute force ;-) jb |
|
40 |
foreach my $query (@queries){ |
|
41 |
# print "hier:" . $query; |
|
42 |
my $dbh = $main::auth->dbconnect(); |
|
43 |
my $sth = prepare_query($form, $dbh, $query); |
|
44 |
do_statement($form,$sth,$query); |
|
45 |
$sth->finish(); |
|
46 |
$dbh ->commit(); |
|
47 |
} |
|
48 | 45 |
return 1; |
49 | 46 |
} |
50 | 47 |
|
Auch abrufbar als: Unified diff
DB-Upgrade-Script so modifiziert, dass es auch mehrfach auf ein und dieselbe Auth-DB ausgeführt werden kann