Lines 152-174
sub execute_version {
Link Here
|
152 |
return $report |
152 |
return $report |
153 |
if ( defined $report->{$version} ); |
153 |
if ( defined $report->{$version} ); |
154 |
|
154 |
|
155 |
my $errors; |
155 |
my $errors = execute ( $queries ); |
156 |
for my $query ( @{$queries->{queries}} ) { |
|
|
157 |
eval { |
158 |
check_coherency( $query ); |
159 |
}; |
160 |
if ( $@ ) { |
161 |
push @$errors, $@ |
162 |
} |
163 |
} |
164 |
|
165 |
if ( $errors ) { |
166 |
$_ =~ s/at [^ ]* line \d*\.$// for @$errors; |
167 |
$report->{$version} = $errors; |
168 |
return $report; |
169 |
} |
170 |
|
171 |
$errors = execute ( $queries ); |
172 |
$report->{$version} = scalar( @$errors ) ? $errors : "OK"; |
156 |
$report->{$version} = scalar( @$errors ) ? $errors : "OK"; |
173 |
set_infos ( $version, $queries, $errors, $md5 ); |
157 |
set_infos ( $version, $queries, $errors, $md5 ); |
174 |
return $report; |
158 |
return $report; |
Lines 280-286
my $tables;
Link Here
|
280 |
|
264 |
|
281 |
=head2 check_coherency |
265 |
=head2 check_coherency |
282 |
|
266 |
|
283 |
my $errors = check_coherency($query); |
267 |
my $errors = check_coherency($query); UNUSED |
284 |
This sub will try to check if a SQL query is useless or no. |
268 |
This sub will try to check if a SQL query is useless or no. |
285 |
for queries that are CREATE TABLE, it will check if the table already exists |
269 |
for queries that are CREATE TABLE, it will check if the table already exists |
286 |
for queries that are ALTER TABLE, it will search if the modification has already been made |
270 |
for queries that are ALTER TABLE, it will search if the modification has already been made |
Lines 290-351
my $tables;
Link Here
|
290 |
|
274 |
|
291 |
=cut |
275 |
=cut |
292 |
|
276 |
|
293 |
sub check_coherency { |
277 |
#sub check_coherency { |
294 |
my ( $query ) = @_; |
278 |
# my ( $query ) = @_; |
295 |
$tables = get_tables_name() if not $tables; |
279 |
# $tables = get_tables_name() if not $tables; |
296 |
|
280 |
# |
297 |
given ( $query ) { |
281 |
# given ( $query ) { |
298 |
when ( /CREATE TABLE(?:.*?)? `?(\w+)`?/ ) { |
282 |
# when ( /CREATE TABLE(?:.*?)? `?(\w+)`?/ ) { |
299 |
my $table_name = $1; |
283 |
# my $table_name = $1; |
300 |
if ( grep { /$table_name/ } @$tables ) { |
284 |
# if ( grep { /$table_name/ } @$tables ) { |
301 |
die "COHERENCY: Table $table_name already exists"; |
285 |
# die "COHERENCY: Table $table_name already exists"; |
302 |
} |
286 |
# } |
303 |
} |
287 |
# } |
304 |
|
288 |
# |
305 |
when ( /ALTER TABLE *`?(\w+)`? *ADD *(?:COLUMN)? `?(\w+)`?/ ) { |
289 |
# when ( /ALTER TABLE *`?(\w+)`? *ADD *(?:COLUMN)? `?(\w+)`?/ ) { |
306 |
my $table_name = $1; |
290 |
# my $table_name = $1; |
307 |
my $column_name = $2; |
291 |
# my $column_name = $2; |
308 |
next if $column_name =~ /(UNIQUE|CONSTRAINT|INDEX|KEY|FOREIGN)/; |
292 |
# next if $column_name =~ /(UNIQUE|CONSTRAINT|INDEX|KEY|FOREIGN)/; |
309 |
if ( not grep { /$table_name/ } @$tables ) { |
293 |
# if ( not grep { /$table_name/ } @$tables ) { |
310 |
return "COHERENCY: Table $table_name does not exist"; |
294 |
# return "COHERENCY: Table $table_name does not exist"; |
311 |
} else { |
295 |
# } else { |
312 |
my $sth = $dbh->prepare( "DESC $table_name $column_name" ); |
296 |
# my $sth = $dbh->prepare( "DESC $table_name $column_name" ); |
313 |
my $rv = $sth->execute; |
297 |
# my $rv = $sth->execute; |
314 |
if ( $rv > 0 ) { |
298 |
# if ( $rv > 0 ) { |
315 |
die "COHERENCY: Field $table_name.$column_name already exists"; |
299 |
# die "COHERENCY: Field $table_name.$column_name already exists"; |
316 |
} |
300 |
# } |
317 |
} |
301 |
# } |
318 |
} |
302 |
# } |
319 |
|
303 |
# |
320 |
when ( /INSERT INTO `?(\w+)`?.*?VALUES *\((.*?)\)/ ) { |
304 |
# when ( /INSERT INTO `?(\w+)`?.*?VALUES *\((.*?)\)/ ) { |
321 |
my $table_name = $1; |
305 |
# my $table_name = $1; |
322 |
my @values = split /,/, $2; |
306 |
# my @values = split /,/, $2; |
323 |
s/^ *'// foreach @values; |
307 |
# s/^ *'// foreach @values; |
324 |
s/' *$// foreach @values; |
308 |
# s/' *$// foreach @values; |
325 |
given ( $table_name ) { |
309 |
# given ( $table_name ) { |
326 |
when ( /systempreferences/ ) { |
310 |
# when ( /systempreferences/ ) { |
327 |
my $syspref = $values[0]; |
311 |
# my $syspref = $values[0]; |
328 |
my $sth = $dbh->prepare( "SELECT COUNT(*) FROM systempreferences WHERE variable = ?" ); |
312 |
# my $sth = $dbh->prepare( "SELECT COUNT(*) FROM systempreferences WHERE variable = ?" ); |
329 |
$sth->execute( $syspref ); |
313 |
# $sth->execute( $syspref ); |
330 |
if ( ( my $count = $sth->fetchrow_array ) > 0 ) { |
314 |
# if ( ( my $count = $sth->fetchrow_array ) > 0 ) { |
331 |
die "COHERENCY: Syspref $syspref already exists"; |
315 |
# die "COHERENCY: Syspref $syspref already exists"; |
332 |
} |
316 |
# } |
333 |
} |
317 |
# } |
334 |
|
318 |
# |
335 |
when ( /permissions/){ |
319 |
# when ( /permissions/){ |
336 |
my $module_bit = $values[0]; |
320 |
# my $module_bit = $values[0]; |
337 |
my $code = $values[1]; |
321 |
# my $code = $values[1]; |
338 |
my $sth = $dbh->prepare( "SELECT COUNT(*) FROM permissions WHERE module_bit = ? AND code = ?" ); |
322 |
# my $sth = $dbh->prepare( "SELECT COUNT(*) FROM permissions WHERE module_bit = ? AND code = ?" ); |
339 |
$sth->execute($module_bit, $code); |
323 |
# $sth->execute($module_bit, $code); |
340 |
if ( ( my $count = $sth->fetchrow_array ) > 0 ) { |
324 |
# if ( ( my $count = $sth->fetchrow_array ) > 0 ) { |
341 |
die "COHERENCY: Permission $code already exists"; |
325 |
# die "COHERENCY: Permission $code already exists"; |
342 |
} |
326 |
# } |
343 |
} |
327 |
# } |
344 |
} |
328 |
# } |
345 |
} |
329 |
# } |
346 |
} |
330 |
# } |
347 |
return 1; |
331 |
# return 1; |
348 |
} |
332 |
#} |
349 |
|
333 |
|
350 |
=head2 get_error |
334 |
=head2 get_error |
351 |
|
335 |
|
Lines 462-483
sub mark_as_ok {
Link Here
|
462 |
my $sth = $dbh->prepare( "UPDATE updatedb_report SET status = 2 WHERE version=?" ); |
446 |
my $sth = $dbh->prepare( "UPDATE updatedb_report SET status = 2 WHERE version=?" ); |
463 |
my $affected = $sth->execute( $version ); |
447 |
my $affected = $sth->execute( $version ); |
464 |
if ( $affected < 1 ) { |
448 |
if ( $affected < 1 ) { |
465 |
# For "Coherency" |
|
|
466 |
my $filepath = get_filepath $version; |
449 |
my $filepath = get_filepath $version; |
467 |
my $queries = get_queries $filepath; |
450 |
my $queries = get_queries $filepath; |
468 |
my $errors; |
451 |
my $md5 = get_md5 $filepath; |
469 |
for my $query ( @{$queries->{queries}} ) { |
452 |
set_infos $version, $queries, undef, $md5; |
470 |
eval { |
|
|
471 |
check_coherency( $query ); |
472 |
}; |
473 |
if ( $@ ) { |
474 |
push @$errors, $@ |
475 |
} |
476 |
} |
477 |
|
478 |
$_ =~ s/at [^ ]* line \d*\.$// for @$errors; |
479 |
my $md5 = get_md5 $filepath; |
480 |
set_infos $version, $queries, $errors, $md5; |
481 |
|
453 |
|
482 |
$sth->execute( $version ); |
454 |
$sth->execute( $version ); |
483 |
} |
455 |
} |