@@ -1339,7 +1339,7 @@ sub upgrade_course_confirm ($c) {
13391339
13401340 my @upgrade_courseIDs = $c -> param(' upgrade_courseIDs' );
13411341
1342- my ($extra_database_tables_exist , $extra_database_fields_exist ) = (0, 0);
1342+ my ($extra_database_tables_exist , $extra_database_fields_exist , $incorrect_type_database_fields_exist ) = (0, 0, 0);
13431343
13441344 my $status_output = $c -> c;
13451345
@@ -1354,8 +1354,9 @@ sub upgrade_course_confirm ($c) {
13541354
13551355 # Report on database status
13561356 my ($tables_ok , $dbStatus ) = $CIchecker -> checkCourseTables($upgrade_courseID );
1357- my ($all_tables_ok , $extra_database_tables , $extra_database_fields , $rebuild_table_indexes , $db_report ) =
1358- $c -> formatReportOnDatabaseTables($dbStatus , $upgrade_courseID );
1357+ my ($all_tables_ok , $extra_database_tables , $extra_database_fields , $rebuild_table_indexes ,
1358+ $incorrect_type_database_fields , $db_report )
1359+ = $c -> formatReportOnDatabaseTables($dbStatus , $upgrade_courseID );
13591360
13601361 my $course_output = $c -> c;
13611362
@@ -1428,6 +1429,24 @@ sub upgrade_course_confirm ($c) {
14281429 );
14291430 }
14301431
1432+ if ($incorrect_type_database_fields ) {
1433+ $incorrect_type_database_fields_exist = 1;
1434+ push (
1435+ @$course_output ,
1436+ $c -> tag(
1437+ ' p' ,
1438+ class => ' text-danger fw-bold' ,
1439+ $c -> maketext(
1440+ ' There are database fields that do not have the same type as the field defined in the schema '
1441+ . ' for at least one table. Check the checkbox by the field to change its type when '
1442+ . ' upgrading the course. Warning: This can fail which may corrupt the table. If you have '
1443+ . ' not archived this course, then do that now before upgrading if you want to change the '
1444+ . ' type of any of these fields.'
1445+ )
1446+ )
1447+ );
1448+ }
1449+
14311450 # Report on directory status
14321451 my ($directories_ok , $directory_report ) = checkCourseDirectories($ce2 );
14331452 push (@$course_output , $c -> tag(' div' , class => ' mb-2' , $c -> maketext(' Directory structure:' )));
@@ -1464,10 +1483,11 @@ sub upgrade_course_confirm ($c) {
14641483
14651484 return $c -> include(
14661485 ' ContentGenerator/CourseAdmin/upgrade_course_confirm' ,
1467- upgrade_courseIDs => \@upgrade_courseIDs ,
1468- extra_database_tables_exist => $extra_database_tables_exist ,
1469- extra_database_fields_exist => $extra_database_fields_exist ,
1470- status_output => $status_output -> join (' ' )
1486+ upgrade_courseIDs => \@upgrade_courseIDs ,
1487+ extra_database_tables_exist => $extra_database_tables_exist ,
1488+ extra_database_fields_exist => $extra_database_fields_exist ,
1489+ incorrect_type_database_fields_exist => $incorrect_type_database_fields_exist ,
1490+ status_output => $status_output -> join (' ' )
14711491 );
14721492}
14731493
@@ -1503,17 +1523,20 @@ sub do_upgrade_course ($c) {
15031523 push (
15041524 @upgrade_report ,
15051525 $CIchecker -> updateTableFields(
1506- $upgrade_courseID , $table_name ,
1507- [ ($c -> param(" $upgrade_courseID .$table_name .delete_fieldIDs" )) ]
1526+ $upgrade_courseID ,
1527+ $table_name ,
1528+ [ ($c -> param(" $upgrade_courseID .$table_name .delete_fieldIDs" )) ],
1529+ [ ($c -> param(" $upgrade_courseID .$table_name .fix_type_fieldIDs" )) ],
15081530 )
15091531 );
15101532 }
15111533
15121534 # Analyze database status and prepare status report
15131535 ($tables_ok , $dbStatus ) = $CIchecker -> checkCourseTables($upgrade_courseID );
15141536
1515- my ($all_tables_ok , $extra_database_tables , $extra_database_fields , $rebuild_table_indexes , $db_report ) =
1516- $c -> formatReportOnDatabaseTables($dbStatus );
1537+ my ($all_tables_ok , $extra_database_tables , $extra_database_fields , $rebuild_table_indexes ,
1538+ $incorrect_type_database_fields , $db_report )
1539+ = $c -> formatReportOnDatabaseTables($dbStatus );
15171540
15181541 # Prepend course name
15191542 $db_report = $c -> c($c -> tag(' div' , class => ' mb-2' , $c -> maketext(' Database:' )), $db_report );
@@ -1541,6 +1564,20 @@ sub do_upgrade_course ($c) {
15411564 );
15421565 }
15431566
1567+ if ($incorrect_type_database_fields ) {
1568+ push (
1569+ @$db_report ,
1570+ $c -> tag(
1571+ ' p' ,
1572+ class => ' text-danger fw-bold' ,
1573+ $c -> maketext(
1574+ ' There are database fields that do not have the same type as the '
1575+ . ' field defined in the schema for at least one table.'
1576+ )
1577+ )
1578+ );
1579+ }
1580+
15441581 # Add missing directories and prepare report on directory status
15451582 my $dir_update_messages = updateCourseDirectories($ce2 ); # Needs more error messages
15461583 my ($directories_ok , $directory_report ) = checkCourseDirectories($ce2 );
@@ -2684,10 +2721,11 @@ sub formatReportOnDatabaseTables ($c, $dbStatus, $courseID = undef) {
26842721 )
26852722 );
26862723
2687- my $all_tables_ok = 1;
2688- my $extra_database_tables = 0;
2689- my $extra_database_fields = 0;
2690- my $rebuild_table_indexes = 0;
2724+ my $all_tables_ok = 1;
2725+ my $extra_database_tables = 0;
2726+ my $extra_database_fields = 0;
2727+ my $rebuild_table_indexes = 0;
2728+ my $incorrect_type_database_fields = 0;
26912729
26922730 my $db_report = $c -> c;
26932731
@@ -2728,9 +2766,35 @@ sub formatReportOnDatabaseTables ($c, $dbStatus, $courseID = undef) {
27282766 } else {
27292767 $extra_database_fields = 1;
27302768 }
2731- if ($fieldInfo {$key }[1]) {
2732- push (@$field_report , $c -> hidden_field(" $courseID .$table .delete_fieldIDs" => $key ));
2733- } else {
2769+ if (defined $courseID ) {
2770+ if ($fieldInfo {$key }[1]) {
2771+ push (@$field_report , $c -> hidden_field(" $courseID .$table .delete_fieldIDs" => $key ));
2772+ } else {
2773+ push (
2774+ @$field_report ,
2775+ $c -> tag(
2776+ ' span' ,
2777+ class => ' form-check d-inline-block' ,
2778+ $c -> tag(
2779+ ' label' ,
2780+ class => ' form-check-label' ,
2781+ $c -> c(
2782+ $c -> check_box(
2783+ " $courseID .$table .delete_fieldIDs" => $key ,
2784+ class => ' form-check-input'
2785+ ),
2786+ $c -> maketext(' Delete field when upgrading' )
2787+ )-> join (' ' )
2788+ )
2789+ )
2790+ );
2791+ }
2792+ }
2793+ } elsif ($field_status == WeBWorK::Utils::CourseDBIntegrityCheck::ONLY_IN_A) {
2794+ $all_tables_ok = 0;
2795+ } elsif ($field_status == WeBWorK::Utils::CourseDBIntegrityCheck::DIFFER_IN_A_AND_B) {
2796+ $incorrect_type_database_fields = 1;
2797+ if (defined $courseID ) {
27342798 push (
27352799 @$field_report ,
27362800 $c -> tag(
@@ -2741,17 +2805,15 @@ sub formatReportOnDatabaseTables ($c, $dbStatus, $courseID = undef) {
27412805 class => ' form-check-label' ,
27422806 $c -> c(
27432807 $c -> check_box(
2744- " $courseID .$table .delete_fieldIDs " => $key ,
2745- class => ' form-check-input'
2808+ " $courseID .$table .fix_type_fieldIDs " => $key ,
2809+ class => ' form-check-input'
27462810 ),
2747- $c -> maketext(' Delete field when upgrading' )
2811+ $c -> maketext(' Change type of field when upgrading' )
27482812 )-> join (' ' )
27492813 )
27502814 )
27512815 );
27522816 }
2753- } elsif ($field_status == WeBWorK::Utils::CourseDBIntegrityCheck::ONLY_IN_A) {
2754- $all_tables_ok = 0;
27552817 }
27562818 push (@$fields_report , $c -> tag(' li' , $field_report -> join (' ' )));
27572819 }
@@ -2765,8 +2827,9 @@ sub formatReportOnDatabaseTables ($c, $dbStatus, $courseID = undef) {
27652827 push (@$db_report , $c -> tag(' p' , class => ' text-success' , $c -> maketext(' Database tables are ok' ))) if $all_tables_ok ;
27662828
27672829 return (
2768- $all_tables_ok , $extra_database_tables , $extra_database_fields ,
2769- $rebuild_table_indexes , $db_report -> join (' ' )
2830+ $all_tables_ok , $extra_database_tables , $extra_database_fields , $rebuild_table_indexes ,
2831+ $incorrect_type_database_fields ,
2832+ $db_report -> join (' ' )
27702833 );
27712834}
27722835
0 commit comments