@@ -1339,7 +1339,7 @@ sub upgrade_course_confirm ($c) {
1339
1339
1340
1340
my @upgrade_courseIDs = $c -> param(' upgrade_courseIDs' );
1341
1341
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);
1343
1343
1344
1344
my $status_output = $c -> c;
1345
1345
@@ -1354,8 +1354,9 @@ sub upgrade_course_confirm ($c) {
1354
1354
1355
1355
# Report on database status
1356
1356
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 );
1359
1360
1360
1361
my $course_output = $c -> c;
1361
1362
@@ -1428,6 +1429,24 @@ sub upgrade_course_confirm ($c) {
1428
1429
);
1429
1430
}
1430
1431
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
+
1431
1450
# Report on directory status
1432
1451
my ($directories_ok , $directory_report ) = checkCourseDirectories($ce2 );
1433
1452
push (@$course_output , $c -> tag(' div' , class => ' mb-2' , $c -> maketext(' Directory structure:' )));
@@ -1464,10 +1483,11 @@ sub upgrade_course_confirm ($c) {
1464
1483
1465
1484
return $c -> include(
1466
1485
' 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 (' ' )
1471
1491
);
1472
1492
}
1473
1493
@@ -1503,17 +1523,20 @@ sub do_upgrade_course ($c) {
1503
1523
push (
1504
1524
@upgrade_report ,
1505
1525
$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" )) ],
1508
1530
)
1509
1531
);
1510
1532
}
1511
1533
1512
1534
# Analyze database status and prepare status report
1513
1535
($tables_ok , $dbStatus ) = $CIchecker -> checkCourseTables($upgrade_courseID );
1514
1536
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 );
1517
1540
1518
1541
# Prepend course name
1519
1542
$db_report = $c -> c($c -> tag(' div' , class => ' mb-2' , $c -> maketext(' Database:' )), $db_report );
@@ -1541,6 +1564,20 @@ sub do_upgrade_course ($c) {
1541
1564
);
1542
1565
}
1543
1566
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
+
1544
1581
# Add missing directories and prepare report on directory status
1545
1582
my $dir_update_messages = updateCourseDirectories($ce2 ); # Needs more error messages
1546
1583
my ($directories_ok , $directory_report ) = checkCourseDirectories($ce2 );
@@ -2684,10 +2721,11 @@ sub formatReportOnDatabaseTables ($c, $dbStatus, $courseID = undef) {
2684
2721
)
2685
2722
);
2686
2723
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;
2691
2729
2692
2730
my $db_report = $c -> c;
2693
2731
@@ -2728,9 +2766,35 @@ sub formatReportOnDatabaseTables ($c, $dbStatus, $courseID = undef) {
2728
2766
} else {
2729
2767
$extra_database_fields = 1;
2730
2768
}
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 ) {
2734
2798
push (
2735
2799
@$field_report ,
2736
2800
$c -> tag(
@@ -2741,17 +2805,15 @@ sub formatReportOnDatabaseTables ($c, $dbStatus, $courseID = undef) {
2741
2805
class => ' form-check-label' ,
2742
2806
$c -> c(
2743
2807
$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'
2746
2810
),
2747
- $c -> maketext(' Delete field when upgrading' )
2811
+ $c -> maketext(' Change type of field when upgrading' )
2748
2812
)-> join (' ' )
2749
2813
)
2750
2814
)
2751
2815
);
2752
2816
}
2753
- } elsif ($field_status == WeBWorK::Utils::CourseDBIntegrityCheck::ONLY_IN_A) {
2754
- $all_tables_ok = 0;
2755
2817
}
2756
2818
push (@$fields_report , $c -> tag(' li' , $field_report -> join (' ' )));
2757
2819
}
@@ -2765,8 +2827,9 @@ sub formatReportOnDatabaseTables ($c, $dbStatus, $courseID = undef) {
2765
2827
push (@$db_report , $c -> tag(' p' , class => ' text-success' , $c -> maketext(' Database tables are ok' ))) if $all_tables_ok ;
2766
2828
2767
2829
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 (' ' )
2770
2833
);
2771
2834
}
2772
2835
0 commit comments