public function attach_files($doc) {
        global $DB;

        $entryid = $doc->get('itemid');

        try {
            $entry = $this->get_entry($entryid);
        } catch (\dml_missing_record_exception $e) {
            debugging('Could not get record to attach files to '.$doc->get('id'), DEBUG_DEVELOPER);
            return;
        }

        $cm = $this->get_cm('data', $entry->dataid, $doc->get('courseid'));
        $context = \context_module::instance($cm->id);

        // Get the files and attach them.
        $fs = get_file_storage();
        $files = $fs->get_area_files($context->id, 'mod_data', 'content', $entryid, 'filename', false);
        foreach ($files as $file) {
            $doc->add_stored_file($file);
        }
    }