-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP Fix/attachmentnotfound - files are not properly deleted #146
Conversation
Thanks for following this up. |
Sorry to disappoint you, but if we are working in the same week, it is a priority... |
I am not disappointed. I trust you. :-) |
locallib.php
Outdated
@@ -1850,6 +1850,13 @@ function moodleoverflow_delete_post($post, $deletechildren, $cm, $moodleoverflow | |||
// Delete the read records. | |||
\mod_moodleoverflow\readtracking::moodleoverflow_delete_read_records(-1, $post->id); | |||
|
|||
// Delete the attachments. | |||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in this way you delete the db enrty, but NOT the actual file in the folder (db is just for where the file can be found)
Change to somthing like
$fs = get_file_storage();
// Prepare file record object
$fileinfo = array(
'component' => 'mod_mymodule',
'filearea' => 'myarea', // usually = table name
'itemid' => 0, // usually = ID of row in table
'contextid' => $context->id, // ID of context
'filepath' => '/', // any path beginning and ending in /
'filename' => 'myfile.txt'); // any filename
// Get file
$file = $fs->get_file($fileinfo['contextid'], $fileinfo['component'], $fileinfo['filearea'],
$fileinfo['itemid'], $fileinfo['filepath'], $fileinfo['filename']);
// Delete it if it exists
if ($file) {
$file->delete();
}
…od_moodleoverflow into fix/attachmentnotfound
No description provided.