From ad96f6a924bc029cb671802ffc211cf406e487d8 Mon Sep 17 00:00:00 2001 From: bmarcinkowski Date: Thu, 8 Oct 2026 15:56:45 +0200 Subject: [PATCH 01/10] fix: stop deleting ClickMeeting rooms that are still in use Meetings and recordings were disappearing from ClickMeeting without anyone deleting them on purpose, across unrelated courses and subaccounts. Three separate defects in the deletion path caused it. Deleting a Moodle activity called DELETE on the API straight away. Moodle deletion is reversible - it goes through the recycle bin and runs from cron - so the room was destroyed while the activity could still come back, and the API call landed minutes or hours after the click that caused it. Rooms now outlive their activity by a configurable grace period, five months by default, and a new scheduled task deletes them once it expires. Copying, importing or restoring a course duplicates the activity but both copies keep the same conference_id, so deleting either one destroyed the shared room for the other, in a course nobody had touched. The room is now only deleted once no activity refers to it, which also covers an activity restored from the recycle bin. The API key came from whoever was acting rather than from the room's owner. Under cron that is nobody in particular, so the call fell back to the main account key and could reach a room on a different subaccount. The owner is now carried through to the deletion. Also fixes two defects found along the way: an activity whose conference row was missing could never be deleted at all, and access tokens identifying participants were left behind in the database. Adds a room_deleted event so a missing meeting can be traced to when and why it was removed. Co-Authored-By: Claude Opus 5 (1M context) --- CHANGELOG.md | 39 +++ classes/event/room_deleted.php | 56 ++++ classes/privacy/provider.php | 4 + classes/task/purge_deleted_rooms.php | 85 +++++++ db/install.xml | 15 ++ db/tasks.php | 37 +++ db/upgrade.php | 17 ++ lang/en/clickmeeting.php | 7 + lang/pl/clickmeeting.php | 7 + lib.php | 88 +++++-- settings.php | 7 + tests/lib_test.php | 365 +++++++++++++++++++++++++++ version.php | 2 +- 13 files changed, 705 insertions(+), 24 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 classes/event/room_deleted.php create mode 100644 classes/task/purge_deleted_rooms.php create mode 100644 db/tasks.php create mode 100644 tests/lib_test.php diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..cabbe17 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,39 @@ +# Changelog + +## v1.2.0 (2026-10-08) + +Fixes meetings and recordings disappearing from ClickMeeting without anyone deleting them +on purpose. + +### Fixed + +- **Deleting an activity no longer destroys the room immediately.** Moodle activity deletion + is reversible — it goes through the recycle bin and runs from cron — but the room in + ClickMeeting was being deleted right away. Restoring the activity brought back a link to a + room that no longer existed. Rooms now outlive their activity by a configurable grace + period, five months by default. +- **A room shared by several activities survives.** Copying, importing or restoring a course + duplicates the activity while both copies keep pointing at the same ClickMeeting room. + Deleting either copy destroyed the room for the other one, in a course nobody had touched. + A room is now only deleted once no activity refers to it. +- **Deletions use the room owner's API key.** The key was taken from whoever happened to be + acting, which under cron is nobody in particular, so the request fell back to the main + account key and could reach a room on a different subaccount. +- **Activities whose room record is missing can be deleted again.** Previously the deletion + failed indefinitely and the activity could never be removed from the course. +- **Access tokens are removed with their activity.** They identify participants and were + being left behind in the database. + +### Added + +- Admin setting "Keep deleted rooms for" (`clickmeeting/graceperiod`), default five months. +- Scheduled task `mod_clickmeeting\task\purge_deleted_rooms`, which deletes rooms once their + grace period has passed. Runs daily at 03:20. +- Event `mod_clickmeeting\event\room_deleted`, logged whenever a room is really deleted, so + a missing meeting can be traced back to when and why it went away. +- PHPUnit coverage for the deletion lifecycle. + +### Upgrade notes + +Adds the table `clickmeeting_pending_deletions`. Existing data is untouched. Rooms already +deleted before this release cannot be recovered. diff --git a/classes/event/room_deleted.php b/classes/event/room_deleted.php new file mode 100644 index 0000000..d7a9ae5 --- /dev/null +++ b/classes/event/room_deleted.php @@ -0,0 +1,56 @@ +. + +namespace mod_clickmeeting\event; + +/** + * Fired when a room is permanently removed from ClickMeeting. + * + * Deletion happens long after the Moodle activity disappears, so this event is what + * ties a missing meeting back to the moment and the reason it was destroyed. + * + * @package mod_clickmeeting + * @copyright 2026 Clickmeeting + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class room_deleted extends \core\event\base { + /** + * Sets the event metadata. + */ + protected function init() { + $this->data['crud'] = 'd'; + $this->data['edulevel'] = self::LEVEL_OTHER; + } + + /** + * Returns the localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('event:roomdeleted', 'clickmeeting'); + } + + /** + * Returns a description of what happened. + * + * @return string + */ + public function get_description() { + return "The ClickMeeting room with id '{$this->other['conferenceid']}' was deleted " . + "because its Moodle activity had been removed and the grace period expired."; + } +} diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 51fa13a..e05bdb8 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -52,6 +52,10 @@ public static function get_metadata(collection $collection): collection { 'user_id' => 'privacy:metadata:clickmeetingtokens:userid', ], 'privacy:metadata:clickmeetingtokens'); + $collection->add_database_table('clickmeeting_pending_deletions', [ + 'user_id' => 'privacy:metadata:clickmeetingpendingdeletions:userid', + ], 'privacy:metadata:clickmeetingpendingdeletions'); + $collection->add_external_location_link('clickmeeting.com', [ 'email' => 'privacy:metadata:clickmeeting_api:email', 'nickname' => 'privacy:metadata:clickmeeting_api:nickname', diff --git a/classes/task/purge_deleted_rooms.php b/classes/task/purge_deleted_rooms.php new file mode 100644 index 0000000..db5aa8f --- /dev/null +++ b/classes/task/purge_deleted_rooms.php @@ -0,0 +1,85 @@ +. + +namespace mod_clickmeeting\task; + +use mod_clickmeeting\event\room_deleted; + +/** + * Removes rooms whose Moodle activity is gone and whose grace period has expired. + * + * @package mod_clickmeeting + * @copyright 2026 Clickmeeting + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class purge_deleted_rooms extends \core\task\scheduled_task { + /** + * Returns the localised task name. + * + * @return string + */ + public function get_name() { + return get_string('task:purgedeletedrooms', 'clickmeeting'); + } + + /** + * Deletes every room that is past its grace period and no longer referenced. + */ + public function execute() { + global $DB, $CFG, $clickmeetingowner; + + require_once($CFG->dirroot . '/mod/clickmeeting/lib.php'); + + $cutoff = time() - clickmeeting_get_grace_period(); + $pending = $DB->get_records_select( + 'clickmeeting_pending_deletions', + 'timescheduled <= :cutoff', + ['cutoff' => $cutoff] + ); + + foreach ($pending as $record) { + // Another activity - a course copy, an import, an activity restored from the recycle + // bin - points at this room again, so deleting it would take the meeting away from them. + if ($DB->record_exists('clickmeeting_conferences', ['conference_id' => $record->conference_id])) { + mtrace("Room {$record->conference_id} is in use again, cancelling its deletion."); + $DB->delete_records('clickmeeting_pending_deletions', ['id' => $record->id]); + continue; + } + + // The room belongs to whoever created it, so it has to be deleted with their API key. + $clickmeetingowner = $record->user_id; + $apiresult = clickmeeting_delete_conference($record->conference_id); + + if ('"200 OK"' !== $apiresult && '"404 Not Found"' !== $apiresult) { + // Leave the record alone so the next run retries it. + mtrace("Could not delete room {$record->conference_id}, will retry: {$apiresult}"); + continue; + } + + $DB->delete_records('clickmeeting_pending_deletions', ['id' => $record->id]); + + if ('"200 OK"' === $apiresult) { + room_deleted::create([ + 'context' => \context_system::instance(), + 'other' => ['conferenceid' => $record->conference_id], + ])->trigger(); + mtrace("Deleted room {$record->conference_id}."); + } else { + mtrace("Room {$record->conference_id} was already gone from ClickMeeting."); + } + } + } +} diff --git a/db/install.xml b/db/install.xml index 32d07e5..58ea2c7 100755 --- a/db/install.xml +++ b/db/install.xml @@ -56,5 +56,20 @@ + + + + + + + + + + + + + + +
diff --git a/db/tasks.php b/db/tasks.php new file mode 100644 index 0000000..882e33e --- /dev/null +++ b/db/tasks.php @@ -0,0 +1,37 @@ +. + +/** + * Scheduled task definitions for mod_clickmeeting. + * + * @package mod_clickmeeting + * @copyright 2026 Clickmeeting + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$tasks = [ + [ + 'classname' => 'mod_clickmeeting\task\purge_deleted_rooms', + 'blocking' => 0, + 'minute' => '20', + 'hour' => '3', + 'day' => '*', + 'dayofweek' => '*', + 'month' => '*', + ], +]; diff --git a/db/upgrade.php b/db/upgrade.php index 8eb76de..4eec213 100755 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -221,6 +221,23 @@ function xmldb_clickmeeting_upgrade($oldversion) { upgrade_mod_savepoint(true, 2018101000, 'clickmeeting'); } + if ($oldversion < 2026100800) { + $table = new xmldb_table('clickmeeting_pending_deletions'); + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, true, null); + $table->add_field('conference_id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); + $table->add_field('user_id', XMLDB_TYPE_INTEGER, '10', null, null, null, null); + $table->add_field('timescheduled', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); + $table->add_index('conference_id', XMLDB_INDEX_UNIQUE, ['conference_id']); + $table->add_index('timescheduled', XMLDB_INDEX_NOTUNIQUE, ['timescheduled']); + + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + upgrade_mod_savepoint(true, 2026100800, 'clickmeeting'); + } + // And that's all. Please, examine and understand the 3 example blocks above. Also // it's interesting to look how other modules are using this script. Remember that // the basic idea is to have "blocks" of code (each one being executed only once, diff --git a/lang/en/clickmeeting.php b/lang/en/clickmeeting.php index e64e11b..36d6155 100755 --- a/lang/en/clickmeeting.php +++ b/lang/en/clickmeeting.php @@ -84,3 +84,10 @@ $string['privacy:metadata:clickmeetingtokens:userid'] = 'Access token is stored in context of user'; $string['privacy:metadata:clickmeetingtokens'] = 'Plugin stores tokens assigned to particular user'; + +$string['settings:graceperiod'] = 'Keep deleted rooms for'; +$string['settings:graceperioddesc'] = 'How long a ClickMeeting room survives after its Moodle activity was deleted. During this time the meeting and its recordings stay reachable in ClickMeeting, and restoring the activity from the recycle bin reconnects it to the same room. Set to zero to use the default of five months.'; +$string['task:purgedeletedrooms'] = 'Delete ClickMeeting rooms past their grace period'; +$string['event:roomdeleted'] = 'ClickMeeting room deleted'; +$string['privacy:metadata:clickmeetingpendingdeletions'] = 'Plugin remembers which rooms are awaiting deletion in ClickMeeting.'; +$string['privacy:metadata:clickmeetingpendingdeletions:userid'] = 'The owner of the room is kept so that the deletion uses their API key.'; diff --git a/lang/pl/clickmeeting.php b/lang/pl/clickmeeting.php index ecdcb91..09048c3 100755 --- a/lang/pl/clickmeeting.php +++ b/lang/pl/clickmeeting.php @@ -83,3 +83,10 @@ $string['privacy:metadata:clickmeetingtokens:userid'] = 'Token dostępowy do wydarzenia przechowywany w kontekście użytkownika'; $string['privacy:metadata:clickmeetingtokens'] = 'Moduł przechowuje listę wygenerowanych tokenów dla uczestników'; + +$string['settings:graceperiod'] = 'Przechowuj usunięte pokoje przez'; +$string['settings:graceperioddesc'] = 'Jak długo pokój ClickMeeting istnieje po usunięciu powiązanej aktywności w Moodle. Przez ten czas wydarzenie i jego nagrania pozostają dostępne w ClickMeeting, a przywrócenie aktywności z kosza podłącza ją z powrotem do tego samego pokoju. Wartość zero oznacza domyślne pięć miesięcy.'; +$string['task:purgedeletedrooms'] = 'Usuwanie pokoi ClickMeeting po okresie karencji'; +$string['event:roomdeleted'] = 'Usunięto pokój ClickMeeting'; +$string['privacy:metadata:clickmeetingpendingdeletions'] = 'Moduł przechowuje informację o pokojach oczekujących na usunięcie w ClickMeeting.'; +$string['privacy:metadata:clickmeetingpendingdeletions:userid'] = 'Właściciel pokoju jest zapamiętywany, aby usunięcie wykonać jego kluczem API.'; diff --git a/lib.php b/lib.php index 5c218d0..6d98c06 100755 --- a/lib.php +++ b/lib.php @@ -30,6 +30,14 @@ defined('MOODLE_INTERNAL') || die(); +/** + * How long a room outlives its Moodle activity when the admin has not chosen otherwise. + * + * Roughly five months, which keeps meetings and their recordings reachable in ClickMeeting + * well past the point where Moodle itself has forgotten the activity. + */ +define('CLICKMEETING_DEFAULT_GRACE_PERIOD', 150 * DAYSECS); + $clickmeetingauthtypes = [ '1' => 'open', '2' => 'password', @@ -94,18 +102,27 @@ function clickmeeting_check_conference_availability($starttime, $duration, $id = } /** + * Returns the API key to talk to ClickMeeting with. + * + * A room lives on the subaccount that created it, so calls about an existing room must use + * its owner's key. $clickmeetingowner carries that owner; it matters most under cron, where + * the acting user is nobody in particular and the global key would hit the wrong subaccount. * * @return string */ function clickmeeting_get_api_key() { - global $DB, $CFG, $USER; - require_once($CFG->dirroot.'/user/profile/lib.php'); + global $DB, $CFG, $USER, $clickmeetingowner; + require_once($CFG->dirroot . '/user/profile/lib.php'); + + $ownerid = !empty($clickmeetingowner) ? $clickmeetingowner : $USER->id; + $user = $DB->get_record('user', ['id' => $ownerid]); - $user = $DB->get_record('user', ['id' => $USER->id]); - profile_load_data($user); + if ($user) { + profile_load_data($user); - if (isset($user->profile_field_clickmeetingapikey) && !empty($user->profile_field_clickmeetingapikey)) { - return $user->profile_field_clickmeetingapikey; + if (!empty($user->profile_field_clickmeetingapikey)) { + return $user->profile_field_clickmeetingapikey; + } } return get_config('clickmeeting', 'apikey'); @@ -429,7 +446,7 @@ function clickmeeting_update_instance(stdClass $clickmeeting, mod_clickmeeting_m * @return boolean Success/Failure */ function clickmeeting_delete_instance($id) { - global $DB, $COURSE, $clickmeetingowner; + global $DB, $clickmeetingowner; if (! $clickmeeting = $DB->get_record('clickmeeting', ['id' => $id])) { return false; @@ -437,29 +454,54 @@ function clickmeeting_delete_instance($id) { $clickmeetingowner = $clickmeeting->user_id; - if (0 < $DB->count_records('clickmeeting_conferences', ['clickmeeting_id' => $clickmeeting->id])) { - $conferenceid = $DB->get_field('clickmeeting_conferences', 'conference_id', ['clickmeeting_id' => $clickmeeting->id]); - } else { - return false; - } - - $apiresult = clickmeeting_delete_conference($conferenceid); + $conferenceid = $DB->get_field('clickmeeting_conferences', 'conference_id', ['clickmeeting_id' => $clickmeeting->id]); - if ('"200 OK"' != $apiresult) { - // jezeli nie znajdujemy conferencji w clickmeetingu to nie trzeba jej tam usuwac - if ('"404 Not Found"' == $apiresult) { - throw new \moodle_exception('api_404_error', 'clickmeeting'); - } - } + $DB->delete_records('clickmeeting_conferences', ['clickmeeting_id' => $clickmeeting->id]); + // Tokens identify participants, so they must not outlive the activity they were issued for. + $DB->delete_records('clickmeeting_tokens', ['clickmeeting_id' => $clickmeeting->id]); + $DB->delete_records('clickmeeting', ['id' => $clickmeeting->id]); - if (0 < $DB->count_records('clickmeeting_conferences', ['clickmeeting_id' => $clickmeeting->id])) { - $DB->delete_records('clickmeeting_conferences', ['clickmeeting_id' => $clickmeeting->id]); + // The room itself outlives the activity for the configured grace period. Moodle deletions are + // reversible from the recycle bin, and a course copy may still point at this very room, so + // destroying it here would take meetings and recordings away from users who never asked for it. + if (!empty($conferenceid)) { + clickmeeting_schedule_room_deletion($conferenceid, $clickmeeting->user_id); } - $DB->delete_records('clickmeeting', ['id' => $clickmeeting->id]); return true; } +/** + * Marks a room for deletion once the grace period has passed. + * + * Re-scheduling an already pending room restarts its grace period, so the room always + * survives for the full period after the last activity pointing at it went away. + * + * @param int $conferenceid Room id in ClickMeeting. + * @param int|null $ownerid User whose API key created the room. + */ +function clickmeeting_schedule_room_deletion($conferenceid, $ownerid) { + global $DB; + + $DB->delete_records('clickmeeting_pending_deletions', ['conference_id' => $conferenceid]); + $DB->insert_record('clickmeeting_pending_deletions', (object) [ + 'conference_id' => $conferenceid, + 'user_id' => $ownerid, + 'timescheduled' => time(), + ]); +} + +/** + * Returns how long a room is kept after its activity was deleted. + * + * @return int Grace period in seconds. + */ +function clickmeeting_get_grace_period() { + $graceperiod = (int) get_config('clickmeeting', 'graceperiod'); + + return $graceperiod > 0 ? $graceperiod : CLICKMEETING_DEFAULT_GRACE_PERIOD; +} + /** * Returns a small object with summary information about what a * user has done with a given particular instance of this module diff --git a/settings.php b/settings.php index facfe33..d27190d 100755 --- a/settings.php +++ b/settings.php @@ -37,4 +37,11 @@ get_string('settings:apikey', 'clickmeeting'), get_string('settings:apikeydesc', 'clickmeeting'), '')); + + $settings->add(new admin_setting_configduration( + 'clickmeeting/graceperiod', + get_string('settings:graceperiod', 'clickmeeting'), + get_string('settings:graceperioddesc', 'clickmeeting'), + CLICKMEETING_DEFAULT_GRACE_PERIOD + )); } diff --git a/tests/lib_test.php b/tests/lib_test.php new file mode 100644 index 0000000..1bf66c3 --- /dev/null +++ b/tests/lib_test.php @@ -0,0 +1,365 @@ +. + +namespace mod_clickmeeting; + +/** + * Tests for the clickmeeting activity library. + * + * @package mod_clickmeeting + * @copyright 2026 Clickmeeting + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +final class lib_test extends \advanced_testcase { + /** @var string Response the ClickMeeting API returns when a room was deleted. */ + private const API_OK = '"200 OK"'; + + /** + * Loads the plugin library under test. + */ + public static function setUpBeforeClass(): void { + global $CFG; + require_once($CFG->dirroot . '/mod/clickmeeting/lib.php'); + parent::setUpBeforeClass(); + } + + /** + * Points the plugin at a dead address, so a test that unexpectedly reaches for the + * network fails fast instead of talking to the real ClickMeeting API. + */ + protected function setUp(): void { + global $clickmeetingowner; + + parent::setUp(); + $this->resetAfterTest(); + set_config('apiurl', 'http://127.0.0.1:9/', 'clickmeeting'); + $clickmeetingowner = null; + } + + /** + * Creates an activity row together with its conference row. + * + * @param int $courseid Course the activity belongs to. + * @param int $conferenceid ClickMeeting room id the activity points at. + * @param int $ownerid User owning the room. + * @return int Id of the new clickmeeting record. + */ + private function create_activity(int $courseid, int $conferenceid, int $ownerid): int { + global $DB; + + $instanceid = $DB->insert_record('clickmeeting', (object) [ + 'course' => $courseid, + 'name' => 'Webinar', + 'user_id' => $ownerid, + 'introformat' => 0, + 'timecreated' => time(), + 'timemodified' => time(), + ]); + $DB->insert_record('clickmeeting_conferences', (object) [ + 'clickmeeting_id' => $instanceid, + 'conference_id' => $conferenceid, + ]); + + return $instanceid; + } + + /** + * Runs the purge task, capturing the progress output it writes. + * + * @return string Whatever the task reported. + */ + private function run_purge_task(): string { + ob_start(); + (new \mod_clickmeeting\task\purge_deleted_rooms())->execute(); + + return ob_get_clean(); + } + + /** + * Asserts that nothing so far spoke to the API, by showing that a queued mock response + * is still waiting to be handed out. Consuming it here also keeps the queue, which Moodle + * does not reset between tests, from leaking into the next one. + */ + private function assert_api_was_not_called(): void { + $leftover = (new \curl())->get('http://127.0.0.1:9/'); + + $this->assertEquals(self::API_OK, $leftover, 'The ClickMeeting API should not have been called.'); + } + + /** + * Deleting an activity must not destroy the room straight away, because Moodle + * deletions are reversible from the recycle bin. + */ + public function test_delete_instance_schedules_room_deletion_instead_of_calling_api(): void { + global $DB; + + $this->resetAfterTest(); + $course = $this->getDataGenerator()->create_course(); + $owner = $this->getDataGenerator()->create_user(); + $instanceid = $this->create_activity($course->id, 777001, $owner->id); + + $this->assertTrue(clickmeeting_delete_instance($instanceid)); + + $this->assertFalse($DB->record_exists('clickmeeting', ['id' => $instanceid])); + $pending = $DB->get_record('clickmeeting_pending_deletions', ['conference_id' => 777001]); + $this->assertNotFalse($pending, 'Room deletion should have been scheduled.'); + $this->assertEquals($owner->id, $pending->user_id); + } + + /** + * Once the grace period has passed the room is really gone from ClickMeeting. + */ + public function test_purge_task_deletes_room_once_grace_period_expired(): void { + global $DB; + + $this->resetAfterTest(); + set_config('graceperiod', WEEKSECS, 'clickmeeting'); + $owner = $this->getDataGenerator()->create_user(); + $DB->insert_record('clickmeeting_pending_deletions', (object) [ + 'conference_id' => 777002, + 'user_id' => $owner->id, + 'timescheduled' => time() - WEEKSECS - 1, + ]); + \curl::mock_response(self::API_OK); + + $sink = $this->redirectEvents(); + $this->run_purge_task(); + $events = $sink->get_events(); + $sink->close(); + + $this->assertFalse($DB->record_exists('clickmeeting_pending_deletions', ['conference_id' => 777002])); + $this->assertCount(1, $events); + $this->assertInstanceOf(\mod_clickmeeting\event\room_deleted::class, $events[0]); + $this->assertEquals(777002, $events[0]->other['conferenceid']); + } + + /** + * Within the grace period the room must be left alone, so that restoring the activity + * from the recycle bin gives the meeting and its recordings back. + */ + public function test_purge_task_keeps_room_within_grace_period(): void { + global $DB; + + $this->resetAfterTest(); + set_config('graceperiod', WEEKSECS, 'clickmeeting'); + $owner = $this->getDataGenerator()->create_user(); + $DB->insert_record('clickmeeting_pending_deletions', (object) [ + 'conference_id' => 777003, + 'user_id' => $owner->id, + 'timescheduled' => time() - DAYSECS, + ]); + \curl::mock_response(self::API_OK); + + $sink = $this->redirectEvents(); + $this->run_purge_task(); + $events = $sink->get_events(); + $sink->close(); + + $this->assertTrue($DB->record_exists('clickmeeting_pending_deletions', ['conference_id' => 777003])); + $this->assertCount(0, $events); + $this->assert_api_was_not_called(); + } + + /** + * A room shared with another activity - a course copy, an import, a restore - must survive + * the deletion of any single activity pointing at it. + */ + public function test_purge_task_spares_room_still_used_by_another_activity(): void { + global $DB; + + $this->resetAfterTest(); + set_config('graceperiod', WEEKSECS, 'clickmeeting'); + $course = $this->getDataGenerator()->create_course(); + $owner = $this->getDataGenerator()->create_user(); + $this->create_activity($course->id, 777004, $owner->id); + $DB->insert_record('clickmeeting_pending_deletions', (object) [ + 'conference_id' => 777004, + 'user_id' => $owner->id, + 'timescheduled' => time() - WEEKSECS - 1, + ]); + \curl::mock_response(self::API_OK); + + $sink = $this->redirectEvents(); + $this->run_purge_task(); + $events = $sink->get_events(); + $sink->close(); + + $this->assertCount(0, $events, 'A room another activity still points at must not be deleted.'); + $this->assert_api_was_not_called(); + $this->assertFalse($DB->record_exists('clickmeeting_pending_deletions', ['conference_id' => 777004])); + } + + /** + * An activity whose room row is missing must still be removable, otherwise Moodle keeps + * throwing on every attempt and the activity can never be deleted. + */ + public function test_delete_instance_removes_activity_that_has_no_room(): void { + global $DB; + + $course = $this->getDataGenerator()->create_course(); + $owner = $this->getDataGenerator()->create_user(); + $instanceid = $DB->insert_record('clickmeeting', (object) [ + 'course' => $course->id, + 'name' => 'Webinar without a room', + 'user_id' => $owner->id, + 'introformat' => 0, + 'timecreated' => time(), + 'timemodified' => time(), + ]); + + $this->assertTrue(clickmeeting_delete_instance($instanceid)); + + $this->assertFalse($DB->record_exists('clickmeeting', ['id' => $instanceid])); + $this->assertEquals(0, $DB->count_records('clickmeeting_pending_deletions')); + } + + /** + * A room already gone from ClickMeeting is simply forgotten, without pretending we deleted it. + */ + public function test_purge_task_forgets_room_that_no_longer_exists(): void { + global $DB; + + set_config('graceperiod', WEEKSECS, 'clickmeeting'); + $owner = $this->getDataGenerator()->create_user(); + $DB->insert_record('clickmeeting_pending_deletions', (object) [ + 'conference_id' => 777005, + 'user_id' => $owner->id, + 'timescheduled' => time() - WEEKSECS - 1, + ]); + \curl::mock_response('"404 Not Found"'); + + $sink = $this->redirectEvents(); + $this->run_purge_task(); + $events = $sink->get_events(); + $sink->close(); + + $this->assertFalse($DB->record_exists('clickmeeting_pending_deletions', ['conference_id' => 777005])); + $this->assertCount(0, $events, 'Nothing was deleted, so no deletion should be reported.'); + } + + /** + * A failing API call must not lose the room: the record stays so the next run retries it. + */ + public function test_purge_task_retries_room_after_a_failed_api_call(): void { + global $DB; + + set_config('graceperiod', WEEKSECS, 'clickmeeting'); + $owner = $this->getDataGenerator()->create_user(); + $DB->insert_record('clickmeeting_pending_deletions', (object) [ + 'conference_id' => 777006, + 'user_id' => $owner->id, + 'timescheduled' => time() - WEEKSECS - 1, + ]); + \curl::mock_response('{"errors":[{"message":"Service unavailable"}]}'); + + $output = $this->run_purge_task(); + + $this->assertTrue($DB->record_exists('clickmeeting_pending_deletions', ['conference_id' => 777006])); + $this->assertStringContainsString('will retry', $output); + } + + /** + * Rooms live on the subaccount that created them, so calls must use the owner's key even + * when somebody else - or cron, acting as nobody - triggers the deletion. + */ + public function test_api_key_belongs_to_the_room_owner_not_the_acting_user(): void { + global $clickmeetingowner; + + set_config('apikey', 'main-account-key', 'clickmeeting'); + $this->getDataGenerator()->create_custom_profile_field([ + 'datatype' => 'text', + 'shortname' => 'clickmeetingapikey', + 'name' => 'ClickMeeting API key', + ]); + $owner = $this->getDataGenerator()->create_user(['profile_field_clickmeetingapikey' => 'subaccount-key']); + $this->setUser($this->getDataGenerator()->create_user()); + + $clickmeetingowner = $owner->id; + + $this->assertEquals('subaccount-key', clickmeeting_get_api_key()); + } + + /** + * With no owner on record the global key is the only sensible choice, and a missing user + * must not bring the whole deletion down. + */ + public function test_api_key_falls_back_to_the_global_key_for_an_unknown_owner(): void { + global $clickmeetingowner; + + set_config('apikey', 'main-account-key', 'clickmeeting'); + $this->setUser($this->getDataGenerator()->create_user()); + + $clickmeetingowner = 999999; + + $this->assertEquals('main-account-key', clickmeeting_get_api_key()); + } + + /** + * Access tokens carry user data, so they must not survive the activity they belong to. + */ + public function test_delete_instance_removes_access_tokens(): void { + global $DB; + + $course = $this->getDataGenerator()->create_course(); + $owner = $this->getDataGenerator()->create_user(); + $participant = $this->getDataGenerator()->create_user(); + $instanceid = $this->create_activity($course->id, 777007, $owner->id); + $DB->insert_record('clickmeeting_tokens', (object) [ + 'clickmeeting_id' => $instanceid, + 'conference_id' => 777007, + 'user_id' => $participant->id, + 'token' => 'abc123', + ]); + + clickmeeting_delete_instance($instanceid); + + $this->assertEquals(0, $DB->count_records('clickmeeting_tokens', ['clickmeeting_id' => $instanceid])); + } + + /** + * Two activities sharing a room both schedule it, which must not collide on the unique + * conference id, and must leave a single pending record behind. + */ + public function test_scheduling_the_same_room_twice_leaves_one_record(): void { + global $DB; + + $owner = $this->getDataGenerator()->create_user(); + + clickmeeting_schedule_room_deletion(777008, $owner->id); + clickmeeting_schedule_room_deletion(777008, $owner->id); + + $this->assertEquals(1, $DB->count_records('clickmeeting_pending_deletions', ['conference_id' => 777008])); + } + + /** + * The pending deletions table stores who owned a room, which is personal data and has to + * be declared - Moodle's own privacy checks do not catch a "user_id" column on their own. + */ + public function test_pending_deletions_table_is_declared_to_the_privacy_api(): void { + $collection = \mod_clickmeeting\privacy\provider::get_metadata( + new \core_privacy\local\metadata\collection('mod_clickmeeting') + ); + + $tables = []; + foreach ($collection->get_collection() as $type) { + if ($type instanceof \core_privacy\local\metadata\types\database_table) { + $tables[] = $type->get_name(); + } + } + + $this->assertContains('clickmeeting_pending_deletions', $tables); + } +} diff --git a/version.php b/version.php index feb568e..857d6ab 100755 --- a/version.php +++ b/version.php @@ -27,7 +27,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2025021002; +$plugin->version = 2026100800; $plugin->requires = 2013111811.01; // Requires this Moodle 2.6 version $plugin->maturity = MATURITY_STABLE; $plugin->cron = 0; From fa25bc564d28e5b72c3acf87f95a56e1f376fea7 Mon Sep 17 00:00:00 2001 From: bmarcinkowski Date: Thu, 8 Oct 2026 17:05:56 +0200 Subject: [PATCH 02/10] chore: fix coding style violations reported by Moodle Code Checker The Moodle Plugin CI workflow has never run green: phpcs reported 154 errors that predate it. This applies phpcbf across the plugin so the checker passes and future failures mean something. Whitespace, argument wrapping, array syntax and interface ordering only - no behaviour is changed. Verified by PHP lint, the plugin test suite, Moodle's privacy checks, and a full v1.1.5 to v1.2.0 upgrade run, since db/upgrade.php was among the reformatted files. Co-Authored-By: Claude Opus 5 (1M context) --- ...ackup_clickmeeting_activity_task.class.php | 1 - .../moodle2/backup_clickmeeting_stepslib.php | 1 - ...store_clickmeeting_activity_task.class.php | 14 ++++--- .../moodle2/restore_clickmeeting_stepslib.php | 1 - classes/privacy/provider.php | 3 +- db/upgrade.php | 40 ++++++++++++++----- index.php | 7 ++-- lib.php | 28 ++++++------- mod_form.php | 5 +-- settings.php | 24 ++++++----- view.php | 16 ++++---- 11 files changed, 82 insertions(+), 58 deletions(-) diff --git a/backup/moodle2/backup_clickmeeting_activity_task.class.php b/backup/moodle2/backup_clickmeeting_activity_task.class.php index 34d1139..1225ca9 100755 --- a/backup/moodle2/backup_clickmeeting_activity_task.class.php +++ b/backup/moodle2/backup_clickmeeting_activity_task.class.php @@ -28,7 +28,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class backup_clickmeeting_activity_task extends backup_activity_task { - /** * Define (add) particular settings this activity can have */ diff --git a/backup/moodle2/backup_clickmeeting_stepslib.php b/backup/moodle2/backup_clickmeeting_stepslib.php index e3f2263..4849ae7 100755 --- a/backup/moodle2/backup_clickmeeting_stepslib.php +++ b/backup/moodle2/backup_clickmeeting_stepslib.php @@ -31,7 +31,6 @@ * Define the complete choice structure */ class backup_activity_structure_step extends \backup_activity_structure_step { - /** * Define the complete structure for backup */ diff --git a/backup/moodle2/restore_clickmeeting_activity_task.class.php b/backup/moodle2/restore_clickmeeting_activity_task.class.php index 5aeddbe..05f75c0 100755 --- a/backup/moodle2/restore_clickmeeting_activity_task.class.php +++ b/backup/moodle2/restore_clickmeeting_activity_task.class.php @@ -29,7 +29,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class restore_clickmeeting_activity_task extends restore_activity_task { - /** * Define (add) particular settings this activity can have */ @@ -68,7 +67,6 @@ public static function define_decode_rules() { $rules[] = new restore_decode_rule('CLICKMEETINGINDEX', '/mod/clickmeeting/index.php?id=$1', 'course'); return $rules; - } /** @@ -104,11 +102,17 @@ public static function define_restore_log_rules_for_course() { $rules = []; // Fix old wrong uses (missing extension) - $rules[] = new restore_log_rule('clickmeeting', 'view all', 'index?id={course}', null, - null, null, 'index.php?id={course}'); + $rules[] = new restore_log_rule( + 'clickmeeting', + 'view all', + 'index?id={course}', + null, + null, + null, + 'index.php?id={course}' + ); $rules[] = new restore_log_rule('clickmeeting', 'view all', 'index.php?id={course}', null); return $rules; } - } diff --git a/backup/moodle2/restore_clickmeeting_stepslib.php b/backup/moodle2/restore_clickmeeting_stepslib.php index ccbb50e..1a759a2 100755 --- a/backup/moodle2/restore_clickmeeting_stepslib.php +++ b/backup/moodle2/restore_clickmeeting_stepslib.php @@ -28,7 +28,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class restore_activity_structure_step extends \restore_activity_structure_step { - /** * Defines table structure */ diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index e05bdb8..6726869 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -39,8 +39,7 @@ /** * Ad hoc task that performs the actions for approved data privacy requests. */ -class provider implements metadata_provider, request_plugin_provider, core_userlist_provider { - +class provider implements core_userlist_provider, metadata_provider, request_plugin_provider { /** * Returns metadata about this system. * diff --git a/db/upgrade.php b/db/upgrade.php index 4eec213..c741886 100755 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -68,7 +68,6 @@ function xmldb_clickmeeting_upgrade($oldversion) { // First example, some fields were added to install.xml on 2007/04/01 if ($oldversion < 2007040100) { - // Define field course to be added to clickmeeting $table = new xmldb_table('clickmeeting'); $field = new xmldb_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id'); @@ -89,8 +88,16 @@ function xmldb_clickmeeting_upgrade($oldversion) { // Define field introformat to be added to clickmeeting $table = new xmldb_table('clickmeeting'); - $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', - 'intro'); + $field = new xmldb_field( + 'introformat', + XMLDB_TYPE_INTEGER, + '4', + XMLDB_UNSIGNED, + XMLDB_NOTNULL, + null, + '0', + 'intro' + ); // Add field introformat if (!$dbman->field_exists($table, $field)) { @@ -106,11 +113,18 @@ function xmldb_clickmeeting_upgrade($oldversion) { // two more fields and one index were added to install.xml (note the micro increment // "01" in the last two digits of the version if ($oldversion < 2007040101) { - // Define field timecreated to be added to clickmeeting $table = new xmldb_table('clickmeeting'); - $field = new xmldb_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', - 'introformat'); + $field = new xmldb_field( + 'timecreated', + XMLDB_TYPE_INTEGER, + '10', + XMLDB_UNSIGNED, + XMLDB_NOTNULL, + null, + '0', + 'introformat' + ); // Add field timecreated if (!$dbman->field_exists($table, $field)) { @@ -119,8 +133,16 @@ function xmldb_clickmeeting_upgrade($oldversion) { // Define field timemodified to be added to clickmeeting $table = new xmldb_table('clickmeeting'); - $field = new xmldb_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', - 'timecreated'); + $field = new xmldb_field( + 'timemodified', + XMLDB_TYPE_INTEGER, + '10', + XMLDB_UNSIGNED, + XMLDB_NOTNULL, + null, + '0', + 'timecreated' + ); // Add field timemodified if (!$dbman->field_exists($table, $field)) { @@ -143,14 +165,12 @@ function xmldb_clickmeeting_upgrade($oldversion) { // Third example, the next day, 2007/04/02 (with the trailing 00), some actions were performed to install.php, // related with the module if ($oldversion < 2007040200) { - // insert here code to perform some actions (same as in install.php) upgrade_mod_savepoint(true, 2007040200, 'clickmeeting'); } if ($oldversion < 2018101000) { - $table = new xmldb_table('clickmeeting'); $field = new xmldb_field('user_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'description'); diff --git a/index.php b/index.php index 7a8a006..18d21ac 100755 --- a/index.php +++ b/index.php @@ -27,8 +27,8 @@ // Replace clickmeeting with the name of your module and remove this line -require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); -require_once(dirname(__FILE__).'/lib.php'); +require_once(dirname(dirname(dirname(__FILE__))) . '/config.php'); +require_once(dirname(__FILE__) . '/lib.php'); $id = required_param('id', PARAM_INT); // course @@ -76,7 +76,8 @@ } else { $link = html_writer::link( new moodle_url('/mod/clickmeeting/view.php', ['id' => $clickmeeting->coursemodule]), - format_string($clickmeeting->name, true)); + format_string($clickmeeting->name, true) + ); } if ($course->format == 'weeks' || $course->format == 'topics') { diff --git a/lib.php b/lib.php index 6d98c06..4143766 100755 --- a/lib.php +++ b/lib.php @@ -96,7 +96,7 @@ function clickmeeting_check_conference_availability($starttime, $duration, $id = ]; $curl = clickmeeting_init_curl(); - $curl->post($apiurl.'conference/availability', $params); + $curl->post($apiurl . 'conference/availability', $params); return 200 === $curl->get_info()['http_code']; } @@ -138,7 +138,7 @@ function clickmeeting_add_conference($params) { $apiurl = get_config('clickmeeting', 'apiurl'); $curlhandle = clickmeeting_init_curl(); - $result = $curlhandle->post($apiurl.'conferences', $params); + $result = $curlhandle->post($apiurl . 'conferences', $params); return $result; } @@ -154,7 +154,7 @@ function clickmeeting_edit_conference($conferenceid, $params) { $apiurl = get_config('clickmeeting', 'apiurl'); $curlhandle = clickmeeting_init_curl(); - $result = $curlhandle->put($apiurl.'conferences/'.$conferenceid, [], ['CURLOPT_POSTFIELDS' => http_build_query($params, '', '&')]); + $result = $curlhandle->put($apiurl . 'conferences/' . $conferenceid, [], ['CURLOPT_POSTFIELDS' => http_build_query($params, '', '&')]); return $result; } @@ -174,7 +174,7 @@ function clickmeeting_edit_conference_title($conferenceid, $title) { ]; $curlhandle = clickmeeting_init_curl(); - $result = $curlhandle->put($apiurl.'conferences/'.$conferenceid, [], ['CURLOPT_POSTFIELDS' => http_build_query($params, '', '&')]); + $result = $curlhandle->put($apiurl . 'conferences/' . $conferenceid, [], ['CURLOPT_POSTFIELDS' => http_build_query($params, '', '&')]); return $result; } @@ -189,7 +189,7 @@ function clickmeeting_delete_conference($conferenceid) { $apiurl = get_config('clickmeeting', 'apiurl'); $curlhandle = clickmeeting_init_curl(); - $result = $curlhandle->delete($apiurl.'conferences/'.$conferenceid); + $result = $curlhandle->delete($apiurl . 'conferences/' . $conferenceid); return $result; } @@ -208,7 +208,7 @@ function clickmeeting_generate_token($roomid) { $params['how_many'] = 1; $curlhandle = clickmeeting_init_curl(); - $result = $curlhandle->post($apiurl.'conferences/'.$roomid.'/tokens', $params); + $result = $curlhandle->post($apiurl . 'conferences/' . $roomid . '/tokens', $params); $decoder = json_decode($result, true); return $decoder['access_tokens'][0]['token']; @@ -259,7 +259,7 @@ function clickmeeting_get_login_url($roomid, $email, $nickname, $role, $auth, $a } $curlhandle = clickmeeting_init_curl(); - $result = $curlhandle->post($apiurl.'conferences/'.$roomid.'/room/autologin_hash', $params); + $result = $curlhandle->post($apiurl . 'conferences/' . $roomid . '/room/autologin_hash', $params); $decoded = json_decode($result, true); return !empty($decoded['autologin_hash']) @@ -343,7 +343,7 @@ function clickmeeting_add_instance(stdClass $clickmeeting, mod_clickmeeting_mod_ $error = ''; if (!empty($r['code'])) { foreach ($r['errors'] as $err) { - $error .= $err['message'].'
'; + $error .= $err['message'] . '
'; } throw new \moodle_exception($error, 'error'); } @@ -425,7 +425,7 @@ function clickmeeting_update_instance(stdClass $clickmeeting, mod_clickmeeting_m if (!empty($r['code'])) { $error = ''; foreach ($r['errors'] as $err) { - $error .= $err['message'].'
'; + $error .= $err['message'] . '
'; } throw new \moodle_exception($error, 'error'); } @@ -640,7 +640,7 @@ function clickmeeting_scale_used_anywhere($scaleid) { */ function clickmeeting_grade_item_update(stdClass $clickmeeting) { global $CFG, $DB; - require_once($CFG->libdir.'/gradelib.php'); + require_once($CFG->libdir . '/gradelib.php'); $item = []; $item['itemname'] = clean_param($clickmeeting->name, PARAM_NOTAGS); @@ -683,7 +683,7 @@ function clickmeeting_generate_password($length) { */ function clickmeeting_update_grades(stdClass $clickmeeting, $userid = 0) { global $CFG, $DB; - require_once($CFG->libdir.'/gradelib.php'); + require_once($CFG->libdir . '/gradelib.php'); $grades = []; // populate array of grade objects indexed by userid @@ -771,7 +771,7 @@ function clickmeeting_extend_navigation(navigation_node $navref, stdClass $cours * @param settings_navigation $settingsnav * @param navigation_node $clickmeetingnode */ -function clickmeeting_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $clickmeetingnode=null) { +function clickmeeting_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $clickmeetingnode = null) { } /** @@ -808,10 +808,10 @@ function clickmeeting_init_curl() { */ function clickmeeting_page_view($clickmeeting, $course, $cm, $context) { - $params = array( + $params = [ 'context' => $context, 'objectid' => $clickmeeting->id, - ); + ]; $event = mod_clickmeeting\event\course_module_viewed::create($params); $event->add_record_snapshot('course_modules', $cm); diff --git a/mod_form.php b/mod_form.php index 3cebbf4..d470404 100755 --- a/mod_form.php +++ b/mod_form.php @@ -27,13 +27,12 @@ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->dirroot.'/course/moodleform_mod.php'); +require_once($CFG->dirroot . '/course/moodleform_mod.php'); /** * Module instance settings form */ class mod_clickmeeting_mod_form extends moodleform_mod { - /** * Defines webinar open to all */ @@ -71,7 +70,7 @@ public function definition() { $conferencestarttime = required_param('start_time', PARAM_TEXT); $conferenceduration = required_param('duration', PARAM_INT); - if (clickmeeting_check_conference_availability($conferencestarttime, $conferenceduration, $conferenceid)) { + if (clickmeeting_check_conference_availability($conferencestarttime, $conferenceduration, $conferenceid)) { http_response_code(200); echo 'SUCCESS'; } else { diff --git a/settings.php b/settings.php index d27190d..0404612 100755 --- a/settings.php +++ b/settings.php @@ -25,18 +25,22 @@ defined('MOODLE_INTERNAL') || die; if ($ADMIN->fulltree) { - require_once(dirname(__FILE__).'/lib.php'); + require_once(dirname(__FILE__) . '/lib.php'); - $settings->add(new admin_setting_configtext('clickmeeting/apiurl', - get_string('settings:apiurl', 'clickmeeting'), - get_string('settings:apiurldesc', 'clickmeeting'), - 'https://api.clickmeeting.com/v1/', - PARAM_URL)); + $settings->add(new admin_setting_configtext( + 'clickmeeting/apiurl', + get_string('settings:apiurl', 'clickmeeting'), + get_string('settings:apiurldesc', 'clickmeeting'), + 'https://api.clickmeeting.com/v1/', + PARAM_URL + )); - $settings->add(new admin_setting_configtext('clickmeeting/apikey', - get_string('settings:apikey', 'clickmeeting'), - get_string('settings:apikeydesc', 'clickmeeting'), - '')); + $settings->add(new admin_setting_configtext( + 'clickmeeting/apikey', + get_string('settings:apikey', 'clickmeeting'), + get_string('settings:apikeydesc', 'clickmeeting'), + '' + )); $settings->add(new admin_setting_configduration( 'clickmeeting/graceperiod', diff --git a/view.php b/view.php index 8729561..472d98c 100755 --- a/view.php +++ b/view.php @@ -25,8 +25,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); -require_once(dirname(__FILE__).'/lib.php'); +require_once(dirname(dirname(dirname(__FILE__))) . '/config.php'); +require_once(dirname(__FILE__) . '/lib.php'); $id = optional_param('id', 0, PARAM_INT); // course_module ID, or $n = optional_param('n', 0, PARAM_INT); // clickmeeting instance ID - it should be named as the first character of the module @@ -100,22 +100,22 @@ // Output starts here echo $OUTPUT->header(); -echo ''.get_string('view:room_name', 'clickmeeting').': '.$clickmeeting->name; +echo '' . get_string('view:room_name', 'clickmeeting') . ': ' . $clickmeeting->name; echo '

'; if (!clickmeeting_is_room_historical($conference->conference_id)) { - $timestamp = strtotime('+'.$clickmeeting->duration.' hours', $clickmeeting->timestart); - echo ''.get_string('view:room_date', 'clickmeeting').': '.$clickmeeting->start_time.' - '.date('Y-m-d H:i:s', $timestamp); + $timestamp = strtotime('+' . $clickmeeting->duration . ' hours', $clickmeeting->timestart); + echo '' . get_string('view:room_date', 'clickmeeting') . ': ' . $clickmeeting->start_time . ' - ' . date('Y-m-d H:i:s', $timestamp); echo '

'; - echo ''.get_string('view:room_description', 'clickmeeting').': '.$clickmeeting->description; + echo '' . get_string('view:room_description', 'clickmeeting') . ': ' . $clickmeeting->description; echo '

'; if (clickmeeting_is_password_protected($clickmeeting)) { - echo ''.get_string('view:password', 'clickmeeting').': '.$conference->password; + echo '' . get_string('view:password', 'clickmeeting') . ': ' . $conference->password; echo '

'; } $loginurl = sprintf('%s?l=%s', $conference->room_url, $loginhash); echo ''; } else { echo '' . get_string('view:oldmeeting', 'clickmeeting') . ''; From f87c89967ca82f9f3fe51189e8c91a86e0bcfdc9 Mon Sep 17 00:00:00 2001 From: bmarcinkowski Date: Fri, 9 Oct 2026 10:41:49 +0200 Subject: [PATCH 03/10] fix: shorten new table name to install on Moodle 4.1 and earlier CI caught this on the MOODLE_401_STABLE jobs: clickmeeting_room_deletions was named clickmeeting_pending_deletions, 30 characters, and Moodle rejects table names over 28 characters until 4.2: Invalid table name {clickmeeting_pending_deletions}: name is too long. The limit was raised later, so the table installed fine on 4.5 while breaking every older site. The plugin declares support from Moodle 2.6 and the plugins directory advertises 2.6 to 4.5, so releasing this would have broken installs and upgrades for a large share of them. Adds a test asserting every table in install.xml fits the 28 character limit, so the next table cannot reintroduce this. Verified on Moodle 4.1.22 (PHP 8.1) and 4.5.15 (PHP 8.2): clean install and v1.1.5 to v1.2.0 upgrade both succeed, table and scheduled task created, existing rows untouched. Co-Authored-By: Claude Opus 5 (1M context) --- CHANGELOG.md | 2 +- classes/privacy/provider.php | 6 ++-- classes/task/purge_deleted_rooms.php | 6 ++-- db/install.xml | 2 +- db/upgrade.php | 2 +- lang/en/clickmeeting.php | 4 +-- lang/pl/clickmeeting.php | 4 +-- lib.php | 4 +-- tests/lib_test.php | 47 +++++++++++++++++++--------- 9 files changed, 47 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cabbe17..a918c26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,5 +35,5 @@ on purpose. ### Upgrade notes -Adds the table `clickmeeting_pending_deletions`. Existing data is untouched. Rooms already +Adds the table `clickmeeting_room_deletions`. Existing data is untouched. Rooms already deleted before this release cannot be recovered. diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index e05bdb8..2b4b74c 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -52,9 +52,9 @@ public static function get_metadata(collection $collection): collection { 'user_id' => 'privacy:metadata:clickmeetingtokens:userid', ], 'privacy:metadata:clickmeetingtokens'); - $collection->add_database_table('clickmeeting_pending_deletions', [ - 'user_id' => 'privacy:metadata:clickmeetingpendingdeletions:userid', - ], 'privacy:metadata:clickmeetingpendingdeletions'); + $collection->add_database_table('clickmeeting_room_deletions', [ + 'user_id' => 'privacy:metadata:clickmeetingroomdeletions:userid', + ], 'privacy:metadata:clickmeetingroomdeletions'); $collection->add_external_location_link('clickmeeting.com', [ 'email' => 'privacy:metadata:clickmeeting_api:email', diff --git a/classes/task/purge_deleted_rooms.php b/classes/task/purge_deleted_rooms.php index db5aa8f..0040a11 100644 --- a/classes/task/purge_deleted_rooms.php +++ b/classes/task/purge_deleted_rooms.php @@ -45,7 +45,7 @@ public function execute() { $cutoff = time() - clickmeeting_get_grace_period(); $pending = $DB->get_records_select( - 'clickmeeting_pending_deletions', + 'clickmeeting_room_deletions', 'timescheduled <= :cutoff', ['cutoff' => $cutoff] ); @@ -55,7 +55,7 @@ public function execute() { // bin - points at this room again, so deleting it would take the meeting away from them. if ($DB->record_exists('clickmeeting_conferences', ['conference_id' => $record->conference_id])) { mtrace("Room {$record->conference_id} is in use again, cancelling its deletion."); - $DB->delete_records('clickmeeting_pending_deletions', ['id' => $record->id]); + $DB->delete_records('clickmeeting_room_deletions', ['id' => $record->id]); continue; } @@ -69,7 +69,7 @@ public function execute() { continue; } - $DB->delete_records('clickmeeting_pending_deletions', ['id' => $record->id]); + $DB->delete_records('clickmeeting_room_deletions', ['id' => $record->id]); if ('"200 OK"' === $apiresult) { room_deleted::create([ diff --git a/db/install.xml b/db/install.xml index 58ea2c7..34ff9f2 100755 --- a/db/install.xml +++ b/db/install.xml @@ -56,7 +56,7 @@ - +
diff --git a/db/upgrade.php b/db/upgrade.php index 4eec213..65b0f81 100755 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -222,7 +222,7 @@ function xmldb_clickmeeting_upgrade($oldversion) { } if ($oldversion < 2026100800) { - $table = new xmldb_table('clickmeeting_pending_deletions'); + $table = new xmldb_table('clickmeeting_room_deletions'); $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, true, null); $table->add_field('conference_id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); $table->add_field('user_id', XMLDB_TYPE_INTEGER, '10', null, null, null, null); diff --git a/lang/en/clickmeeting.php b/lang/en/clickmeeting.php index 36d6155..ef3a181 100755 --- a/lang/en/clickmeeting.php +++ b/lang/en/clickmeeting.php @@ -89,5 +89,5 @@ $string['settings:graceperioddesc'] = 'How long a ClickMeeting room survives after its Moodle activity was deleted. During this time the meeting and its recordings stay reachable in ClickMeeting, and restoring the activity from the recycle bin reconnects it to the same room. Set to zero to use the default of five months.'; $string['task:purgedeletedrooms'] = 'Delete ClickMeeting rooms past their grace period'; $string['event:roomdeleted'] = 'ClickMeeting room deleted'; -$string['privacy:metadata:clickmeetingpendingdeletions'] = 'Plugin remembers which rooms are awaiting deletion in ClickMeeting.'; -$string['privacy:metadata:clickmeetingpendingdeletions:userid'] = 'The owner of the room is kept so that the deletion uses their API key.'; +$string['privacy:metadata:clickmeetingroomdeletions'] = 'Plugin remembers which rooms are awaiting deletion in ClickMeeting.'; +$string['privacy:metadata:clickmeetingroomdeletions:userid'] = 'The owner of the room is kept so that the deletion uses their API key.'; diff --git a/lang/pl/clickmeeting.php b/lang/pl/clickmeeting.php index 09048c3..68b9d43 100755 --- a/lang/pl/clickmeeting.php +++ b/lang/pl/clickmeeting.php @@ -88,5 +88,5 @@ $string['settings:graceperioddesc'] = 'Jak długo pokój ClickMeeting istnieje po usunięciu powiązanej aktywności w Moodle. Przez ten czas wydarzenie i jego nagrania pozostają dostępne w ClickMeeting, a przywrócenie aktywności z kosza podłącza ją z powrotem do tego samego pokoju. Wartość zero oznacza domyślne pięć miesięcy.'; $string['task:purgedeletedrooms'] = 'Usuwanie pokoi ClickMeeting po okresie karencji'; $string['event:roomdeleted'] = 'Usunięto pokój ClickMeeting'; -$string['privacy:metadata:clickmeetingpendingdeletions'] = 'Moduł przechowuje informację o pokojach oczekujących na usunięcie w ClickMeeting.'; -$string['privacy:metadata:clickmeetingpendingdeletions:userid'] = 'Właściciel pokoju jest zapamiętywany, aby usunięcie wykonać jego kluczem API.'; +$string['privacy:metadata:clickmeetingroomdeletions'] = 'Moduł przechowuje informację o pokojach oczekujących na usunięcie w ClickMeeting.'; +$string['privacy:metadata:clickmeetingroomdeletions:userid'] = 'Właściciel pokoju jest zapamiętywany, aby usunięcie wykonać jego kluczem API.'; diff --git a/lib.php b/lib.php index 6d98c06..ef62030 100755 --- a/lib.php +++ b/lib.php @@ -483,8 +483,8 @@ function clickmeeting_delete_instance($id) { function clickmeeting_schedule_room_deletion($conferenceid, $ownerid) { global $DB; - $DB->delete_records('clickmeeting_pending_deletions', ['conference_id' => $conferenceid]); - $DB->insert_record('clickmeeting_pending_deletions', (object) [ + $DB->delete_records('clickmeeting_room_deletions', ['conference_id' => $conferenceid]); + $DB->insert_record('clickmeeting_room_deletions', (object) [ 'conference_id' => $conferenceid, 'user_id' => $ownerid, 'timescheduled' => time(), diff --git a/tests/lib_test.php b/tests/lib_test.php index 1bf66c3..00e1668 100644 --- a/tests/lib_test.php +++ b/tests/lib_test.php @@ -114,7 +114,7 @@ public function test_delete_instance_schedules_room_deletion_instead_of_calling_ $this->assertTrue(clickmeeting_delete_instance($instanceid)); $this->assertFalse($DB->record_exists('clickmeeting', ['id' => $instanceid])); - $pending = $DB->get_record('clickmeeting_pending_deletions', ['conference_id' => 777001]); + $pending = $DB->get_record('clickmeeting_room_deletions', ['conference_id' => 777001]); $this->assertNotFalse($pending, 'Room deletion should have been scheduled.'); $this->assertEquals($owner->id, $pending->user_id); } @@ -128,7 +128,7 @@ public function test_purge_task_deletes_room_once_grace_period_expired(): void { $this->resetAfterTest(); set_config('graceperiod', WEEKSECS, 'clickmeeting'); $owner = $this->getDataGenerator()->create_user(); - $DB->insert_record('clickmeeting_pending_deletions', (object) [ + $DB->insert_record('clickmeeting_room_deletions', (object) [ 'conference_id' => 777002, 'user_id' => $owner->id, 'timescheduled' => time() - WEEKSECS - 1, @@ -140,7 +140,7 @@ public function test_purge_task_deletes_room_once_grace_period_expired(): void { $events = $sink->get_events(); $sink->close(); - $this->assertFalse($DB->record_exists('clickmeeting_pending_deletions', ['conference_id' => 777002])); + $this->assertFalse($DB->record_exists('clickmeeting_room_deletions', ['conference_id' => 777002])); $this->assertCount(1, $events); $this->assertInstanceOf(\mod_clickmeeting\event\room_deleted::class, $events[0]); $this->assertEquals(777002, $events[0]->other['conferenceid']); @@ -156,7 +156,7 @@ public function test_purge_task_keeps_room_within_grace_period(): void { $this->resetAfterTest(); set_config('graceperiod', WEEKSECS, 'clickmeeting'); $owner = $this->getDataGenerator()->create_user(); - $DB->insert_record('clickmeeting_pending_deletions', (object) [ + $DB->insert_record('clickmeeting_room_deletions', (object) [ 'conference_id' => 777003, 'user_id' => $owner->id, 'timescheduled' => time() - DAYSECS, @@ -168,7 +168,7 @@ public function test_purge_task_keeps_room_within_grace_period(): void { $events = $sink->get_events(); $sink->close(); - $this->assertTrue($DB->record_exists('clickmeeting_pending_deletions', ['conference_id' => 777003])); + $this->assertTrue($DB->record_exists('clickmeeting_room_deletions', ['conference_id' => 777003])); $this->assertCount(0, $events); $this->assert_api_was_not_called(); } @@ -185,7 +185,7 @@ public function test_purge_task_spares_room_still_used_by_another_activity(): vo $course = $this->getDataGenerator()->create_course(); $owner = $this->getDataGenerator()->create_user(); $this->create_activity($course->id, 777004, $owner->id); - $DB->insert_record('clickmeeting_pending_deletions', (object) [ + $DB->insert_record('clickmeeting_room_deletions', (object) [ 'conference_id' => 777004, 'user_id' => $owner->id, 'timescheduled' => time() - WEEKSECS - 1, @@ -199,7 +199,7 @@ public function test_purge_task_spares_room_still_used_by_another_activity(): vo $this->assertCount(0, $events, 'A room another activity still points at must not be deleted.'); $this->assert_api_was_not_called(); - $this->assertFalse($DB->record_exists('clickmeeting_pending_deletions', ['conference_id' => 777004])); + $this->assertFalse($DB->record_exists('clickmeeting_room_deletions', ['conference_id' => 777004])); } /** @@ -223,7 +223,7 @@ public function test_delete_instance_removes_activity_that_has_no_room(): void { $this->assertTrue(clickmeeting_delete_instance($instanceid)); $this->assertFalse($DB->record_exists('clickmeeting', ['id' => $instanceid])); - $this->assertEquals(0, $DB->count_records('clickmeeting_pending_deletions')); + $this->assertEquals(0, $DB->count_records('clickmeeting_room_deletions')); } /** @@ -234,7 +234,7 @@ public function test_purge_task_forgets_room_that_no_longer_exists(): void { set_config('graceperiod', WEEKSECS, 'clickmeeting'); $owner = $this->getDataGenerator()->create_user(); - $DB->insert_record('clickmeeting_pending_deletions', (object) [ + $DB->insert_record('clickmeeting_room_deletions', (object) [ 'conference_id' => 777005, 'user_id' => $owner->id, 'timescheduled' => time() - WEEKSECS - 1, @@ -246,7 +246,7 @@ public function test_purge_task_forgets_room_that_no_longer_exists(): void { $events = $sink->get_events(); $sink->close(); - $this->assertFalse($DB->record_exists('clickmeeting_pending_deletions', ['conference_id' => 777005])); + $this->assertFalse($DB->record_exists('clickmeeting_room_deletions', ['conference_id' => 777005])); $this->assertCount(0, $events, 'Nothing was deleted, so no deletion should be reported.'); } @@ -258,7 +258,7 @@ public function test_purge_task_retries_room_after_a_failed_api_call(): void { set_config('graceperiod', WEEKSECS, 'clickmeeting'); $owner = $this->getDataGenerator()->create_user(); - $DB->insert_record('clickmeeting_pending_deletions', (object) [ + $DB->insert_record('clickmeeting_room_deletions', (object) [ 'conference_id' => 777006, 'user_id' => $owner->id, 'timescheduled' => time() - WEEKSECS - 1, @@ -267,7 +267,7 @@ public function test_purge_task_retries_room_after_a_failed_api_call(): void { $output = $this->run_purge_task(); - $this->assertTrue($DB->record_exists('clickmeeting_pending_deletions', ['conference_id' => 777006])); + $this->assertTrue($DB->record_exists('clickmeeting_room_deletions', ['conference_id' => 777006])); $this->assertStringContainsString('will retry', $output); } @@ -341,14 +341,14 @@ public function test_scheduling_the_same_room_twice_leaves_one_record(): void { clickmeeting_schedule_room_deletion(777008, $owner->id); clickmeeting_schedule_room_deletion(777008, $owner->id); - $this->assertEquals(1, $DB->count_records('clickmeeting_pending_deletions', ['conference_id' => 777008])); + $this->assertEquals(1, $DB->count_records('clickmeeting_room_deletions', ['conference_id' => 777008])); } /** * The pending deletions table stores who owned a room, which is personal data and has to * be declared - Moodle's own privacy checks do not catch a "user_id" column on their own. */ - public function test_pending_deletions_table_is_declared_to_the_privacy_api(): void { + public function test_room_deletions_table_is_declared_to_the_privacy_api(): void { $collection = \mod_clickmeeting\privacy\provider::get_metadata( new \core_privacy\local\metadata\collection('mod_clickmeeting') ); @@ -360,6 +360,23 @@ public function test_pending_deletions_table_is_declared_to_the_privacy_api(): v } } - $this->assertContains('clickmeeting_pending_deletions', $tables); + $this->assertContains('clickmeeting_room_deletions', $tables); + } + + /** + * Moodle rejects table names longer than 28 characters on 4.1 and earlier, which this + * plugin still supports. The limit was raised later, so a name that installs fine on 4.5 + * can still break every older site. + */ + public function test_table_names_fit_the_moodle_name_limit(): void { + global $CFG; + + $xml = simplexml_load_file($CFG->dirroot . '/mod/clickmeeting/db/install.xml'); + + $this->assertNotFalse($xml, 'install.xml should be readable.'); + foreach ($xml->TABLES->TABLE as $table) { + $name = (string) $table['NAME']; + $this->assertLessThanOrEqual(28, strlen($name), "Table name {$name} is too long for Moodle 4.1."); + } } } From e2ac072730e9cfada7ee0d7db570e4c4ca80b364 Mon Sep 17 00:00:00 2001 From: bmarcinkowski Date: Fri, 9 Oct 2026 10:50:03 +0200 Subject: [PATCH 04/10] fix: honour erasure requests for the room owner The new clickmeeting_room_deletions table records who owned a room so the deletion can run with their API key. That column was declared to the privacy API but nothing acted on it, so an erasure request left the user id behind for the whole grace period - up to five months. The row lives on after its activity, so it belongs to no module context. The provider now reports the system context for anyone named in the table, and clears the owner on erasure. The row itself stays: the room still has to be deleted, and it falls back to the global API key, which is already the behaviour when the owner no longer exists. Covers get_contexts_for_userid, get_users_in_context, delete_data_for_user, delete_data_for_users and delete_data_for_all_users_in_context. Co-Authored-By: Claude Opus 5 (1M context) --- CHANGELOG.md | 2 ++ classes/privacy/provider.php | 36 +++++++++++++++++++++++++++ tests/lib_test.php | 47 ++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a918c26..ed57382 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,8 @@ on purpose. - Event `mod_clickmeeting\event\room_deleted`, logged whenever a room is really deleted, so a missing meeting can be traced back to when and why it went away. - PHPUnit coverage for the deletion lifecycle. +- Privacy API support for the new table: the room owner is discoverable and is cleared on an + erasure request, while the room itself stays scheduled for deletion. ### Upgrade notes diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 2b4b74c..235afdc 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -71,6 +71,8 @@ public static function get_metadata(collection $collection): collection { * @return contextlist $contextlist The list of contexts used in this plugin. */ public static function get_contexts_for_userid(int $userid): contextlist { + global $DB; + $contextlist = new contextlist(); $sql = 'SELECT c.id @@ -90,6 +92,11 @@ public static function get_contexts_for_userid(int $userid): contextlist { $contextlist->add_from_sql($sql, $params); + // A pending room deletion outlives its activity, so it belongs to no module context. + if ($DB->record_exists('clickmeeting_room_deletions', ['user_id' => $userid])) { + $contextlist->add_system_context(); + } + return $contextlist; } @@ -159,6 +166,12 @@ public static function export_user_data(approved_contextlist $contextlist): void public static function delete_data_for_all_users_in_context(\context $context): void { global $DB; + if ($context instanceof \context_system) { + $DB->set_field_select('clickmeeting_room_deletions', 'user_id', null, 'user_id IS NOT NULL', []); + + return; + } + if (!($context instanceof context_module)) { return; } @@ -183,6 +196,12 @@ public static function delete_data_for_user(approved_contextlist $contextlist): $user = $contextlist->get_user(); foreach ($contextlist->get_contexts() as $context) { + if ($context instanceof \context_system) { + // Keep the row - the room still has to go - but forget whose it was. + $DB->set_field('clickmeeting_room_deletions', 'user_id', null, ['user_id' => $user->id]); + continue; + } + if (!($context instanceof context_module)) { continue; } @@ -204,6 +223,16 @@ public static function delete_data_for_user(approved_contextlist $contextlist): public static function get_users_in_context(userlist $userlist): void { $context = $userlist->get_context(); + if ($context instanceof \context_system) { + $userlist->add_from_sql( + 'user_id', + 'SELECT user_id FROM {clickmeeting_room_deletions} WHERE user_id IS NOT NULL', + [] + ); + + return; + } + if (!($context instanceof context_module)) { return; } @@ -232,6 +261,13 @@ public static function delete_data_for_users(approved_userlist $userlist): void global $DB; $context = $userlist->get_context(); + if ($context instanceof \context_system) { + [$insql, $inparams] = $DB->get_in_or_equal($userlist->get_userids(), SQL_PARAMS_NAMED); + $DB->set_field_select('clickmeeting_room_deletions', 'user_id', null, "user_id $insql", $inparams); + + return; + } + if (!($context instanceof context_module)) { return; } diff --git a/tests/lib_test.php b/tests/lib_test.php index 00e1668..8c1a60a 100644 --- a/tests/lib_test.php +++ b/tests/lib_test.php @@ -379,4 +379,51 @@ public function test_table_names_fit_the_moodle_name_limit(): void { $this->assertLessThanOrEqual(28, strlen($name), "Table name {$name} is too long for Moodle 4.1."); } } + + /** + * An erasure request must not leave the owner's id behind. The row itself has to stay, or + * the room would never be deleted from ClickMeeting - it falls back to the global API key. + */ + public function test_erasure_request_clears_the_room_owner(): void { + global $DB; + + $owner = $this->getDataGenerator()->create_user(); + $DB->insert_record('clickmeeting_room_deletions', (object) [ + 'conference_id' => 777009, + 'user_id' => $owner->id, + 'timescheduled' => time(), + ]); + + \mod_clickmeeting\privacy\provider::delete_data_for_user( + new \core_privacy\local\request\approved_contextlist( + $owner, + 'mod_clickmeeting', + [\context_system::instance()->id] + ) + ); + + $record = $DB->get_record('clickmeeting_room_deletions', ['conference_id' => 777009]); + $this->assertNotFalse($record, 'The room must still be scheduled for deletion.'); + $this->assertNull($record->user_id); + } + + /** + * A user known only through a pending room deletion still has to be discoverable, otherwise + * their erasure request never reaches that row. + */ + public function test_room_owner_is_found_by_the_privacy_api(): void { + global $DB; + + $owner = $this->getDataGenerator()->create_user(); + $DB->insert_record('clickmeeting_room_deletions', (object) [ + 'conference_id' => 777010, + 'user_id' => $owner->id, + 'timescheduled' => time(), + ]); + + $contextlist = \mod_clickmeeting\privacy\provider::get_contexts_for_userid($owner->id); + + // Context ids come back from the database as strings, so compare loosely. + $this->assertContainsEquals(\context_system::instance()->id, $contextlist->get_contextids()); + } } From 39ad80da7175d1a9964b3e37aef105e5e2846806 Mon Sep 17 00:00:00 2001 From: bmarcinkowski Date: Fri, 9 Oct 2026 11:20:42 +0200 Subject: [PATCH 05/10] ci: test against currently supported Moodle releases The matrix dated from when Moodle 4.1 was current. Moodle is now on 5.3, and nothing in CI touched 5.x at all - including the public/ directory layout that 5.1 introduced, which changes where plugins are installed. Matrix now runs Moodle 4.1 LTS through 5.3, each branch paired only with PHP versions that branch actually supports, so a red job means the plugin is broken rather than the combination being impossible. PHP 7.4 and 8.0 are gone: both are past end of life and no tested branch accepts them. Services move to postgres 17 and mariadb 11.4, which Moodle 5.3 requires; verified locally that Moodle 4.1 still installs against mariadb 11.4, so the older end of the matrix keeps working. Runner moves to ubuntu-24.04 and the mariadb health check to healthcheck.sh, which the 11.x images ship. release.yml was still on actions/checkout@v2 and action-gh-release@v1; both are bumped. Verified locally before changing anything: clean install and a v1.1.5 to v1.2.0 upgrade both succeed on Moodle 5.3 (PHP 8.3, mariadb 11.4) with no plugin changes needed. Co-Authored-By: Claude Opus 5 (1M context) --- .github/workflows/moodle-ci.yml | 52 ++++++++++++++++++--------------- .github/workflows/release.yml | 4 +-- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/.github/workflows/moodle-ci.yml b/.github/workflows/moodle-ci.yml index b0b208b..c0cc7ca 100644 --- a/.github/workflows/moodle-ci.yml +++ b/.github/workflows/moodle-ci.yml @@ -4,11 +4,11 @@ on: [push, pull_request] jobs: test: - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 services: postgres: - image: postgres:15 + image: postgres:17 env: POSTGRES_USER: 'postgres' POSTGRES_HOST_AUTH_METHOD: 'trust' @@ -17,7 +17,7 @@ jobs: options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3 mariadb: - image: mariadb:10.11 + image: mariadb:11.4 env: MYSQL_USER: 'root' MYSQL_ALLOW_EMPTY_PASSWORD: "true" @@ -25,43 +25,49 @@ jobs: MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci" ports: - 3306:3306 - options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3 + options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval 10s --health-timeout 5s --health-retries 5 strategy: fail-fast: false matrix: + # Each Moodle branch is paired only with PHP versions it actually supports, so a red + # job means the plugin is broken rather than the combination being impossible. include: - # Moodle 4.0.1 - PHP 7.4, 8.0, 8.1 - - php: '7.4' - moodle-branch: 'MOODLE_401_STABLE' - database: pgsql - - php: '8.0' - moodle-branch: 'MOODLE_401_STABLE' - database: pgsql + # Moodle 4.1 LTS - oldest release this plugin is tested against. - php: '8.1' moodle-branch: 'MOODLE_401_STABLE' database: pgsql - - php: '7.4' - moodle-branch: 'MOODLE_401_STABLE' - database: mariadb - - php: '8.0' - moodle-branch: 'MOODLE_401_STABLE' - database: mariadb - php: '8.1' moodle-branch: 'MOODLE_401_STABLE' database: mariadb - # Moodle 4.0.5 - 8.1, 8.2 + # Moodle 4.5 LTS - what the plugins directory currently advertises. - php: '8.1' moodle-branch: 'MOODLE_405_STABLE' database: pgsql - - php: '8.2' - moodle-branch: 'MOODLE_405_STABLE' - database: pgsql - - php: '8.1' + - php: '8.3' moodle-branch: 'MOODLE_405_STABLE' database: mariadb + # Moodle 5.0 - php: '8.2' - moodle-branch: 'MOODLE_405_STABLE' + moodle-branch: 'MOODLE_500_STABLE' + database: pgsql + - php: '8.3' + moodle-branch: 'MOODLE_500_STABLE' + database: mariadb + # Moodle 5.1 - first release with the public/ directory layout. + - php: '8.3' + moodle-branch: 'MOODLE_501_STABLE' + database: pgsql + # Moodle 5.2 + - php: '8.3' + moodle-branch: 'MOODLE_502_STABLE' + database: mariadb + # Moodle 5.3 - latest release. + - php: '8.3' + moodle-branch: 'MOODLE_503_STABLE' + database: pgsql + - php: '8.3' + moodle-branch: 'MOODLE_503_STABLE' database: mariadb steps: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c5e9e3d..51f2f97 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Create ZIP file run: | @@ -19,7 +19,7 @@ jobs: zip -r mod_clickmeeting.zip mod_clickmeeting -x "*.git*" - name: Upload Release Asset - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: files: mod_clickmeeting.zip env: From 9b51f394174b2d948317518caf7fc7ec92825841 Mon Sep 17 00:00:00 2001 From: bmarcinkowski Date: Fri, 9 Oct 2026 11:24:49 +0200 Subject: [PATCH 06/10] ci: pin release actions to commit SHAs and drop unneeded token scope release.yml runs with a write-scoped GITHUB_TOKEN and publishes the ZIP that users install, while referencing third-party actions by moving tag. Whoever controls those tags can repoint them at any commit and run code with that token, which reaches both the repository and the published asset. Both actions are now pinned to commit SHAs, with the version kept in a comment so upgrades stay readable. Permissions are declared explicitly: contents:write for the release workflow, contents:read for CI, which writes nothing. Note the @v2 bump in the previous commit introduced this exposure in its current form - the v1 reference had the same weakness. Co-Authored-By: Claude Opus 5 (1M context) --- .github/workflows/moodle-ci.yml | 4 ++++ .github/workflows/release.yml | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/moodle-ci.yml b/.github/workflows/moodle-ci.yml index c0cc7ca..e99d588 100644 --- a/.github/workflows/moodle-ci.yml +++ b/.github/workflows/moodle-ci.yml @@ -2,6 +2,10 @@ name: Moodle Plugin CI on: [push, pull_request] +# Nothing here writes to the repository. +permissions: + contents: read + jobs: test: runs-on: ubuntu-24.04 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 51f2f97..eddfa3c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,13 +4,17 @@ on: release: types: [created] +# Publishing the release asset is the only thing this workflow needs to write. +permissions: + contents: write + jobs: build: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 - name: Create ZIP file run: | @@ -19,7 +23,7 @@ jobs: zip -r mod_clickmeeting.zip mod_clickmeeting -x "*.git*" - name: Upload Release Asset - uses: softprops/action-gh-release@v2 + uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2.6.2 with: files: mod_clickmeeting.zip env: From 0801e4e71f3acff92171c54d6b5e2b7e0a3197ee Mon Sep 17 00:00:00 2001 From: bmarcinkowski Date: Fri, 9 Oct 2026 12:06:48 +0200 Subject: [PATCH 07/10] feat: declare supported Moodle branches The plugins directory advertised "2.6 to 4.5" purely because version.php never said otherwise, so Moodle 5.x users saw the plugin as incompatible even though it runs there fine. Declares supported = [39, 503], covering every branch actually verified for this release: 3.9 LTS, 3.11, 4.1 LTS, 4.5 LTS, 5.0, 5.1, 5.2 and 5.3. Each was given a clean install and a v1.1.5 to v1.2.0 upgrade; 4.1 through 5.3 are also covered by CI, 3.9 and 3.11 were checked locally on PHP 7.4. The lower bound stays at 3.9 deliberately. Those branches lost support in December 2023, but the plugin installs and upgrades there, and cutting them off would deny the sites least likely to upgrade Moodle the very fix that stops their meetings and recordings from being deleted. requires is left alone: supported is advisory and only changes what the directory and the admin page report, while requires blocks installation outright, and the boundary below 3.9 was not tested. Verified on live installs that Moodle reports the plugin as supported: branch 39 and branch 311 both return VERSION_SUPPORTED. Co-Authored-By: Claude Opus 5 (1M context) --- CHANGELOG.md | 6 ++++++ version.php | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed57382..d5728d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,12 @@ on purpose. - Privacy API support for the new table: the room owner is discoverable and is cleared on an erasure request, while the room itself stays scheduled for deletion. +### Compatibility + +Declares `$plugin->supported = [39, 503]`: Moodle 3.9 LTS through 5.3, each verified with a +clean install and a v1.1.5 upgrade. This is advisory - it does not block installation - and +makes the plugin show as compatible for Moodle 5.x in the plugins directory. + ### Upgrade notes Adds the table `clickmeeting_room_deletions`. Existing data is untouched. Rooms already diff --git a/version.php b/version.php index 857d6ab..a4bf415 100755 --- a/version.php +++ b/version.php @@ -28,7 +28,11 @@ defined('MOODLE_INTERNAL') || die(); $plugin->version = 2026100800; -$plugin->requires = 2013111811.01; // Requires this Moodle 2.6 version +$plugin->requires = 2013111811.01; // Requires this Moodle 2.6 version. +// Branches this release is actually tested against: 3.9 LTS through 5.3. This is advisory - +// it tells the plugins directory and the admin UI what we stand behind, without blocking +// installation anywhere $plugin->requires allows it. +$plugin->supported = [39, 503]; $plugin->maturity = MATURITY_STABLE; $plugin->cron = 0; $plugin->component = 'mod_clickmeeting'; From 53880f26f7c0c41afe024454b8a1ca6ae7950308 Mon Sep 17 00:00:00 2001 From: bmarcinkowski Date: Fri, 9 Oct 2026 12:22:02 +0200 Subject: [PATCH 08/10] fix: stop the release ZIP from nesting a copy of the plugin inside itself The build did `mkdir mod_clickmeeting` then `cp -R * mod_clickmeeting/`, but the glob already matched the directory it had just created, so cp copied the plugin into itself until it hit the recursion and bailed. The `|| true` swallowed that error, leaving roughly fifty stray files under mod_clickmeeting/mod_clickmeeting/ in the package every user downloads. Checking out directly into the plugin directory name produces the required layout with no copying at all. The ZIP drops from 168K to 92K. Verified by building the archive the way the runner does and installing Moodle 3.11 from the unpacked package rather than from the repository: no nesting, no .git files, correct version, table and scheduled task created. Co-Authored-By: Claude Opus 5 (1M context) --- .github/workflows/release.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eddfa3c..dfec0ad 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,14 +13,16 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout code + # Checking out straight into the plugin directory name gives the ZIP its required + # layout without copying, which previously nested a partial copy of the plugin + # inside itself because the glob already matched the freshly created directory. + - name: Check out into the plugin directory uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + path: mod_clickmeeting - name: Create ZIP file - run: | - mkdir mod_clickmeeting - cp -R * mod_clickmeeting/ 2>/dev/null || true - zip -r mod_clickmeeting.zip mod_clickmeeting -x "*.git*" + run: zip -r mod_clickmeeting.zip mod_clickmeeting -x "*.git*" - name: Upload Release Asset uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2.6.2 From 436053bfdcec64db6059b84f3f8385d867b93fb0 Mon Sep 17 00:00:00 2001 From: bmarcinkowski Date: Tue, 13 Oct 2026 21:36:28 +0200 Subject: [PATCH 09/10] fix: book a new ClickMeeting room when an activity is restored Backup carried conference_id over verbatim, so a restored or duplicated activity drove the very same room as its original. Two courses sharing one conference is wrong on its own, and deleting either activity took the room out from under the other. Restore now books a fresh room through the API, owned by whoever runs the restore, with a newly generated password; a refusal from the API aborts the restore rather than leaving an activity pointing at nothing. room_type had to join the backup for this: without it the new room could not be created with the type the original had. Backups written before this change carry no type and fall back to webinar. HACK-3336 Co-Authored-By: Claude Opus 5 (1M context) --- .../moodle2/backup_clickmeeting_stepslib.php | 1 + .../moodle2/restore_clickmeeting_stepslib.php | 55 ++++- lang/en/clickmeeting.php | 1 + lang/pl/clickmeeting.php | 1 + tests/restore_test.php | 215 ++++++++++++++++++ version.php | 2 +- 6 files changed, 270 insertions(+), 5 deletions(-) create mode 100644 tests/restore_test.php diff --git a/backup/moodle2/backup_clickmeeting_stepslib.php b/backup/moodle2/backup_clickmeeting_stepslib.php index 4849ae7..846f0ff 100755 --- a/backup/moodle2/backup_clickmeeting_stepslib.php +++ b/backup/moodle2/backup_clickmeeting_stepslib.php @@ -44,6 +44,7 @@ protected function define_structure() { 'course', 'name', 'description', + 'room_type', 'lobby_msg', 'start_time', 'access_type', diff --git a/backup/moodle2/restore_clickmeeting_stepslib.php b/backup/moodle2/restore_clickmeeting_stepslib.php index 1a759a2..203fc60 100755 --- a/backup/moodle2/restore_clickmeeting_stepslib.php +++ b/backup/moodle2/restore_clickmeeting_stepslib.php @@ -59,19 +59,66 @@ protected function process_clickmeeting($data) { } /** - * Inserts conference data into new table + * Creates a brand new ClickMeeting room for the restored activity. + * + * The backed up room belongs to the original activity and must not be shared: a copy would + * let two activities (and two courses) drive the same conference, and deleting one would + * take the other down with it. Restoring therefore books a fresh room through the API, + * owned by whoever is running the restore. * * @param object $data */ protected function process_clickmeeting_conferences($data) { - global $DB, $USER; + global $CFG, $DB, $USER; + global $clickmeetingowner; + require_once($CFG->dirroot . '/mod/clickmeeting/lib.php'); $data = (object)$data; - $oldid = $data->id; $data->user_id = $USER->id; $data->clickmeeting_id = $this->get_new_parentid('clickmeeting'); - $newitemid = $DB->insert_record('clickmeeting_conferences', $data); + $clickmeeting = $DB->get_record('clickmeeting', ['id' => $data->clickmeeting_id], '*', MUST_EXIST); + + // The room is created with the restoring user's API key, so it has to be billed to them too. + $clickmeetingowner = $USER->id; + + $password = clickmeeting_generate_password(8); + + $params = [ + 'name' => $clickmeeting->name, + // Backups taken before room_type was exported carry no type; webinar is the plugin default. + 'room_type' => !empty($clickmeeting->room_type) ? $clickmeeting->room_type : 'webinar', + 'permanent_room' => '0', + 'access_type' => $clickmeeting->access_type, + 'lobby_description' => $clickmeeting->lobby_msg, + 'starts_at' => $clickmeeting->start_time, + 'duration' => $clickmeeting->duration, + 'timezone' => date_default_timezone_get(), + 'password' => $password, + ]; + + $r = json_decode(clickmeeting_add_conference($params), true); + + if (!empty($r['code'])) { + $error = ''; + foreach ($r['errors'] as $err) { + $error .= $err['message'] . '
'; + } + throw new \moodle_exception($error, 'error'); + } + + if (!isset($r['room'])) { + throw new \moodle_exception('cannotcreateroom', 'clickmeeting'); + } + + $room = $r['room']; + $data->conference_id = $room['id']; + $data->room_url = $room['room_url']; + $data->embed_room = $room['embed_room_url']; + $data->room_pin = $room['room_pin']; + $data->password = $password; + + $DB->insert_record('clickmeeting_conferences', $data); } /** diff --git a/lang/en/clickmeeting.php b/lang/en/clickmeeting.php index ef3a181..f4ac59a 100755 --- a/lang/en/clickmeeting.php +++ b/lang/en/clickmeeting.php @@ -75,6 +75,7 @@ $string['startdate_booked'] = 'This start date is already booked'; $string['update_error'] = 'Error updating record'; +$string['cannotcreateroom'] = 'Could not create a ClickMeeting room for the restored activity'; $string['api_404_error'] = '404 Not Found'; $string['privacy:metadata:clickmeeting_api'] = 'In order to integrate with Clickmeeting API, user data needs to be exchanged with that service.'; diff --git a/lang/pl/clickmeeting.php b/lang/pl/clickmeeting.php index 68b9d43..92a8e5d 100755 --- a/lang/pl/clickmeeting.php +++ b/lang/pl/clickmeeting.php @@ -75,6 +75,7 @@ $string['startdate_booked'] = 'Nie można utworzyć konferencji dla tej daty'; $string['update_error'] = 'Błąd przy aktualizacji wpisu'; +$string['cannotcreateroom'] = 'Nie udało się utworzyć pokoju ClickMeeting dla przywracanej aktywności'; $string['api_404_error'] = '404 Not Found'; $string['privacy:metadata:clickmeeting_api'] = 'W celu zachowania poprawnej integracji z Clickmeeting API, następuje przekazanie danych uczestników do zewnętrznego systemu'; diff --git a/tests/restore_test.php b/tests/restore_test.php new file mode 100644 index 0000000..3f1a4a1 --- /dev/null +++ b/tests/restore_test.php @@ -0,0 +1,215 @@ +. + +namespace mod_clickmeeting; + +/** + * Tests for what happens to the ClickMeeting room when an activity is copied. + * + * Copying, importing and restoring a course all go through the restore machinery. A copy must + * get a room of its own: two activities sharing one room means two courses sharing one meeting, + * one set of recordings and one schedule. + * + * @package mod_clickmeeting + * @copyright 2026 Clickmeeting + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +final class restore_test extends \advanced_testcase { + /** @var string Room the API hands out when asked to create one. */ + private const API_NEW_ROOM = '{"room":{"id":777911,"room_url":"https://example.clickmeeting.com/new",' + . '"embed_room_url":"https://example.clickmeeting.com/new/embed","room_pin":222222}}'; + + /** @var int Room the original activity points at. */ + private const ORIGINAL_ROOM = 777900; + + /** + * Loads the plugin library and the course functions the tests drive. + */ + public static function setUpBeforeClass(): void { + global $CFG; + require_once($CFG->dirroot . '/mod/clickmeeting/lib.php'); + require_once($CFG->dirroot . '/course/lib.php'); + parent::setUpBeforeClass(); + } + + /** + * Points the plugin at a dead address, so a test that unexpectedly reaches for the + * network fails fast instead of talking to the real ClickMeeting API. + */ + protected function setUp(): void { + parent::setUp(); + $this->resetAfterTest(); + set_config('apiurl', 'http://127.0.0.1:9/', 'clickmeeting'); + } + + /** + * Creates an activity, its conference row and the course module holding them together. + * + * @param \stdClass $course Course the activity lives in. + * @param int $conferenceid ClickMeeting room the activity points at. + * @return \cm_info The new course module. + */ + private function create_activity(\stdClass $course, int $conferenceid): \cm_info { + global $DB, $USER; + + $timestart = time() + DAYSECS; + $instanceid = $DB->insert_record('clickmeeting', (object) [ + 'course' => $course->id, + 'name' => 'Webinar', + 'description' => 'A meeting', + 'user_id' => $USER->id, + 'lobby_msg' => 'Please wait', + 'start_time' => date('Y-m-d H:i:s', $timestart), + 'timestart' => $timestart, + 'duration' => 2, + 'room_type' => 'meeting', + 'access_type' => '1', + 'introformat' => 0, + 'timecreated' => time(), + 'timemodified' => time(), + ]); + $DB->insert_record('clickmeeting_conferences', (object) [ + 'clickmeeting_id' => $instanceid, + 'conference_id' => $conferenceid, + 'room_url' => 'https://example.clickmeeting.com/original', + 'embed_room' => 'https://example.clickmeeting.com/original/embed', + 'room_pin' => 111111, + 'password' => 'originalpassword', + ]); + + $module = $DB->get_record('modules', ['name' => 'clickmeeting'], '*', MUST_EXIST); + $cmid = add_course_module((object) [ + 'course' => $course->id, + 'module' => $module->id, + 'instance' => $instanceid, + 'section' => 0, + 'visible' => 1, + 'visibleold' => 1, + 'groupmode' => 0, + 'groupingid' => 0, + 'completion' => 0, + 'showdescription' => 0, + ]); + course_add_cm_to_section($course, $cmid, 0); + + return get_fast_modinfo($course)->get_cm($cmid); + } + + /** + * Returns the conference row belonging to an activity. + * + * @param int $instanceid Activity the room belongs to. + * @return \stdClass + */ + private function get_conference(int $instanceid): \stdClass { + global $DB; + + return $DB->get_record('clickmeeting_conferences', ['clickmeeting_id' => $instanceid], '*', MUST_EXIST); + } + + /** + * A duplicated activity must book its own room rather than reuse the original one. + */ + public function test_duplicating_an_activity_creates_a_new_room(): void { + $this->setAdminUser(); + $course = $this->getDataGenerator()->create_course(); + $cm = $this->create_activity($course, self::ORIGINAL_ROOM); + \curl::mock_response(self::API_NEW_ROOM); + + $copy = duplicate_module($course, $cm); + + $this->assertEquals(777911, $this->get_conference($copy->instance)->conference_id); + } + + /** + * The original activity keeps the room it had, so copying a course does not disturb it. + */ + public function test_duplicating_leaves_the_original_room_alone(): void { + $this->setAdminUser(); + $course = $this->getDataGenerator()->create_course(); + $cm = $this->create_activity($course, self::ORIGINAL_ROOM); + \curl::mock_response(self::API_NEW_ROOM); + + duplicate_module($course, $cm); + + $this->assertEquals(self::ORIGINAL_ROOM, $this->get_conference($cm->instance)->conference_id); + } + + /** + * Everything identifying the room has to come from the API answer. A copied room_url or + * password would send participants to the original meeting however new the room id looks. + */ + public function test_duplicating_does_not_copy_the_room_credentials(): void { + $this->setAdminUser(); + $course = $this->getDataGenerator()->create_course(); + $cm = $this->create_activity($course, self::ORIGINAL_ROOM); + \curl::mock_response(self::API_NEW_ROOM); + + $copy = duplicate_module($course, $cm); + + $conference = $this->get_conference($copy->instance); + $this->assertEquals('https://example.clickmeeting.com/new', $conference->room_url); + $this->assertEquals('https://example.clickmeeting.com/new/embed', $conference->embed_room); + $this->assertEquals(222222, $conference->room_pin); + $this->assertNotEquals('originalpassword', $conference->password); + } + + /** + * The room type decides what the booked room actually is, so the backup has to carry it. + */ + public function test_duplicating_keeps_the_room_type_of_the_original(): void { + global $DB; + + $this->setAdminUser(); + $course = $this->getDataGenerator()->create_course(); + $cm = $this->create_activity($course, self::ORIGINAL_ROOM); + \curl::mock_response(self::API_NEW_ROOM); + + $copy = duplicate_module($course, $cm); + + $this->assertEquals('meeting', $DB->get_record('clickmeeting', ['id' => $copy->instance])->room_type); + } + + /** + * If the room cannot be booked the copy would be an activity pointing at nothing, so the + * restore has to fail loudly instead of leaving that behind. + */ + public function test_duplicating_fails_when_the_api_cannot_create_a_room(): void { + global $DB; + + $this->setAdminUser(); + $course = $this->getDataGenerator()->create_course(); + $cm = $this->create_activity($course, self::ORIGINAL_ROOM); + \curl::mock_response('{"code":400,"errors":[{"message":"Room limit reached"}]}'); + + try { + duplicate_module($course, $cm); + $this->fail('Expected the restore to abort with a moodle_exception.'); + } catch (\moodle_exception $e) { + $this->assertStringContainsString('Room limit reached', $e->getMessage()); + } finally { + // An aborted restore never gets to drop its temporary table. A real request tears the + // database connection down with it, but here the table outlives the test and the reset + // afterwards trips over it, so drop it while it is still there. + foreach (['backup_ids_temp', 'backup_files_temp'] as $name) { + $temptable = new \xmldb_table($name); + if ($DB->get_manager()->table_exists($temptable)) { + $DB->get_manager()->drop_table($temptable); + } + } + } + } +} diff --git a/version.php b/version.php index a4bf415..e929be7 100755 --- a/version.php +++ b/version.php @@ -27,7 +27,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2026100800; +$plugin->version = 2026101300; $plugin->requires = 2013111811.01; // Requires this Moodle 2.6 version. // Branches this release is actually tested against: 3.9 LTS through 5.3. This is advisory - // it tells the plugins directory and the admin UI what we stand behind, without blocking From 15d2d05050f86a2ef892d0709aee0eed247e6c27 Mon Sep 17 00:00:00 2001 From: bmarcinkowski Date: Tue, 13 Oct 2026 22:07:14 +0200 Subject: [PATCH 10/10] fix: send the edited values when updating a ClickMeeting room Renaming or rescheduling an activity changed nothing on the ClickMeeting side. The request did go out, but empty: both edit calls handed their body to curl::put() through the options array, and put() overwrites that very option with its own $params argument, which was passed as an empty array. The API received a PUT with no fields and dutifully changed nothing, without an error to show for it. Passing the body as the $params argument puts it back on the wire. Covered by tests that run a stub HTTP server and read back the request that arrived, since a mocked response cannot tell an empty request from a full one. HACK-3336 Co-Authored-By: Claude Opus 5 (1M context) --- lib.php | 6 +- tests/api_test.php | 250 +++++++++++++++++++++++++++++++++++++++++++++ version.php | 2 +- 3 files changed, 255 insertions(+), 3 deletions(-) create mode 100644 tests/api_test.php diff --git a/lib.php b/lib.php index 9c477fa..51d9d17 100755 --- a/lib.php +++ b/lib.php @@ -154,7 +154,9 @@ function clickmeeting_edit_conference($conferenceid, $params) { $apiurl = get_config('clickmeeting', 'apiurl'); $curlhandle = clickmeeting_init_curl(); - $result = $curlhandle->put($apiurl . 'conferences/' . $conferenceid, [], ['CURLOPT_POSTFIELDS' => http_build_query($params, '', '&')]); + // The body goes in as the second argument: curl::put() overwrites the postfields option with + // whatever it finds there, so passing the body through the options would send an empty request. + $result = $curlhandle->put($apiurl . 'conferences/' . $conferenceid, http_build_query($params, '', '&')); return $result; } @@ -174,7 +176,7 @@ function clickmeeting_edit_conference_title($conferenceid, $title) { ]; $curlhandle = clickmeeting_init_curl(); - $result = $curlhandle->put($apiurl . 'conferences/' . $conferenceid, [], ['CURLOPT_POSTFIELDS' => http_build_query($params, '', '&')]); + $result = $curlhandle->put($apiurl . 'conferences/' . $conferenceid, http_build_query($params, '', '&')); return $result; } diff --git a/tests/api_test.php b/tests/api_test.php new file mode 100644 index 0000000..0bc96a7 --- /dev/null +++ b/tests/api_test.php @@ -0,0 +1,250 @@ +. + +namespace mod_clickmeeting; + +/** + * Tests for the requests the plugin puts on the wire. + * + * Mocked responses say nothing about what was actually sent, and the bug these tests cover lives + * entirely in the request: an edit that reached the API carrying no fields at all. So these tests + * run a throwaway HTTP server, point the plugin at it and read back the requests it received. + * + * @package mod_clickmeeting + * @copyright 2026 Clickmeeting + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +final class api_test extends \advanced_testcase { + /** @var resource|null Handle of the stub API server, closed after each test. */ + private $server = null; + + /** @var string Directory the stub server records received requests into. */ + private string $serverdir = ''; + + /** + * Loads the plugin library under test. + */ + public static function setUpBeforeClass(): void { + global $CFG; + require_once($CFG->dirroot . '/mod/clickmeeting/lib.php'); + require_once($CFG->dirroot . '/course/lib.php'); + parent::setUpBeforeClass(); + } + + /** + * Sets up a user, since every API call looks up its caller's API key. + */ + protected function setUp(): void { + parent::setUp(); + $this->resetAfterTest(); + $this->setAdminUser(); + } + + /** + * Stops the stub server so no process outlives the test. + */ + protected function tearDown(): void { + if (is_resource($this->server)) { + proc_terminate($this->server); + proc_close($this->server); + $this->server = null; + } + parent::tearDown(); + } + + /** + * Starts a stub ClickMeeting API on a free port and points the plugin at it. + * + * @param array $routes Responses keyed by "METHOD uri-fragment", matched in order. + * @param string $default Response for any request none of the routes matches. + */ + private function start_stub_api(array $routes, string $default = '{}'): void { + $this->serverdir = make_request_directory(); + file_put_contents($this->serverdir . '/routes.json', json_encode([ + 'routes' => $routes, + 'default' => $default, + ])); + file_put_contents($this->serverdir . '/router.php', <<<'PHP' + $_SERVER['REQUEST_METHOD'], + 'uri' => $_SERVER['REQUEST_URI'], + 'body' => file_get_contents('php://input'), + ]; + file_put_contents(__DIR__ . '/requests.jsonl', json_encode($request) . "\n", FILE_APPEND); + + $routes = json_decode(file_get_contents(__DIR__ . '/routes.json'), true); + $body = $routes['default']; + foreach ($routes['routes'] as $route => $response) { + [$method, $fragment] = explode(' ', $route, 2); + if ($method === $request['method'] && str_contains($request['uri'], $fragment)) { + $body = $response; + break; + } + } + + header('Content-Type: application/json'); + echo $body; + PHP); + + $socket = stream_socket_server('tcp://127.0.0.1:0'); + $address = stream_socket_get_name($socket, false); + $port = (int)substr($address, strrpos($address, ':') + 1); + fclose($socket); + + $devnull = ['file', '/dev/null', 'w']; + $this->server = proc_open( + [PHP_BINARY, '-S', '127.0.0.1:' . $port, '-t', $this->serverdir, $this->serverdir . '/router.php'], + [1 => $devnull, 2 => $devnull], + $pipes + ); + + for ($attempt = 0; $attempt < 100; $attempt++) { + $probe = @fsockopen('127.0.0.1', $port, $errno, $errstr, 0.1); + if ($probe !== false) { + fclose($probe); + set_config('apiurl', 'http://127.0.0.1:' . $port . '/', 'clickmeeting'); + return; + } + usleep(50000); + } + + $this->fail('The stub ClickMeeting API did not come up on port ' . $port . '.'); + } + + /** + * Returns the requests the stub API received, oldest first. + * + * @return array List of requests, each with method, uri and raw body. + */ + private function get_received_requests(): array { + $recorded = $this->serverdir . '/requests.jsonl'; + $this->assertFileExists($recorded, 'The plugin never reached the API.'); + + $requests = []; + foreach (file($recorded, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) { + $requests[] = json_decode($line, true); + } + + return $requests; + } + + /** + * Returns the first recorded request made with the given method. + * + * @param string $method HTTP method to look for. + * @return array The request, with method, uri and raw body. + */ + private function get_received_request(string $method): array { + foreach ($this->get_received_requests() as $request) { + if ($method === $request['method']) { + return $request; + } + } + + $this->fail('No ' . $method . ' request reached the API.'); + } + + /** + * Editing a room has to carry the new values; a PUT with an empty body leaves the room + * exactly as it was, which is how renaming or rescheduling an activity silently did nothing. + */ + public function test_editing_a_room_sends_the_changed_fields(): void { + $this->start_stub_api([], '{"room":{"id":777911}}'); + + clickmeeting_edit_conference(777911, [ + 'name' => 'Renamed meeting', + 'starts_at' => '2026-11-20 10:00:00', + 'duration' => 3, + ]); + + $request = $this->get_received_request('PUT'); + $this->assertStringContainsString('conferences/777911', $request['uri']); + parse_str($request['body'], $sent); + $this->assertSame('Renamed meeting', $sent['name']); + $this->assertSame('2026-11-20 10:00:00', $sent['starts_at']); + $this->assertSame('3', $sent['duration']); + } + + /** + * Renaming an activity inline on the course page goes through its own, narrower call, which + * has to put the new title on the wire just the same. + */ + public function test_editing_a_room_title_sends_the_new_title(): void { + $this->start_stub_api([], '{"room":{"id":777911}}'); + + clickmeeting_edit_conference_title(777911, 'Renamed inline'); + + $request = $this->get_received_request('PUT'); + parse_str($request['body'], $sent); + $this->assertSame('Renamed inline', $sent['name']); + } + + /** + * The whole path a teacher takes when they edit an activity: the new name and start date have + * to reach the room, not just the Moodle database. + */ + public function test_updating_an_activity_sends_the_new_name_and_date_to_the_api(): void { + global $COURSE, $DB; + + $course = $this->getDataGenerator()->create_course(); + $COURSE = $course; + // The edit form posts the section back and the update refuses to run without it. + $_POST['section'] = 0; + + $clickmeeting = (object)[ + 'course' => $course->id, + 'name' => 'Original name', + 'description' => '', + 'room_type' => 'meeting', + 'lobby_msg' => 'Please wait', + 'access_type' => '1', + 'timestart' => time() + DAYSECS, + 'start_time' => date('Y-m-d H:i:s', time() + DAYSECS), + 'duration' => 2, + 'user_id' => get_admin()->id, + 'timecreated' => time(), + 'timemodified' => time(), + ]; + $clickmeeting->id = $DB->insert_record('clickmeeting', $clickmeeting); + $DB->insert_record('clickmeeting_conferences', (object)[ + 'clickmeeting_id' => $clickmeeting->id, + 'conference_id' => 777911, + 'room_url' => 'https://example.clickmeeting.com/room', + 'embed_room' => 'https://example.clickmeeting.com/room/embed', + 'room_pin' => 111111, + 'password' => 'roompassword', + ]); + + $this->start_stub_api([ + 'GET conferences/777911' => '{"conference":{"status":"active"}}', + 'PUT conferences/777911' => '{"room":{"id":777911}}', + ], '{}'); + + $newstart = time() + (5 * DAYSECS); + $update = clone $clickmeeting; + $update->instance = $clickmeeting->id; + $update->name = 'Renamed by the teacher'; + $update->timestart = $newstart; + + clickmeeting_update_instance($update); + + $request = $this->get_received_request('PUT'); + parse_str($request['body'], $sent); + $this->assertSame('Renamed by the teacher', $sent['name']); + $this->assertSame(date('Y-m-d H:i:s', $newstart), $sent['starts_at']); + } +} diff --git a/version.php b/version.php index e929be7..6e0e08b 100755 --- a/version.php +++ b/version.php @@ -27,7 +27,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2026101300; +$plugin->version = 2026101301; $plugin->requires = 2013111811.01; // Requires this Moodle 2.6 version. // Branches this release is actually tested against: 3.9 LTS through 5.3. This is advisory - // it tells the plugins directory and the admin UI what we stand behind, without blocking