Skip to content

Conversation

@NinaHerrmann
Copy link
Contributor

No description provided.

@pejhab
Copy link

pejhab commented Jun 13, 2023

Thanks for following this up.
Shouldn't this be a priority as it breaks a core feature which makes a lot of forums unusable?

@NinaHerrmann
Copy link
Contributor Author

Sorry to disappoint you, but if we are working in the same week, it is a priority...

@pejhab
Copy link

pejhab commented Jun 13, 2023

I am not disappointed. I trust you. :-)

locallib.php Outdated
\mod_moodleoverflow\readtracking::moodleoverflow_delete_read_records(-1, $post->id);

// Delete the attachments.
try {
Copy link
Contributor Author

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();
}

(https://docs.moodle.org/dev/File_API#Delete_file)

@NinaHerrmann NinaHerrmann changed the title Fix/attachmentnotfound WIP Fix/attachmentnotfound - files are not properly deleted Jun 20, 2023
@NinaHerrmann NinaHerrmann merged commit 60402bd into master Jun 24, 2023
@TamaroWalter TamaroWalter deleted the fix/attachmentnotfound branch March 6, 2025 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants