From f9ba91328da2773af853e6f236e44c3e49a00c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=B6sch?= Date: Fri, 24 Jan 2025 17:38:04 +0100 Subject: [PATCH] MDL-83036 core db: change course fullname to 1333 chars This is mainly for the benefit of multilang users. As well as changing the database schema, it is also necessary to change where this is inforced in PHP code (forms, web services). --- admin/tool/recyclebin/db/install.xml | 2 +- admin/tool/recyclebin/db/upgrade.php | 17 ++++- admin/tool/recyclebin/version.php | 2 +- admin/tool/uploadcourse/classes/course.php | 14 +++- course/classes/constants.php | 2 +- lib/db/install.xml | 4 +- lib/db/upgrade.php | 80 ++++++++++++++++++++-- version.php | 2 +- 8 files changed, 107 insertions(+), 16 deletions(-) diff --git a/admin/tool/recyclebin/db/install.xml b/admin/tool/recyclebin/db/install.xml index 8aa6c9d45b888..748155d7d8842 100644 --- a/admin/tool/recyclebin/db/install.xml +++ b/admin/tool/recyclebin/db/install.xml @@ -25,7 +25,7 @@ - + diff --git a/admin/tool/recyclebin/db/upgrade.php b/admin/tool/recyclebin/db/upgrade.php index 544a99885ef40..71a6a18927d1b 100644 --- a/admin/tool/recyclebin/db/upgrade.php +++ b/admin/tool/recyclebin/db/upgrade.php @@ -47,9 +47,9 @@ function xmldb_tool_recyclebin_upgrade($oldversion) { if ($oldversion < 2024111500) { - // Changing precision of field fullname on table tool_recyclebin_category to (255). + // Changing precision of field fullname on table tool_recyclebin_category to (1333). $table = new xmldb_table('tool_recyclebin_category'); - $field = new xmldb_field('fullname', XMLDB_TYPE_CHAR, '1333', null, XMLDB_NOTNULL, null, null, 'shortname'); + $field = new xmldb_field('fullname', XMLDB_TYPE_CHAR, '1333', null, XMLDB_NOTNULL, null, null, 'timecreated'); // Launch change of precision for field fullname. $dbman->change_field_precision($table, $field); @@ -58,5 +58,18 @@ function xmldb_tool_recyclebin_upgrade($oldversion) { upgrade_plugin_savepoint(true, 2024111500, 'tool', 'recyclebin'); } + if ($oldversion < 2024121801) { + + // Changing precision of field shortname on table tool_recyclebin_category to (1333). + $table = new xmldb_table('tool_recyclebin_category'); + $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '1333', null, XMLDB_NOTNULL, null, null, 'fullname'); + + // Launch change of precision for field shortname. + $dbman->change_field_precision($table, $field); + + // Recyclebin savepoint reached. + upgrade_plugin_savepoint(true, 2024121801, 'tool', 'recyclebin'); + } + return true; } diff --git a/admin/tool/recyclebin/version.php b/admin/tool/recyclebin/version.php index c32e1d7de8d58..b86599ffce505 100644 --- a/admin/tool/recyclebin/version.php +++ b/admin/tool/recyclebin/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024121800; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2024121801; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2024100100; // Requires this Moodle version. $plugin->component = 'tool_recyclebin'; // Full name of the plugin (used for diagnostics). diff --git a/admin/tool/uploadcourse/classes/course.php b/admin/tool/uploadcourse/classes/course.php index 6600bf0b1be9a..f7ae7eb3400c2 100644 --- a/admin/tool/uploadcourse/classes/course.php +++ b/admin/tool/uploadcourse/classes/course.php @@ -432,8 +432,8 @@ public function prepare() { } // Ensure we don't overflow the maximum length of the shortname field. - if (core_text::strlen($this->shortname) > 255) { - $this->error('invalidshortnametoolong', new lang_string('invalidshortnametoolong', 'tool_uploadcourse', 255)); + if (core_text::strlen($this->shortname) > 1333) { + $this->error('invalidshortnametoolong', new lang_string('invalidshortnametoolong', 'tool_uploadcourse', 1333)); return false; } } @@ -518,6 +518,16 @@ public function prepare() { return false; } + // Ensure we don't overflow the maximum length of the shortname field. + if ( + !empty($coursedata['shortname']) && + core_text::strlen($coursedata['shortname']) > \core_course\constants::SHORTNAME_MAXIMUM_LENGTH + ) { + $this->error('invalidshortnametoolong', new lang_string('invalidshortnametoolong', 'tool_uploadcourse', + \core_course\constants::SHORTNAME_MAXIMUM_LENGTH)); + return false; + } + // If the course does not exist, or will be forced created. if (!$exists || $mode === tool_uploadcourse_processor::MODE_CREATE_ALL) { diff --git a/course/classes/constants.php b/course/classes/constants.php index 4242d77a838ad..831758a6c9def 100644 --- a/course/classes/constants.php +++ b/course/classes/constants.php @@ -28,6 +28,6 @@ abstract class constants { public const FULLNAME_MAXIMUM_LENGTH = 1333; /** @var int the length of the course.shortname field. */ - public const SHORTNAME_MAXIMUM_LENGTH = 255; + public const SHORTNAME_MAXIMUM_LENGTH = 1333; } diff --git a/lib/db/install.xml b/lib/db/install.xml index 6cef0858a3704..8c110ca040463 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -73,7 +73,7 @@ - + @@ -401,7 +401,7 @@ - + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 1cdcc28b500e3..3c616e9048897 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -1166,11 +1166,11 @@ function xmldb_main_upgrade($oldversion) { if ($oldversion < 2024111500.00) { - // Changing precision of field fullname on table course to (1333). + // Changing precision of field shortname on table course to (1333). $table = new xmldb_table('course'); - $field = new xmldb_field('fullname', XMLDB_TYPE_CHAR, '1333', null, XMLDB_NOTNULL, null, null, 'sortorder'); + $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '1333', null, XMLDB_NOTNULL, null, null, 'sortorder'); - // Launch change of precision for field fullname. + // Launch change of precision for field shortname. $dbman->change_field_precision($table, $field); // Main savepoint reached. @@ -1179,11 +1179,11 @@ function xmldb_main_upgrade($oldversion) { if ($oldversion < 2024111500.01) { - // Changing precision of field fullname on table course_request to (1333). + // Changing precision of field shortname on table course_request to (1333). $table = new xmldb_table('course_request'); - $field = new xmldb_field('fullname', XMLDB_TYPE_CHAR, '1333', null, XMLDB_NOTNULL, null, null, 'id'); + $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '1333', null, XMLDB_NOTNULL, null, null, 'id'); - // Launch change of precision for field fullname. + // Launch change of precision for field shortname. $dbman->change_field_precision($table, $field); // Main savepoint reached. @@ -1382,15 +1382,83 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2025011700.02); } +<<<<<<< HEAD if ($oldversion < 2025012400.01) { // Remove the default value for the apiversion field. $table = new xmldb_table('badge_external_backpack'); $apiversionfield = new xmldb_field('apiversion', XMLDB_TYPE_CHAR, '12', null, XMLDB_NOTNULL, null, null); $dbman->change_field_default($table, $apiversionfield); +======= + if ($oldversion < 2025012400.00) { + + // Changing precision of field shortname on table course to (1333). + $table = new xmldb_table('course'); + $field = new xmldb_field('fullname', XMLDB_TYPE_CHAR, '1333', null, XMLDB_NOTNULL, null, null, 'sortorder'); + + // Launch change of precision for field fullname. + $dbman->change_field_precision($table, $field); + + // Main savepoint reached. + upgrade_main_savepoint(true, 2025012400.00); + } + + if ($oldversion < 2025012400.01) { + + // Changing precision of field fullname on table course_request to (1333). + $table = new xmldb_table('course_request'); + $field = new xmldb_field('fullname', XMLDB_TYPE_CHAR, '1333', null, XMLDB_NOTNULL, null, null, 'id'); + + // Launch change of precision for field fullname. + $dbman->change_field_precision($table, $field); // Main savepoint reached. upgrade_main_savepoint(true, 2025012400.01); } + // Now we want to change the precision of course_request.shortname. + // To do this, we need to first drop the index, then re-create it. + if ($oldversion < 2025012400.02) { + + // Define index shortname (not unique) to be dropped form course_request. + $table = new xmldb_table('course_request'); + $index = new xmldb_index('shortname', XMLDB_INDEX_NOTUNIQUE, ['shortname']); + + // Conditionally launch drop index shortname. + if ($dbman->index_exists($table, $index)) { + $dbman->drop_index($table, $index); + } + + // Main savepoint reached. + upgrade_main_savepoint(true, 2025012400.02); + } + + if ($oldversion < 2025012400.03) { + + // Changing precision of field shortname on table course_request to (255). + $table = new xmldb_table('course_request'); + $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'shortname'); + + // Launch change of precision for field shortname. + $dbman->change_field_precision($table, $field); + + // Main savepoint reached. + upgrade_main_savepoint(true, 2025012400.03); + } + + if ($oldversion < 2025012400.04) { + + // Define index shortname (not unique) to be added to course_request. + $table = new xmldb_table('course_request'); + $index = new xmldb_index('shortname', XMLDB_INDEX_NOTUNIQUE, ['shortname']); + + // Conditionally launch add index shortname. + if (!$dbman->index_exists($table, $index)) { + $dbman->add_index($table, $index); + } + + // Main savepoint reached. + upgrade_main_savepoint(true, 2025012400.04); + } + return true; } diff --git a/version.php b/version.php index 2e218ac513f92..745782811d3fa 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2025013100.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2025012400.04; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '5.0dev (Build: 20250131)'; // Human-friendly version name