This commit is contained in:
Jun Pataleta 2024-11-18 14:31:40 +08:00
commit 239893647a
No known key found for this signature in database
GPG Key ID: F83510526D99E2C7
13 changed files with 218 additions and 17 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="admin/tool/recyclebin/db" VERSION="20160315" COMMENT="XMLDB file for Moodle tool/recyclebin"
<XMLDB PATH="admin/tool/recyclebin/db" VERSION="20241115" COMMENT="XMLDB file for Moodle tool/recyclebin"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
>
@ -26,7 +26,7 @@
<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="fullname" TYPE="char" LENGTH="255" 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>
<KEYS>

View File

@ -0,0 +1,65 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Upgrade script for tool_recyclebin.
*
* @package tool_recyclebin
* @copyright The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Upgrade the plugin.
*
* @param int $oldversion
* @return bool always true
*/
function xmldb_tool_recyclebin_upgrade($oldversion) {
global $DB;
$dbman = $DB->get_manager();
// Automatically generated Moodle v4.1.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.2.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.3.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.4.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.5.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2024111500) {
// Changing precision of field fullname on table tool_recyclebin_category to (255).
$table = new xmldb_table('tool_recyclebin_category');
$field = new xmldb_field('fullname', XMLDB_TYPE_CHAR, '1333', null, XMLDB_NOTNULL, null, null, 'shortname');
// Launch change of precision for field fullname.
$dbman->change_field_precision($table, $field);
// Recyclebin savepoint reached.
upgrade_plugin_savepoint(true, 2024111500, 'tool', 'recyclebin');
}
return true;
}

View File

