Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest

services:
postgres:
Expand All @@ -31,7 +31,7 @@ jobs:
fail-fast: false
matrix:
php: ['8.3', '8.4']
moodle-branch: ['main', 'MOODLE_501_STABLE', 'MOODLE_500_STABLE']
moodle-branch: ['main', 'MOODLE_502_STABLE']
database: [pgsql, mariadb]

steps:
Expand Down
22 changes: 7 additions & 15 deletions classes/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use core\event\course_module_updated;
use core\task\manager;
use core_course\task\content_notification_task;
use core_courseformat\formatactions;
use dml_exception;
use moodle_exception;
use require_login_exception;
Expand Down Expand Up @@ -174,7 +175,7 @@ public static function duplicate(array $modules, $sectionnumber = false): void {
}

try {
$duplicatedmod = duplicate_module($modinfo->get_course(), $modinfo->get_cm($cmid));
$duplicatedmod = formatactions::cm($courseid)->duplicate($cmid);
} catch (\Exception $e) {
$errors[$cmid] = 'cmid:' . $cmid . '(' . $e->getMessage() . ')';
$event = \block_massaction\event\course_modules_duplicated_failed::create([
Expand Down Expand Up @@ -204,7 +205,7 @@ public static function duplicate(array $modules, $sectionnumber = false): void {
}

// Move each module to the end of their section.
moveto_module($duplicatedmod, $section);
formatactions::cm($courseid)->move_end_section($duplicatedmod->id, $section->id);
}
$event = \block_massaction\event\course_modules_duplicated::create([
'context' => \context_course::instance($courseid),
Expand Down Expand Up @@ -393,7 +394,7 @@ public static function duplicate_to_course(array $modules, int $targetcourseid,
if ($sectionnum != -1) {
// A target section has been specified, so we have to move the course modules.
foreach ($duplicatedmods as $modid) {
moveto_module($targetmodinfo->get_cm($modid), $targetsection);
formatactions::cm($targetcourseid)->move_end_section($modid, $targetsection->id);
}
}
$event = \block_massaction\event\course_modules_duplicated::create([
Expand Down Expand Up @@ -526,8 +527,7 @@ public static function print_deletion_confirmation(
* @throws moodle_exception
*/
public static function perform_deletion(array $modules): void {
global $CFG, $DB;
require_once($CFG->dirroot . '/course/lib.php');
global $DB;

foreach ($modules as $cm) {
if (!$cm = get_coursemodule_from_id('', $cm->id, 0, true)) {
Expand All @@ -538,15 +538,7 @@ public static function perform_deletion(array $modules): void {
throw new moodle_exception('invalidcourseid');
}

$modlib = $CFG->dirroot . '/mod/' . $cm->modname . '/lib.php';

if (file_exists($modlib)) {
require_once($modlib);
} else {
new moodle_exception('modulemissingcode', '', '', $modlib);
}

course_delete_module($cm->id, true);
formatactions::cm($cm->course)->delete($cm->id, true);
}
}

Expand Down Expand Up @@ -663,7 +655,7 @@ public static function perform_moveto(array $modules, int $target): void {
}

// Move each module to the end of their section.
moveto_module($cm, $section);
formatactions::cm($cm->course)->move_end_section($cm->id, $section->id);
}
}

Expand Down
6 changes: 3 additions & 3 deletions classes/massactionutils.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public static function extract_modules_from_json(string $massactionrequest): std
/**
* This duplicates a course module to a *different* course.
*
* This function is mainly copied from 'duplicate_module' from /course/lib.php. Unfortunately, it seems that this function
* was once intended to also be able to duplicate a module to another course, but mid-function it started to be specific to
* the course the source module is part of.
* This function is mainly copied from 'duplicate_module' from /course/lib.php which since Moodle 5.2 has moved
* to cmactions::duplicate. Unfortunately, it seems that this function was once intended to also be able to duplicate
* a module to another course, but mid-function it started to be specific to the course the source module is part of.
*
* @param object $course course object.
* @param object $cm course module object to be duplicated.
Expand Down
35 changes: 21 additions & 14 deletions tests/massaction_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use coding_exception;
use core\event\course_module_updated;
use core\task\manager;
use core_courseformat\formatactions;
use dml_exception;
use moodle_exception;
use require_login_exception;
Expand Down Expand Up @@ -389,7 +390,8 @@ public function test_mass_hide_unhide_modules(): void {
$this->assertEquals(1, $module->visibleoncoursepage); // Visible on course page in a visible section.

// Hide section.
set_section_visible($this->course->id, $module->sectionnum, 0);
$sectioninfo = get_fast_modinfo($this->course)->get_section_info($module->sectionnum);
formatactions::section($this->course->id)->set_visibility($sectioninfo, false);
$module = get_fast_modinfo($this->course)->get_cm($moduleid);
// After section has been hidden the course module should also be hidden.
$this->assertEquals(0, $module->visible); // Hidden in a hidden section.
Expand Down Expand Up @@ -421,7 +423,8 @@ public function test_mass_hide_unhide_modules(): void {

// Just to doublecheck that a visible section behaves differently.
// Available modules in visible sections are not visible on course page.
set_section_visible($this->course->id, $module->sectionnum, 1);
$sectioninfo = get_fast_modinfo($this->course)->get_section_info($module->sectionnum);
formatactions::section($this->course->id)->set_visibility($sectioninfo, true);
actions::set_visibility([$module], true, false);
$module = get_fast_modinfo($this->course)->get_cm($moduleid);
$this->assertEquals(1, $module->visible);
Expand Down Expand Up @@ -887,21 +890,25 @@ private function shuffle_modules(): void {
// Reason: We want to see if the order in the section is preserved which usually is different from the module ids.
// The method to be tested should follow the sections order. To be able to see the correct effect we have to ensure that
// the order of moduleids isn't the same as the order in the section.
moveto_module(
get_fast_modinfo($this->course->id)->get_cm(get_fast_modinfo($this->course->id)->get_sections()[1][0]),
get_fast_modinfo($this->course->id)->get_section_info(1)
$modinfo = get_fast_modinfo($this->course->id);
formatactions::cm($this->course->id)->move_end_section(
$modinfo->get_sections()[1][0],
$modinfo->get_section_info(1)->id
);
moveto_module(
get_fast_modinfo($this->course->id)->get_cm(get_fast_modinfo($this->course->id)->get_sections()[1][3]),
get_fast_modinfo($this->course->id)->get_section_info(1)
$modinfo = get_fast_modinfo($this->course->id);
formatactions::cm($this->course->id)->move_end_section(
$modinfo->get_sections()[1][3],
$modinfo->get_section_info(1)->id
);
moveto_module(
get_fast_modinfo($this->course->id)->get_cm(get_fast_modinfo($this->course->id)->get_sections()[3][0]),
get_fast_modinfo($this->course->id)->get_section_info(3)
$modinfo = get_fast_modinfo($this->course->id);
formatactions::cm($this->course->id)->move_end_section(
$modinfo->get_sections()[3][0],
$modinfo->get_section_info(3)->id
);
moveto_module(
get_fast_modinfo($this->course->id)->get_cm(get_fast_modinfo($this->course->id)->get_sections()[3][3]),
get_fast_modinfo($this->course->id)->get_section_info(3)
$modinfo = get_fast_modinfo($this->course->id);
formatactions::cm($this->course->id)->move_end_section(
$modinfo->get_sections()[3][3],
$modinfo->get_section_info(3)->id
);
}

Expand Down
8 changes: 4 additions & 4 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

defined('MOODLE_INTERNAL') || die;

$plugin->version = 2025102700;
$plugin->requires = 2023100900;
$plugin->version = 2026042700;
$plugin->requires = 2024042000;
$plugin->component = 'block_massaction';
$plugin->maturity = MATURITY_STABLE;
$plugin->release = 'v7.5.1';
$plugin->supported = [500, 501];
$plugin->release = 'v8.0.0';
$plugin->supported = [502, 502];
Loading