Skip to content

Delete obsolete directories after purging the backups from mdl_files #2

@abias

Description

@abias

After purging the backups, there are obsolete directory entries left in mdl_files.

You might want to add something like that after line https://github.com/UniversidadORT/moodle-tool_autobackups/blob/master/cli/purge_autobackups.php#L89:

$sql2 = 'select id, contextid, itemid, filepath, filename 

from {files}
where component = \'backup\' and filearea = \'automated\' and filename = \'.\';';

$sth2 = $DB -> get_records_sql($sql2);

foreach ($sth2 as $id => $row) {
        $file = $fs -> get_file($row -> contextid, 'backup', 'automated', $row -> itemid, $row -> filepath, $row -> filename);
        if ($file) { // file found

                if (array_key_exists('c', $options) || array_key_exists('x', $options)) {
                        // Delete directory
                        if ( $file -> delete() ) {
                                echo 'Directory sent to trash:    ' . $file -> get_filename() . "\n";
                        } else {
                                echo 'Could not delete directory: ' . $file -> get_filename() . "\n";
                        }
                }
        }
}

Cheers,
Alex

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions