mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-42882 upgrade: Improvements to upgrade code
Suggested by Petr: * Don't rely on single user for upgrade * Make the pathnamehash generation a bit clearer (and add a test to verify its correctly formed).
This commit is contained in:
parent
40c761e01a
commit
6c704b1534
@ -178,6 +178,9 @@ class core_upgradelib_testcase extends advanced_testcase {
|
||||
$folderrecord = $selectargs;
|
||||
$folderrecord['filepath'] = '/';
|
||||
$folderrecord['filename'] = '.';
|
||||
|
||||
// Get previous folder record.
|
||||
$oldrecord = $DB->get_record('files', $folderrecord);
|
||||
$DB->delete_records('files', $folderrecord);
|
||||
|
||||
// Verify the folder record has been removed.
|
||||
@ -193,6 +196,8 @@ class core_upgradelib_testcase extends advanced_testcase {
|
||||
$newareafilecount = $DB->count_records('files', $selectargs);
|
||||
$this->assertSame($newareafilecount, $areafilecount);
|
||||
|
||||
$this->assertTrue($DB->record_exists('files', $folderrecord));
|
||||
$newrecord = $DB->get_record('files', $folderrecord, '*', MUST_EXIST);
|
||||
// Verify the hash is correctly created.
|
||||
$this->assertSame($oldrecord->pathnamehash, $newrecord->pathnamehash);
|
||||
}
|
||||
}
|
||||
|
@ -2107,13 +2107,13 @@ function upgrade_fix_missing_root_folders() {
|
||||
$rs = $DB->get_recordset_sql($sql);
|
||||
$defaults = array('filepath' => '/',
|
||||
'filename' => '.',
|
||||
'userid' => $USER->id,
|
||||
'userid' => 0, // Don't rely on any particular user for these system records.
|
||||
'filesize' => 0,
|
||||
'timecreated' => time(),
|
||||
'timemodified' => time(),
|
||||
'contenthash' => sha1(''));
|
||||
foreach ($rs as $r) {
|
||||
$pathhash = sha1("/$r->contextid/$r->component/$r->filearea/$r->itemid".'/.');
|
||||
$pathhash = sha1("/$r->contextid/$r->component/$r->filearea/$r->itemid/.");
|
||||
$DB->insert_record('files', (array)$r + $defaults +
|
||||
array('pathnamehash' => $pathhash));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user