60 |
60 |
|
61 |
61 |
SL::LxOfficeConf->read;
|
62 |
62 |
|
63 |
|
my $login = $config{login} || $::lx_office_conf{devel}{login};
|
|
63 |
my $client = $config{client} || $::lx_office_conf{devel}{client};
|
64 |
64 |
|
65 |
|
if (!$login) {
|
66 |
|
error("No login found in config. Please provide a login:");
|
|
65 |
if (!$client) {
|
|
66 |
error("No client found in config. Please provide a client:");
|
67 |
67 |
usage();
|
68 |
68 |
}
|
69 |
69 |
|
70 |
70 |
$::lxdebug = LXDebug->new();
|
71 |
71 |
$::locale = Locale->new("de");
|
72 |
72 |
$::form = new Form;
|
73 |
|
$::auth = SL::Auth->new();
|
74 |
|
$::user = User->new(login => $login);
|
75 |
|
%::myconfig = $auth->read_user(login => $login);
|
76 |
|
$::request = { cgi => CGI->new({}) };
|
77 |
73 |
$form->{script} = 'rose_meta_data.pl';
|
78 |
|
$form->{login} = $login;
|
|
74 |
$::auth = SL::Auth->new();
|
79 |
75 |
|
80 |
|
map { $form->{$_} = $::myconfig{$_} } qw(stylesheet charset);
|
|
76 |
if (!$::auth->set_client($client)) {
|
|
77 |
error("No client with ID or name '$client' found in config. Please provide a client:");
|
|
78 |
usage();
|
|
79 |
}
|
81 |
80 |
|
82 |
81 |
mkdir $meta_path unless -d $meta_path;
|
83 |
82 |
}
|
... | ... | |
92 |
91 |
my $meta_file = "${meta_path}/${package}.pm";
|
93 |
92 |
my $file = "SL/DB/${package}.pm";
|
94 |
93 |
|
95 |
|
$schema = <<CODE if $schema;
|
|
94 |
my $schema_str = $schema ? <<CODE : '';
|
96 |
95 |
__PACKAGE__->meta->schema('$schema');
|
97 |
96 |
CODE
|
98 |
97 |
|
... | ... | |
102 |
101 |
use base qw(SL::DB::Object);
|
103 |
102 |
|
104 |
103 |
__PACKAGE__->meta->table('$table');
|
105 |
|
$schema
|
|
104 |
$schema_str
|
106 |
105 |
__PACKAGE__->meta->auto_initialize;
|
107 |
106 |
|
108 |
107 |
__PACKAGE__->meta->perl_class_definition(indent => 2); # , braces => 'bsd'
|
... | ... | |
110 |
109 |
|
111 |
110 |
if ($EVAL_ERROR) {
|
112 |
111 |
error("Error in execution for table '$table'");
|
113 |
|
error("'$EVAL_ERROR'") if $config{verbose};
|
|
112 |
error("'$EVAL_ERROR'") unless $config{quiet};
|
114 |
113 |
return;
|
115 |
114 |
}
|
116 |
115 |
|
... | ... | |
120 |
119 |
$definition =~ s/( foreign_keys \s*=> \s*\[ .* ^\s+ ) ${auto_generated_name} \b/${1}${desired_name}/msx;
|
121 |
120 |
}
|
122 |
121 |
|
|
122 |
$definition =~ s/(table\s*=>.*?\n)/$1 schema => '${schema}',\n/ if $schema;
|
|
123 |
|
123 |
124 |
my $full_definition = <<CODE;
|
124 |
125 |
# This file has been auto-generated. Do not modify it; it will be overwritten
|
125 |
126 |
# by $::script automatically.
|
... | ... | |
137 |
138 |
use SL::DB::MetaSetup::${package};
|
138 |
139 |
|
139 |
140 |
# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
|
140 |
|
$schema
|
141 |
141 |
__PACKAGE__->meta->make_manager_class;
|
142 |
142 |
|
143 |
143 |
1;
|
... | ... | |
151 |
151 |
my $new_size = length $full_definition;
|
152 |
152 |
my $new_md5 = md5_hex($full_definition);
|
153 |
153 |
if ($old_size == $new_size && $old_md5 == $new_md5) {
|
154 |
|
notice("No changes in $meta_file, skipping.") if $config{verbose};
|
|
154 |
notice("No changes in $meta_file, skipping.") unless $config{quiet};
|
155 |
155 |
return;
|
156 |
156 |
}
|
157 |
157 |
|
... | ... | |
178 |
178 |
sub parse_args {
|
179 |
179 |
my ($options) = @_;
|
180 |
180 |
GetOptions(
|
181 |
|
'login|user=s' => \ my $login,
|
|
181 |
'client=s' => \ my $client,
|
182 |
182 |
all => \ my $all,
|
183 |
183 |
'no-commit|dry-run' => \ my $nocommit,
|
184 |
184 |
help => sub { pod2usage(verbose => 99, sections => 'NAME|SYNOPSIS|OPTIONS') },
|
185 |
|
verbose => \ my $verbose,
|
|
185 |
quiet => \ my $quiet,
|
186 |
186 |
diff => \ my $diff,
|
187 |
187 |
);
|
188 |
188 |
|
189 |
|
$options->{login} = $login if $login;
|
|
189 |
$options->{client} = $client;
|
190 |
190 |
$options->{all} = $all;
|
191 |
191 |
$options->{nocommit} = $nocommit;
|
192 |
|
$options->{verbose} = $verbose;
|
|
192 |
$options->{quiet} = $quiet;
|
193 |
193 |
|
194 |
194 |
if ($diff) {
|
195 |
195 |
if (eval { require Text::Diff; 1 }) {
|
... | ... | |
268 |
268 |
|
269 |
269 |
=head1 SYNOPSIS
|
270 |
270 |
|
271 |
|
scripts/rose_create_model.pl --login login table1[=package1] [table2[=package2] ...]
|
272 |
|
scripts/rose_create_model.pl --login login [--all|-a]
|
|
271 |
scripts/rose_create_model.pl --client name-or-id table1[=package1] [table2[=package2] ...]
|
|
272 |
scripts/rose_create_model.pl --client name-or-id [--all|-a]
|
273 |
273 |
|
274 |
274 |
# updates all models
|
275 |
|
scripts/rose_create_model.pl --login login --all
|
|
275 |
scripts/rose_create_model.pl --client name-or-id --all
|
276 |
276 |
|
277 |
277 |
# updates only customer table, login taken from config
|
278 |
278 |
scripts/rose_create_model.pl customer
|
... | ... | |
281 |
281 |
scripts/rose_create_model.pl parts=Part
|
282 |
282 |
|
283 |
283 |
# try to update parts, but don't do it. tell what would happen in detail
|
284 |
|
scripts/rose_create_model.pl --no-commit --verbose parts
|
|
284 |
scripts/rose_create_model.pl --no-commit parts
|
285 |
285 |
|
286 |
286 |
=head1 DESCRIPTION
|
287 |
287 |
|
... | ... | |
327 |
327 |
|
328 |
328 |
=over 4
|
329 |
329 |
|
330 |
|
=item C<--login, -l LOGIN>
|
|
330 |
=item C<--client, -c CLIENT>
|
331 |
331 |
|
332 |
|
=item C<--user, -u LOGIN>
|
|
332 |
Provide a client whose database settings are used. If not present the
|
|
333 |
client is loaded from the config key C<devel/client>. If that too is
|
|
334 |
not found, an error is thrown.
|
333 |
335 |
|
334 |
|
Provide a login. If not present the login is loaded from the config key
|
335 |
|
C<devel/login>. If that too is not found, an error is thrown.
|
|
336 |
Note that C<CLIENT> can be either a database ID or a client's name.
|
336 |
337 |
|
337 |
338 |
=item C<--all, -a>
|
338 |
339 |
|
... | ... | |
355 |
356 |
|
356 |
357 |
Print this help.
|
357 |
358 |
|
358 |
|
=item C<--verbose, -v>
|
|
359 |
=item C<--quiet, -q>
|
359 |
360 |
|
360 |
|
Prints extra information, such as skipped files that were not changed and
|
361 |
|
errors where the auto initialization failed.
|
|
361 |
Does not print extra information, such as skipped files that were not
|
|
362 |
changed and errors where the auto initialization failed.
|
362 |
363 |
|
363 |
364 |
=back
|
364 |
365 |
|
rose_auto_create_model.pl: Umstellung auf Client; Schema bei Auth* in MetaSetup; Verbose als Default
1. Umstellung auf Client anstelle von Login. Dafür muss man jetzt
"--client name-or-ID" angeben. Analog holt sich das Script den
Client aus der Konfiguration devel.client, sofern vorhanden.
2. Schema-Informationen werden nun in die MetaSetup-Dateien
geschrieben und nicht mehr in die DB-Klasse.
3. Gesprächigkeit ist nun der Default. Daher ist --verbose weggefallen
und wurde durch seinen Komplementär --quiet ersetzt.