public static function annotate_files($backupid, $contextid, $component, $filearea, $itemid,
            \core\progress\base $progress = null) {
        global $DB;
        $sql = 'SELECT id
                  FROM {files}
                 WHERE contextid = ?
                   AND component = ?';
        $params = array($contextid, $component);

        if (!is_null($filearea)) { // Add filearea to query and params if necessary
            $sql .= ' AND filearea = ?';
            $params[] = $filearea;
        }

        if (!is_null($itemid)) { // Add itemid to query and params if necessary
            $sql .= ' AND itemid = ?';
            $params[] = $itemid;
        }
        if ($progress) {
            $progress->start_progress('');
        }
        $rs = $DB->get_recordset_sql($sql, $params);
        foreach ($rs as $record) {
            if ($progress) {
                $progress->progress();
            }
            self::insert_backup_ids_record($backupid, 'file', $record->id);
        }
        if ($progress) {
            $progress->end_progress();
        }
        $rs->close();
    }