Merge branch 'mdl-87187-51' of https://github.com/matthewhilton/moodle into MOODLE_501_STABLE

This commit is contained in:
Huong Nguyen
2026-02-19 08:50:47 +07:00
3 changed files with 69 additions and 4 deletions
@@ -63,7 +63,7 @@ class backup_bigbluebuttonbn_activity_structure_step extends backup_activity_str
$recording = new backup_nested_element('recording', ['id'], [
'courseid', 'bigbluebuttonbnid', 'groupid', 'recordingid', 'headlesss', 'imported', 'status', 'importeddata',
'timecreated']);
'timecreated', 'timemodified']);
// Build the tree.
$bigbluebuttonbn->add_child($logs);
@@ -58,7 +58,6 @@ class restore_bigbluebuttonbn_activity_structure_step extends restore_activity_s
global $DB;
$data = (object) $data;
$data->course = $this->get_courseid();
$data->timemodified = $this->apply_date_offset($data->timemodified);
// Check if we are in backup::MODE_IMPORT (we set a new meetingid) or backup::MODE_GENERAL (we keep the same meetingid).
if ($this->get_task()->get_info()->mode == backup::MODE_IMPORT || empty($data->meetingid)) {
// We are in backup::MODE_IMPORT, we need to renew the meetingid.
@@ -83,7 +82,6 @@ class restore_bigbluebuttonbn_activity_structure_step extends restore_activity_s
$data->courseid = $this->get_mappingid('course', $data->courseid);
$data->bigbluebuttonbnid = $this->get_new_parentid('bigbluebuttonbn');
$data->userid = $this->get_mappingid('user', $data->userid);
$data->timecreated = $this->apply_date_offset($data->timecreated);
// Insert the bigbluebuttonbn_logs record.
$newitemid = $DB->insert_record('bigbluebuttonbn_logs', $data);
// Immediately after inserting associated record, call this.
@@ -102,7 +100,6 @@ class restore_bigbluebuttonbn_activity_structure_step extends restore_activity_s
// Apply modifications.
$data->courseid = $this->get_mappingid('course', $data->courseid);
$data->bigbluebuttonbnid = $this->get_new_parentid('bigbluebuttonbn');
$data->timecreated = $this->apply_date_offset($data->timecreated);
// Insert the bigbluebuttonbn_recordings record.
$newitemid = $DB->insert_record('bigbluebuttonbn_recordings', $data);
// Immediately after inserting associated record, call this.
@@ -247,4 +247,72 @@ final class backup_restore_test extends restore_date_testcase {
array_filter((array) $bbbdest, $filterfunction, ARRAY_FILTER_USE_KEY)
);
}
/**
* Test that timecreated and timemodified are the same during backup and restore.
*
* This confirms that apply_date_offset is NOT applied to these fields.
*/
public function test_backup_restore_time_dates(): void {
global $DB;
$this->resetAfterTest();
// Make an activity, a recording, and a log.
[$bbactivitycontext, $bbactivitycm, $bbactivity] = $this->create_instance($this->get_course());
// Due to mod_helper::process_pre_save_instance, any new instances have their timemodified set to zero.
// So manually update it here.
$DB->update_record('bigbluebuttonbn', ['id' => $bbactivity->id, 'timemodified' => time()]);
$bbactivity = $DB->get_record('bigbluebuttonbn', ['id' => $bbactivity->id]);
$recording = new recording(0, (object)[
'courseid' => $this->get_course()->id,
'bigbluebuttonbnid' => $bbactivity->id,
'groupid' => 0,
'recordingid' => '123456789',
'imported' => 0,
'status' => recording::RECORDING_STATUS_PROCESSED,
]);
$recording->save();
$log = $DB->get_record('bigbluebuttonbn_logs', ['courseid' => $this->get_course()->id]);
$this->assertCount(1, $DB->get_records(recording::TABLE));
$this->assertCount(1, $DB->get_records('bigbluebuttonbn_logs'));
$this->assertCount(1, $DB->get_records('bigbluebuttonbn'));
$originalrecordingtimecreated = $recording->get('timecreated');
$originalrecordingtimemodified = $recording->get('timemodified');
$originalactivitytimecreated = $bbactivity->timecreated;
$originalactivitytimemodified = $bbactivity->timemodified;
$originallogtimecreated = $log->timecreated;
// Update the course to have a start time in the future.
$testtime = time();
$originalcoursestarttime = $testtime + YEARSECS;
$DB->update_record('course', ['id' => $this->get_course()->id, 'startdate' => $originalcoursestarttime]);
// Backup and restore to new course, with a start date even later in the future.
$newcoursestartime = $testtime + 2 * YEARSECS;
$newcourseid = $this->backup_and_restore($this->get_course(), $newcoursestartime);
// Sanity check the backup and restore was ok.
$this->assertCount(2, $DB->get_records(recording::TABLE));
$this->assertCount(2, $DB->get_records('bigbluebuttonbn_logs'));
$this->assertCount(2, $DB->get_records('bigbluebuttonbn'));
$newactivity = $DB->get_record('bigbluebuttonbn', ['course' => $newcourseid]);
$newlog = $DB->get_record('bigbluebuttonbn_logs', ['courseid' => $newcourseid]);
$newrecording = $DB->get_record(recording::TABLE, ['courseid' => $newcourseid]);
$this->assertNotEmpty($newactivity);
$this->assertNotEmpty($newlog);
$this->assertNotEmpty($newrecording);
// Assert times is the same.
$this->assertEquals($originalrecordingtimecreated, $newrecording->timecreated);
$this->assertEquals($originalrecordingtimemodified, $newrecording->timemodified);
$this->assertEquals($originalactivitytimecreated, $newactivity->timecreated);
$this->assertEquals($originalactivitytimemodified, $newactivity->timemodified);
$this->assertEquals($originallogtimecreated, $newlog->timecreated);
// Note: Logs don't have a timemodified.
}
}