Log Message:
-----------
Fixed a bug that occurs when you have courses with similar names with
a underscore such as math101 and math101_fall09. Before checking tables
for math101 would find tables for math101_fall09 and bring up false
warnings. See http://webwork.maa.org/moodle/mod/forum/discuss.php?d=6248
Modified Files:
--------------
webwork2/lib/WeBWorK/Utils:
CourseIntegrityCheck.pm
Revision Data
-------------
Index: CourseIntegrityCheck.pm
===================================================================
RCS file: /webwork/cvs/system/webwork2/lib/WeBWorK/Utils/CourseIntegrityCheck.pm,v
retrieving revision 1.5
retrieving revision 1.6
diff -Llib/WeBWorK/Utils/CourseIntegrityCheck.pm -Llib/WeBWorK/Utils/CourseIntegrityCheck.pm -u -r1.5 -r1.6
--- lib/WeBWorK/Utils/CourseIntegrityCheck.pm
+++ lib/WeBWorK/Utils/CourseIntegrityCheck.pm
@@ -104,6 +104,7 @@
# for corresponding tables.
##########################################################
my $db = $self->db;
+ my $ce = $self->{ce};
$self->lock_database;
foreach my $table (sort keys %$db) {
next if $db->{$table}{params}{non_native}; # skip non-native tables
@@ -131,8 +132,26 @@
my $stmt = "show tables like '${courseName}%'"; # mysql request
my $result = $dbh->selectall_arrayref($stmt) ;
my @tableNames = map {@$_} @$result; # drill down in the result to the table name level
+
+# Table names are of the form courseID_table (with an underscore). So if we have two courses mth101 and mth101_fall09
+# when we check the tables for mth101 we will inadvertantly pick up the tables for mth101_fall09. Thus we find all
+# courseID's and exclude the extraneous tables.
+
+ my @courseIDs = listCourses($ce);
+ my @similarIDs =();
+ foreach my $courseID (@courseIDs) {
+ next unless $courseID =~/^${courseName}\_(.*)/;
+ push(@similarIDs, $courseID);
+ }
+
+ OUTER_LOOP:
foreach my $table (sort @tableNames) {
- next unless $table =~/^${courseName}\_(.*)/; #double check that we only have our course tables
+ next unless $table =~/^${courseName}\_(.*)/; #double check that we only have our course tables and similar ones
+
+ foreach my $courseID (@similarIDs) { #exclude tables with similar but wrong names
+ next OUTER_LOOP if $table =~/^${courseID}\_(.*)/;
+ }
+
my $schema_name = $1;
my $exists = exists($db->{$schema_name});
$tables_ok = 0 unless exists($db->{$schema_name});
@@ -436,4 +455,4 @@
-1;
\ No newline at end of file
+1;
|