I experimented a bit further:
$fs = get_file_storage();
foreach(file("filedump.txt") as $filepath) {
$fieldlist = explode(',', $filepath);
// echo $fieldlist[0]; // id
// echo $fieldlist[1]; // contenthash
// echo $fieldlist[2]; // pathnamehash
// $fieldlist[3] = $context->$fieldlist[3]; // contextid ???
// echo $fieldlist[4]; // component
// echo $fieldlist[5]; // filearea
// echo $fieldlist[6]; // itemid
// echo $fieldlist[7]; // filepath
// echo $fieldlist[8]; // filename
// 'contextid' => $context->id, // ID of context
// Get file
// $file = $fs->get_file($fileinfo['contextid'], $fileinfo['component'], $fileinfo['filearea'], $fileinfo['itemid'], $fileinfo['filepath'], $fileinfo['filename']);
$file = $fs->get_file($fieldlist[3], $fieldlist[4], $fieldlist[5], $fieldlist[6], $fieldlist[7], $fieldlist[8]);
// Delete it if it exists
if ($file) {
echo "Found";
$file->delete();
}
else {
echo "Not found";
}
}
Sorry, I have to leave some debugging lines in the source. I think, my current problem is how to get the context from the context id. (See the ??? mid right.) If I uncomment that line I get:
PHP Notice: Undefined variable: context in /var/www/html/bztfdevmoodle/delfiledump.php on line 22
PHP Notice: Array to string conversion in /var/www/html/bztfdevmoodle/delfiledump.php on line 22
PHP Notice: Trying to get property 'Array' of non-object in /var/www/html/bztfdevmoodle/delfiledump.php on line 22
PHP Notice: Trying to access array offset on value of type null in /var/www/html/bztfdevmoodle/delfiledump.php on line 22
The cause must be obvious to the developers, who master Moodle's "context".