diff --git a/lib/tests/upgradelib_test.php b/lib/tests/upgradelib_test.php index 70547536b05..d19f9a80711 100644 --- a/lib/tests/upgradelib_test.php +++ b/lib/tests/upgradelib_test.php @@ -178,6 +178,9 @@ class upgradelib_test 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 upgradelib_test 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); } } diff --git a/lib/upgradelib.php b/lib/upgradelib.php index 800745a8675..8ae11fe648e 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -2106,13 +2106,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)); }