From a74f9d57d972444f66f96497fbf9ce9ed91a86a2 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 30 Jun 2020 13:52:59 +0200 Subject: [PATCH] =?utf8?q?DBUpgrade-Mechanismus:=20umgekehrte=20Abh=C3=A4n?= =?utf8?q?gigkeiten=20mit=20=C2=BBrequired=5Fby=C2=AB=20angeben=20k=C3=B6n?= =?utf8?q?nen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Existierender Mechanismus mit »depends« sagt: die Scripte in »depends« müssen ausgeführt werden, bevor ich selber ausgeführt werde. Mit »required_by« kann man das Umgekehrte angeben: ich selber muss ausgeführt werden, bevor die Scripte in »required_by« ausgeführt werden können. Damit kann man z.B. kundenspezifische SQL-Upgrades schreiben, die erzwungen vor offiziellen SQL-Upgrades ausgeführt werden, ohne die offiziellen Upgrade-Dateien dafür verändern zu müssen. --- SL/DBUpgrade2.pm | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/SL/DBUpgrade2.pm b/SL/DBUpgrade2.pm index 3918ad40d..0b14eca5b 100644 --- a/SL/DBUpgrade2.pm +++ b/SL/DBUpgrade2.pm @@ -56,9 +56,10 @@ sub parse_dbupdate_controls { $file =~ s|.*/||; my $control = { - "priority" => 1000, - "depends" => [], - "locales" => [], + priority => 1000, + depends => [], + required_by => [], + locales => [], }; while () { @@ -71,8 +72,8 @@ sub parse_dbupdate_controls { my @fields = split(/\s*:\s*/, $_, 2); next unless (scalar(@fields) == 2); - if ($fields[0] eq "depends") { - push(@{$control->{"depends"}}, split(/\s+/, $fields[1])); + if ($fields[0] =~ m{^(?:depends|required_by)$}) { + push(@{$control->{$fields[0]}}, split(/\s+/, $fields[1])); } elsif ($fields[0] eq "locales") { push @{$control->{locales}}, $fields[1]; } else { @@ -100,7 +101,7 @@ sub parse_dbupdate_controls { delete @{$control}{qw(depth applied)}; - my @unknown_keys = grep { !m{^ (?: depends | description | file | ignore | locales | may_fail | priority | superuser_privileges | tag ) $}x } keys %{ $control }; + my @unknown_keys = grep { !m{^ (?: depends | required_by | description | file | ignore | locales | may_fail | priority | superuser_privileges | tag ) $}x } keys %{ $control }; if (@unknown_keys) { _control_error($form, $file_name, sprintf($locale->text("Unknown control fields: #1", join(' ', sort({ lc $a cmp lc $b } @unknown_keys))))); } @@ -114,6 +115,15 @@ sub parse_dbupdate_controls { close(IN); } + foreach my $name (keys %all_controls) { + my $control = $all_controls{$name}; + + foreach my $dependency (@{ delete $control->{required_by} }) { + _control_error($form, $control->{"file"}, sprintf($locale->text("Unknown dependency '%s'."), $dependency)) if (!defined($all_controls{$dependency})); + push @{ $all_controls{$dependency}->{depends} }, $name; + } + } + foreach my $control (values(%all_controls)) { foreach my $dependency (@{$control->{"depends"}}) { _control_error($form, $control->{"file"}, sprintf($locale->text("Unknown dependency '%s'."), $dependency)) if (!defined($all_controls{$dependency})); -- 2.20.1