Die Funktion Form::parse_html_template2() in Form::parse_html_template() umbenannt...
[kivitendo-erp.git] / sql / Pg-upgrade / Pg-upgrade-2.2.0.37-2.2.0.38.pl
1 #!/usr/bin/perl
2
3 # Upgrade von Vorlagen
4
5 die("This script cannot be run from the command line.") unless ($main::form);
6
7 use File::Copy;
8
9 sub update_templates {
10   local *IN;
11
12   if (!open(IN, "users/members")) {
13     die($dbup_locale->text("Could not open the file users/members."));
14   }
15
16   my %all_template_dirs;
17   while (<IN>) {
18     chomp();
19     $all_template_dirs{$1} = 1 if (/^templates=(.*)/);
20   }
21   close(IN);
22
23   my @new_templates;
24
25   foreach my $raw (@_) {
26     $raw =~ /^.*?-(.*)/;
27     push(@new_templates, { "source" => "templates/$raw",
28                            "destination" => $1 });
29   }
30
31   my @warnings;
32
33   foreach my $dir (keys(%all_template_dirs)) {
34     foreach my $template (@new_templates) {
35       my $destination = $dir . "/" . $template->{"destination"};
36       if (-f $destination) {
37         if (!rename($destination, $destination . ".bak")) {
38           push(@warnings, sprintf($dbup_locale->text("Could not rename %s to %s. Reason: %s"),
39                                   $destination, $destination . ".bak", $!));
40         }
41       }
42       if (!copy($template->{"source"}, $destination)) {
43         push(@warnings, sprintf($dbup_locale->text("Could not copy %s to %s. Reason: %s"),
44                                 $template->{"source"}, $destination . ".bak", $!));
45       }
46     }
47   }
48
49   if (@warnings) {
50     @warnings = map(+{ "message" => $_ }, @warnings);
51     print($form->parse_html_template("dbupgrade/update_templates_warnings", { "WARNINGS" => \@warnings }));
52   }
53
54   return 1;
55 }
56
57 sub do_update {
58   update_templates("German-winston.xml",
59                    "German-taxbird.txb",
60                    "German-credit_note.tex",
61                    "German-zahlungserinnerung.tex");
62 }
63
64 return do_update();