Revision 600c47b8
Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt
SL/DBUpgrade2/Base.pm | ||
---|---|---|
4 | 4 |
|
5 | 5 |
use parent qw(Rose::Object); |
6 | 6 |
|
7 |
use Carp; |
|
7 | 8 |
use English qw(-no_match_vars); |
9 |
use File::Basename (); |
|
10 |
use File::Copy (); |
|
11 |
use File::Path (); |
|
12 |
use List::MoreUtils qw(uniq); |
|
13 |
|
|
8 | 14 |
use Rose::Object::MakeMethods::Generic ( |
9 | 15 |
scalar => [ qw(dbh myconfig) ], |
10 | 16 |
); |
... | ... | |
64 | 70 |
return !$empty; |
65 | 71 |
} |
66 | 72 |
|
73 |
sub add_print_templates { |
|
74 |
my ($self, $src_dir, @files) = @_; |
|
75 |
|
|
76 |
$::lxdebug->message(LXDebug::DEBUG1(), "add_print_templates: src_dir $src_dir files " . join(' ', @files)); |
|
77 |
|
|
78 |
foreach (@files) { |
|
79 |
croak "File '${src_dir}/$_' does not exist" unless -f "${src_dir}/$_"; |
|
80 |
} |
|
81 |
|
|
82 |
my %users = $::auth->read_all_users; |
|
83 |
my @template_dirs = uniq map { $_ = $_->{templates}; s:/+$::; $_ } values %users; |
|
84 |
|
|
85 |
$::lxdebug->message(LXDebug::DEBUG1(), "add_print_templates: template_dirs " . join(' ', @template_dirs)); |
|
86 |
|
|
87 |
foreach my $src_file (@files) { |
|
88 |
foreach my $template_dir (@template_dirs) { |
|
89 |
my $dest_file = $template_dir . '/' . $src_file; |
|
90 |
|
|
91 |
if (-f $dest_file) { |
|
92 |
$::lxdebug->message(LXDebug::DEBUG1(), "add_print_templates: dest_file exists, skipping: ${dest_file}"); |
|
93 |
next; |
|
94 |
} |
|
95 |
|
|
96 |
my $dest_dir = File::Basename::dirname($dest_file); |
|
97 |
|
|
98 |
if ($dest_dir && !-d $dest_dir) { |
|
99 |
File::Path::make_path($dest_dir) or die "Cannot create directory '${dest_dir}': $!"; |
|
100 |
} |
|
101 |
|
|
102 |
File::Copy::copy($src_dir . '/' . $src_file, $dest_file) or die "Cannot copy '${src_dir}/${src_file}' to '${dest_file}': $!"; |
|
103 |
|
|
104 |
$::lxdebug->message(LXDebug::DEBUG1(), "add_print_templates: copied '${src_dir}/${src_file}' to '${dest_file}'"); |
|
105 |
} |
|
106 |
} |
|
107 |
|
|
108 |
return 1; |
|
109 |
} |
|
110 |
|
|
67 | 111 |
1; |
68 | 112 |
__END__ |
69 | 113 |
|
... | ... | |
105 | 149 |
|
106 | 150 |
=back |
107 | 151 |
|
108 |
|
|
109 | 152 |
=head1 FUNCTIONS |
110 | 153 |
|
111 | 154 |
=over 4 |
112 | 155 |
|
156 |
=item C<add_print_templates $source_dir, @files> |
|
157 |
|
|
158 |
Adds (copies) new print templates to existing users. All existing |
|
159 |
users in the authentication database are read. The listed C<@files> |
|
160 |
are copied to each user's configured templates directory preserving |
|
161 |
sub-directory structure (non-existing sub-directories will be |
|
162 |
created). If a template with the same name exists it will be skipped. |
|
163 |
|
|
164 |
The source file names must all be relative to the source directory |
|
165 |
C<$source_dir>. This way only the desired sub-directories are created |
|
166 |
in the users' template directories. Example: |
|
167 |
|
|
168 |
$self->add_print_templates( |
|
169 |
'templates/print/Standard', |
|
170 |
qw(receipt.tex common.sty images/background.png) |
|
171 |
); |
|
172 |
|
|
173 |
Let's assume a user's template directory is |
|
174 |
C<templates/big-money-inc>. The call above would trigger five actions: |
|
175 |
|
|
176 |
=over 2 |
|
177 |
|
|
178 |
=item 1. Create the directory C<templates/big-money-inc> if it doesn't |
|
179 |
exist. |
|
180 |
|
|
181 |
=item 2. Copy C<templates/print/Standard/receipt.tex> to |
|
182 |
C<templates/big-money-inc/receipt.tex> if there's no such file in that |
|
183 |
directory. |
|
184 |
|
|
185 |
=item 3. Copy C<templates/print/Standard/common.sty> to |
|
186 |
C<templates/big-money-inc/common.sty> if there's no such file in that |
|
187 |
directory. |
|
188 |
|
|
189 |
=item 4. Create the directory C<templates/big-money-inc/images> if it |
|
190 |
doesn't exist. |
|
191 |
|
|
192 |
=item 5. Copy C<templates/print/Standard/images/background.png> to |
|
193 |
C<templates/big-money-inc/images/background.png> if there's no such |
|
194 |
file in that directory. |
|
195 |
|
|
196 |
=back |
|
197 |
|
|
113 | 198 |
=item C<check_coa $coa_name> |
114 | 199 |
|
115 | 200 |
Returns trueish if the database uses the chart of accounts named |
Auch abrufbar als: Unified diff
Perl-Datenbankupgrades: Funktion add_print_templates() zum Hinzufügen neuer Druckvorlagen