@ -22,6 +22,7 @@ namespace tool_recyclebin;
* @package tool_recyclebin
* @copyright 2015 University of Kent
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \tool_recyclebin\category_bin
*/
class category_bin_test extends \advanced_testcase {
@ -74,6 +75,25 @@ class category_bin_test extends \advanced_testcase {
$this->assertEquals(1, count($recyclebin->get_items()));
}
public function test_delete_course_with_long_names(): void {
global $DB;
// Create a course with its name at the upper limit of what is allowed.
$course = $this->getDataGenerator()->create_course([
'shortname' => str_repeat("S", \core_course\constants::SHORTNAME_MAXIMUM_LENGTH),
'fullname' => str_repeat("F", \core_course\constants::FULLNAME_MAXIMUM_LENGTH),
]);
// Should have nothing in the recycle bin.
$this->assertEquals(0, $DB->count_records('tool_recyclebin_category'));
delete_course($course, false);
// Verify the course is now in the recycle bin.
$recyclebin = new \tool_recyclebin\category_bin($course->category);
$this->assertCount(1, $recyclebin->get_items());
}
/**
* Check that our hook is called when a course is deleted.
*/

View File

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024100700; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2024111500; // 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).

View File

@ -509,8 +509,12 @@ class tool_uploadcourse_course {
}
// Ensure we don't overflow the maximum length of the fullname field.
if (!empty($coursedata['fullname']) && core_text::strlen($coursedata['fullname']) > 254) {
$this->error('invalidfullnametoolong', new lang_string('invalidfullnametoolong', 'tool_uploadcourse', 254));
if (
!empty($coursedata['fullname']) &&
core_text::strlen($coursedata['fullname']) > \core_course\constants::FULLNAME_MAXIMUM_LENGTH
) {
$this->error('invalidfullnametoolong', new lang_string('invalidfullnametoolong', 'tool_uploadcourse',
\core_course\constants::FULLNAME_MAXIMUM_LENGTH));
return false;
}

View File

@ -1826,8 +1826,10 @@ abstract class restore_dbops {
}
// Ensure we don't overflow maximum length of name fields, in multi-byte safe manner.
$currentfullname = core_text::substr($fullname, 0, 254 - strlen($suffixfull)) . $suffixfull;
$currentshortname = core_text::substr($shortname, 0, 100 - strlen($suffixshort)) . $suffixshort;
$currentfullname = core_text::substr($fullname, 0,
\core_course\constants::FULLNAME_MAXIMUM_LENGTH - strlen($suffixfull)) . $suffixfull;
$currentshortname = core_text::substr($shortname, 0,
\core_course\constants::SHORTNAME_MAXIMUM_LENGTH - strlen($suffixshort)) . $suffixshort;
$coursefull = $DB->get_record_select('course', 'fullname = ? AND id != ?',
array($currentfullname, $courseid), '*', IGNORE_MULTIPLE);

View File

@ -89,13 +89,15 @@ class copy_form extends \moodleform {
$mform->addElement('html', \html_writer::div(get_string('copycoursedesc', 'backup'), 'form-description mb-6'));
// Course fullname.
$mform->addElement('text', 'fullname', get_string('fullnamecourse'), 'maxlength="254" size="50"');
$mform->addElement('text', 'fullname', get_string('fullnamecourse'),
['maxlength' => \core_course\constants::FULLNAME_MAXIMUM_LENGTH, 'size' => 50]);
$mform->addHelpButton('fullname', 'fullnamecourse');
$mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
$mform->setType('fullname', PARAM_TEXT);
// Course shortname.
$mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"');
$mform->addElement('text', 'shortname', get_string('shortnamecourse'),
['maxlength' => \core_course\constants::SHORTNAME_MAXIMUM_LENGTH, 'size' => 20]);
$mform->addHelpButton('shortname', 'shortnamecourse');
$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform->setType('shortname', PARAM_TEXT);

View File

@ -0,0 +1,33 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core_course;
/**
* Constants related to courses.
*
* @package core_course
* @copyright The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class constants {
/** @var int the length of the course.shortname field. */
public const FULLNAME_MAXIMUM_LENGTH = 1333;
/** @var int the length of the course.shortname field. */
public const SHORTNAME_MAXIMUM_LENGTH = 255;
}

View File

@ -58,7 +58,8 @@ class course_edit_form extends moodleform {
$mform->setType('returnurl', PARAM_LOCALURL);
$mform->setConstant('returnurl', $returnurl);
$mform->addElement('text','fullname', get_string('fullnamecourse'),'maxlength="254" size="50"');
$mform->addElement('text', 'fullname', get_string('fullnamecourse'),
['maxlength' => \core_course\constants::FULLNAME_MAXIMUM_LENGTH, 'size' => 50]);
$mform->addHelpButton('fullname', 'fullnamecourse');
$mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
$mform->setType('fullname', PARAM_TEXT);
@ -67,7 +68,8 @@ class course_edit_form extends moodleform {
$mform->setConstant('fullname', $course->fullname);
}
$mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"');
$mform->addElement('text', 'shortname', get_string('shortnamecourse'),
['maxlength' => \core_course\constants::SHORTNAME_MAXIMUM_LENGTH, 'size' => 20]);
$mform->addHelpButton('shortname', 'shortnamecourse');
$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform->setType('shortname', PARAM_TEXT);

View File

@ -58,12 +58,14 @@ class course_request_form extends moodleform {
$mform->addElement('header','coursedetails', get_string('courserequestdetails'));
$mform->addElement('text', 'fullname', get_string('fullnamecourse'), 'maxlength="254" size="50"');
$mform->addElement('text', 'fullname', get_string('fullnamecourse'),
['maxlength' => \core_course\constants::FULLNAME_MAXIMUM_LENGTH, 'size' => 50]);
$mform->addHelpButton('fullname', 'fullnamecourse');
$mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
$mform->setType('fullname', PARAM_TEXT);
$mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"');
$mform->addElement('text', 'shortname', get_string('shortnamecourse'),
['maxlength' => \core_course\constants::SHORTNAME_MAXIMUM_LENGTH, 'size' => 20]);
$mform->addHelpButton('shortname', 'shortnamecourse');
$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform->setType('shortname', PARAM_TEXT);

View File

@ -72,7 +72,7 @@
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<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="254" NOTNULL="true" 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="idnumber" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="summary" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
@ -400,8 +400,8 @@
<TABLE NAME="course_request" COMMENT="course requests">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="fullname" TYPE="char" LENGTH="254" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="shortname" TYPE="char" LENGTH="100" NOTNULL="true" 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="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"/>

View File

@ -1474,5 +1474,76 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2024110800.02);
}
if ($oldversion < 2024111500.00) {
// Changing precision of field fullname 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, 2024111500.00);
}
if ($oldversion < 2024111500.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, 2024111500.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 < 2024111500.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, 2024111500.02);
}
if ($oldversion < 2024111500.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, 'fullname');
// Launch change of precision for field shortname.
$dbman->change_field_precision($table, $field);
// Main savepoint reached.
upgrade_main_savepoint(true, 2024111500.03);
}
if ($oldversion < 2024111500.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, 2024111500.04);
}
return true;
}

View File

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2024111500.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2024111500.04; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '5.0dev (Build: 20241115)'; // Human-friendly version name