Merge branch 'MDL-87280-main' of https://github.com/sarjona/moodle

This commit is contained in:
Sara Arjona
2025-12-29 14:51:30 +01:00
6 changed files with 194 additions and 1 deletions
@@ -0,0 +1,8 @@
issueNumber: MDL-87280
notes:
mod_subsection:
- message: >-
A new scheduled task, `remove_existing_descriptions`, has been added.
Once enabled, this task will remove the descriptions for all existing
subsection instances.
type: improved
@@ -0,0 +1,46 @@
<?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 mod_subsection\task;
use core\task\scheduled_task;
/**
* A scheduled task to remove existing descriptions from subsection instances.
*
* @package mod_subsection
* @copyright 2025 Sara Arjona <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class remove_existing_descriptions_task extends scheduled_task {
/**
* Return the task name.
*
* @return string The name of the task.
*/
public function get_name(): string {
return get_string('removeexistingdescriptions', 'mod_subsection');
}
/**
* Execute the task.
*/
public function execute(): void {
global $DB;
$DB->set_field('course_sections', 'summary', '', ['component' => 'mod_subsection']);
}
}
+39
View File
@@ -0,0 +1,39 @@
<?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/>.
/**
* Definition of Subsection scheduled tasks.
*
* @package mod_subsection
* @category task
* @copyright 2025 Sara Arjona <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$tasks = [
[
'classname' => '\mod_subsection\task\remove_existing_descriptions_task',
'blocking' => 0,
'minute' => 'R',
'hour' => '0',
'day' => '*',
'dayofweek' => '*',
'month' => '*',
'disabled' => true,
],
];
@@ -29,6 +29,7 @@ $string['pluginadministration'] = 'Subsection administration';
$string['pluginname'] = 'Subsection';
$string['privacy:metadata'] = 'Subsection does not store any personal data';
$string['quickcreatename'] = 'New subsection';
$string['removeexistingdescriptions'] = 'Remove existing descriptions from subsection instances';
$string['subsection:addinstance'] = 'Add subsection';
$string['subsection:view'] = 'View subsection';
$string['subsectionname'] = 'Name';
@@ -0,0 +1,99 @@
<?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 mod_subsection\task;
/**
* Class containing unit tests for the remove existing descriptions task.
*
* @package mod_subsection
* @copyright 2025 Sara Arjona <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
#[\PHPUnit\Framework\Attributes\CoversClass(remove_existing_descriptions_task::class)]
final class remove_existing_descriptions_task_test extends \advanced_testcase {
/**
* Test remove_existing_descriptions task.
*/
public function test_remove_existing_descriptions(): void {
global $DB;
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course(['format' => 'topics', 'numsections' => 1]);
$this->getDataGenerator()->create_module('subsection', ['course' => $course->id, 'section' => 1]);
// Add description to course sections and the subsection.
$DB->set_field(
'course_sections',
'summary',
'Section with description',
['course' => $course->id],
);
// Add another subsection without description.
$this->getDataGenerator()->create_module('subsection', ['course' => $course->id, 'section' => 1]);
// Check only 2 sections and 1 subsection have description.
$this->assertEquals(
3,
$DB->count_records_select(
'course_sections',
'course = :courseid AND summary != \'\'',
['courseid' => $course->id],
),
);
$this->assertEquals(
2,
$DB->count_records_select(
'course_sections',
'course = :courseid AND component = \'mod_subsection\'',
['courseid' => $course->id],
),
);
$this->assertEquals(
1,
$DB->count_records_select(
'course_sections',
'course = :courseid AND component = \'mod_subsection\' AND summary != \'\'',
['courseid' => $course->id],
),
);
// Run the task.
ob_start();
$task = new remove_existing_descriptions_task();
$task->execute();
ob_end_clean();
// Check only 2 sections keep having description after running the task.
$this->assertEquals(
2,
$DB->count_records_select(
'course_sections',
'course = :courseid AND summary != \'\'',
['courseid' => $course->id],
),
);
// Check no subsection has description after running the task.
$this->assertEquals(
0,
$DB->count_records_select(
'course_sections',
'course = :courseid AND component = \'mod_subsection\' AND summary != \'\'',
['courseid' => $course->id],
),
);
}
}
+1 -1
View File
@@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'mod_subsection';
$plugin->version = 2025100600;
$plugin->version = 2025100601;
$plugin->requires = 2025092600;
$plugin->maturity = MATURITY_STABLE;