Revision b946ca81
Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt
scripts/rose_auto_create_model.pl | ||
---|---|---|
13 | 13 |
use Digest::MD5 qw(md5_hex); |
14 | 14 |
use English qw( -no_match_vars ); |
15 | 15 |
use Getopt::Long; |
16 |
use List::MoreUtils qw(any);
|
|
16 |
use List::MoreUtils qw(none);
|
|
17 | 17 |
use Pod::Usage; |
18 | 18 |
use Term::ANSIColor; |
19 | 19 |
|
... | ... | |
85 | 85 |
} |
86 | 86 |
|
87 | 87 |
sub process_table { |
88 |
my @spec = split(/=/, shift, 2);
|
|
88 |
my @spec = @_;
|
|
89 | 89 |
my $table = $spec[0]; |
90 | 90 |
my $schema = ''; |
91 | 91 |
($schema, $table) = split(m/\./, $table) if $table =~ m/\./; |
... | ... | |
287 | 287 |
my @tables; |
288 | 288 |
if ($config{all}) { |
289 | 289 |
my $db = SL::DB::create(undef, 'KIVITENDO'); |
290 |
@tables = |
|
291 |
map { $package_names{KIVITENDO}->{$_} ? "$_=" . $package_names{KIVITENDO}->{$_} : $_ } |
|
292 |
grep { my $table = $_; !any { $_ eq $table } @{ $blacklist{KIVITENDO} } } |
|
293 |
$db->list_tables; |
|
290 |
@tables = grep { my $table = $_; none { $_ eq $table } @{ $blacklist{KIVITENDO} } } $db->list_tables; |
|
291 |
|
|
294 | 292 |
} elsif (@ARGV) { |
295 | 293 |
@tables = @ARGV; |
296 | 294 |
} else { |
... | ... | |
313 | 311 |
setup(); |
314 | 312 |
my @tables = make_tables(); |
315 | 313 |
|
316 |
for my $table (@tables) { |
|
317 |
# add default model name unless model name is given or no defaults exists |
|
318 |
$table .= '=' . $package_names{KIVITENDO}->{lc $table} if $table !~ /=/ && $package_names{KIVITENDO}->{lc $table}; |
|
319 |
|
|
320 |
process_table($table); |
|
314 |
my @unknown_tables = grep { !$package_names{KIVITENDO}->{$_} } @tables; |
|
315 |
if (@unknown_tables) { |
|
316 |
error("The following tables do not have entries in \%SL::DB::Helper::Mappings::kivitendo_package_names: " . join(' ', sort @unknown_tables)); |
|
317 |
exit 1; |
|
321 | 318 |
} |
322 | 319 |
|
320 |
process_table($_, $package_names{KIVITENDO}->{$_}) for @tables; |
|
321 |
|
|
323 | 322 |
1; |
324 | 323 |
|
325 | 324 |
__END__ |
... | ... | |
332 | 331 |
|
333 | 332 |
=head1 SYNOPSIS |
334 | 333 |
|
335 |
scripts/rose_create_model.pl --client name-or-id table1[=package1] [table2[=package2] ...]
|
|
334 |
scripts/rose_create_model.pl --client name-or-id table1 [table2 ...]
|
|
336 | 335 |
scripts/rose_create_model.pl --client name-or-id [--all|-a] |
337 | 336 |
|
338 | 337 |
# updates all models |
... | ... | |
382 | 381 |
load the schema information for this table and create the appropriate class |
383 | 382 |
files, or update them if already present. |
384 | 383 |
|
385 |
Each table has two associated files. A C<SL::DB::MetaSetup::*> class, which is |
|
386 |
a perl version of the schema definition, and a C<SL::DB::*> class file. The |
|
387 |
first one will be updated if the schema changes, the second one will only be |
|
388 |
created if it does not exist. |
|
384 |
Each table has three associated files. A C<SL::DB::MetaSetup::*> |
|
385 |
class, which is a perl version of the schema definition, a |
|
386 |
C<SL::DB::*> class file and a C<SL::DB::Manager::*> manager class |
|
387 |
file. The first one will be updated if the schema changes, the second |
|
388 |
and third ones will only be created if it they do not exist. |
|
389 | 389 |
|
390 | 390 |
=head1 OPTIONS |
391 | 391 |
|
... | ... | |
433 | 433 |
|
434 | 434 |
=head1 AUTHOR |
435 | 435 |
|
436 |
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>, |
|
436 | 437 |
Sven Schöling E<lt>s.schoeling@linet-services.deE<gt> |
437 | 438 |
|
438 | 439 |
=cut |
Auch abrufbar als: Unified diff
rose_auto_create_model: auf Eintrag in %kivitendo_package_names bestehen
Das Script prüft nun immer (sowohl im Modus mit "--all" als auch bei
explizit angegebenen Tabellennamen), ob es für eine Tabelle einen
Eintrag in %SL::DB::Helper::Mappings::kivitendo_package_names gibt und
nutzt diese. Die Syntax "table=package" wird nicht mehr unterstützt.