X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=scripts%2Frose_auto_create_model.pl;h=1850f4599a511c7754d67cd4c304adb8b175b0ba;hb=56b91fb4030432fde4159c11a0ca97a7571535f3;hp=14e4ba0fcd5a97cf73f3d98581e95b3b8f038c91;hpb=e03763d69fe89fffd6a3bde4fa144e7fa27fbd98;p=kivitendo-erp.git diff --git a/scripts/rose_auto_create_model.pl b/scripts/rose_auto_create_model.pl index 14e4ba0fc..1850f4599 100755 --- a/scripts/rose_auto_create_model.pl +++ b/scripts/rose_auto_create_model.pl @@ -44,6 +44,18 @@ our $meta_path = "SL/DB/MetaSetup"; my %config; +our %foreign_key_name_map = ( + oe => { payment => 'payment_terms', }, + ar => { payment => 'payment_terms', }, + ap => { payment => 'payment_terms', }, + + orderitems => { parts => 'part', trans => 'order', }, + delivery_order_items => { parts => 'part' }, + invoice => { parts => 'part' }, + + periodic_invoices_configs => { oe => 'order' }, +); + sub setup { SL::LxOfficeConf->read; @@ -81,7 +93,7 @@ sub process_table { my $file = "SL/DB/${package}.pm"; $schema = <meta->schema('$schema'); +__PACKAGE__->meta->schema('$schema'); CODE my $definition = eval <meta->table('$table'); -$schema + $schema __PACKAGE__->meta->auto_initialize; __PACKAGE__->meta->perl_class_definition(indent => 2); # , braces => 'bsd' @@ -103,6 +115,11 @@ CODE } $definition =~ s/::AUTO::/::/g; + + while (my ($auto_generated_name, $desired_name) = each %{ $foreign_key_name_map{$table} || {} }) { + $definition =~ s/( foreign_keys \s*=> \s*\[ .* ^\s+ ) ${auto_generated_name} \b/${1}${desired_name}/msx; + } + my $full_definition = <meta->make_manager_class; 1; @@ -162,7 +180,6 @@ sub parse_args { GetOptions( 'login|user=s' => \ my $login, all => \ my $all, - sugar => \ my $sugar, 'no-commit|dry-run' => \ my $nocommit, help => sub { pod2usage(verbose => 99, sections => 'NAME|SYNOPSIS|OPTIONS') }, verbose => \ my $verbose, @@ -170,7 +187,6 @@ sub parse_args { ); $options->{login} = $login if $login; - $options->{sugar} = $sugar; $options->{all} = $all; $options->{nocommit} = $nocommit; $options->{verbose} = $verbose; @@ -205,17 +221,16 @@ sub usage { sub make_tables { my @tables; - if ($config{all} || $config{sugar}) { - my ($type, $prefix) = $config{sugar} ? ('SUGAR', 'sugar_') : ('LXOFFICE', ''); - my $db = SL::DB::create(undef, $type); - @tables = - map { $package_names{$type}->{$_} ? "$_=" . $package_names{$type}->{$_} : $prefix ? "$_=$prefix$_" : $_ } - grep { my $table = $_; !any { $_ eq $table } @{ $blacklist{$type} } } + if ($config{all}) { + my $db = SL::DB::create(undef, 'LXOFFICE'); + @tables = + map { $package_names{LXOFFICE}->{$_} ? "$_=" . $package_names{LXOFFICE}->{$_} : $_ } + grep { my $table = $_; !any { $_ eq $table } @{ $blacklist{LXOFFICE} } } $db->list_tables; } elsif (@ARGV) { @tables = @ARGV; } else { - error("You specified neither --sugar nor --all nor any specific tables."); + error("You specified neither --all nor any specific tables."); usage(); } @@ -249,12 +264,12 @@ __END__ =head1 NAME -rose_auto_create_model - mana Rose::DB::Object classes for Lx-Office +rose_auto_create_model - mana Rose::DB::Object classes for kivitendo =head1 SYNOPSIS scripts/rose_create_model.pl --login login table1[=package1] [table2[=package2] ...] - scripts/rose_create_model.pl --login login [--all|-a] [--sugar|-s] + scripts/rose_create_model.pl --login login [--all|-a] # updates all models scripts/rose_create_model.pl --login login --all @@ -324,12 +339,8 @@ C. If that too is not found, an error is thrown. Process all tables from the database. Only those that are blacklistes in L are excluded. -=item C<--sugar, -s> - -Process tables in sugar schema instead of standard schema. Rarely useful unless -you debug schema awareness of the RDBO layer. - =item C<--no-commit, -n> + =item C<--dry-run> Do not write back generated files. This will do everything as usual but not