Skip to content

Commit

Permalink
MDL-83036 core db: change course fullname to 1333 chars
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
lucaboesch committed Jan 31, 2025
1 parent 07881a5 commit f9ba913
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 16 deletions.
2 changes: 1 addition & 1 deletion admin/tool/recyclebin/db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="categoryid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="shortname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="shortname" TYPE="char" LENGTH="1333" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="fullname" TYPE="char" LENGTH="1333" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
</FIELDS>
Expand Down
17 changes: 15 additions & 2 deletions admin/tool/recyclebin/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion admin/tool/recyclebin/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).
14 changes: 12 additions & 2 deletions admin/tool/uploadcourse/classes/course.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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) {

Expand Down
2 changes: 1 addition & 1 deletion course/classes/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
4 changes: 2 additions & 2 deletions lib/db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<FIELD NAME="category" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="fullname" TYPE="char" LENGTH="1333" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="shortname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="shortname" TYPE="char" LENGTH="1333" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="idnumber" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="summary" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="summaryformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
Expand Down Expand Up @@ -401,7 +401,7 @@
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="fullname" TYPE="char" LENGTH="1333" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="shortname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="shortname" TYPE="char" LENGTH="1333" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="summary" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="summaryformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="category" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
Expand Down
80 changes: 74 additions & 6 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f9ba913

Please sign in to comment.