X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=scripts%2Frose_auto_create_model.pl;h=14e4ba0fcd5a97cf73f3d98581e95b3b8f038c91;hb=efef8dbd0df5877d736cf25dcb56a15e0f3037be;hp=6b6db0a8c31a6cce714c4f8b1f8042899c6a2361;hpb=7dce1e6b79376cb9fd7966051210b0e099f97c9c;p=kivitendo-erp.git diff --git a/scripts/rose_auto_create_model.pl b/scripts/rose_auto_create_model.pl index 6b6db0a8c..14e4ba0fc 100755 --- a/scripts/rose_auto_create_model.pl +++ b/scripts/rose_auto_create_model.pl @@ -31,7 +31,6 @@ my %blacklist = SL::DB::Helper::Mappings->get_blacklist; my %package_names = SL::DB::Helper::Mappings->get_package_names; our $form; -our $cgi; our $auth; our %lx_office_conf; @@ -56,13 +55,13 @@ sub setup { usage(); } - $::lxdebug = LXDebug->new(); + $::lxdebug = LXDebug->new(); $::locale = Locale->new("de"); $::form = new Form; - $::cgi = new CGI(''); $::auth = SL::Auth->new(); - $::user = User->new($login); - %::myconfig = $auth->read_user($login); + $::user = User->new(login => $login); + %::myconfig = $auth->read_user(login => $login); + $::request = { cgi => CGI->new({}) }; $form->{script} = 'rose_meta_data.pl'; $form->{login} = $login; @@ -129,13 +128,16 @@ CODE my $file_exists = -f $meta_file; if ($file_exists) { my $old_size = -s $meta_file; - my $old_md5 = md5_hex(do { local(@ARGV, $/) = ($meta_file); <> }); + my $orig_file = do { local(@ARGV, $/) = ($meta_file); <> }; + my $old_md5 = md5_hex($orig_file); my $new_size = length $full_definition; my $new_md5 = md5_hex($full_definition); if ($old_size == $new_size && $old_md5 == $new_md5) { notice("No changes in $meta_file, skipping.") if $config{verbose}; return; } + + show_diff(\$orig_file, \$full_definition) if $config{show_diff}; } if (!$config{nocommit}) { @@ -158,12 +160,13 @@ CODE sub parse_args { my ($options) = @_; GetOptions( - 'login|user=s' => \ my $login, - all => \ my $all, - sugar => \ my $sugar, - 'no-commit' => \ my $nocommit, - help => sub { pod2usage(verbose => 99, sections => 'NAME|SYNOPSIS|OPTIONS') }, - verbose => \ my $verbose, + '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, + diff => \ my $diff, ); $options->{login} = $login if $login; @@ -171,6 +174,29 @@ sub parse_args { $options->{all} = $all; $options->{nocommit} = $nocommit; $options->{verbose} = $verbose; + + if ($diff) { + if (eval { require Text::Diff; 1 }) { + $options->{show_diff} = 1; + } else { + error('Could not load Text::Diff. Sorry, no diffs for you.'); + } + } +} + +sub show_diff { + my ($text_a, $text_b) = @_; + + my %colors = ( + '+' => 'green', + '-' => 'red', + ); + + Text::Diff::diff($text_a, $text_b, { OUTPUT => sub { + for (split /\n/, $_[0]) { + print colored($_, $colors{substr($_, 0, 1)}), $/; + } + }}); } sub usage { @@ -268,12 +294,19 @@ database connection, and the piece of mind that comes from knowing that your class is stable, and won't change behind your back in response to an "action at a distance" (i.e., a database schema update).> -Unfortunately this ready easier than it is, since classes need to get in the -right package and directory, certain stuff need to be adjusted and table names +Unfortunately this reads easier than it is, since classes need to go into the +right package and directory, certain stuff needs to be adjusted and table names need to be translated into their class names. This script will wrap all that behind a few simple options. -In the most basic version, just give it a login and +In the most basic version, just give it a login and a table name, and it will +load the schema information for this table and create the appropriate class +files, or update them if already present. + +Each table has two associated files. A C class, which is +a perl version of the schema definition, and a C class file. The +first one will be updated if the schema changes, the second one will only be +created if it does not exist. =head1 OPTIONS @@ -297,9 +330,15 @@ 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 -actually modify any files. +actually modify any file. + +=item C<--diff> + +Displays diff for selected file, if file is present and newer file is +different. Beware, does not imply C<--no-commit>. =item C<--help, -h>