public static function export_context_data(\core_privacy\local\request\contextlist_collection $contextlistcollection) {
        global $DB;

        $coursecontextids = $DB->get_records_menu('context', ['contextlevel' => CONTEXT_COURSE], '', 'id, instanceid');
        $courseids = [];
        foreach ($contextlistcollection as $component) {
            foreach ($component->get_contexts() as $context) {
                // All course contexts have been accounted for, so skip all checks.
                if (empty($coursecontextids)) {
                    break;
                }
                // Only course, module, and block contexts are checked.
                if (in_array($context->contextlevel, [CONTEXT_USER, CONTEXT_SYSTEM, CONTEXT_COURSECAT])) {
                    continue;
                }
                // If the context is a course, then we just add it without the need to check context path.
                if ($context->contextlevel == CONTEXT_COURSE) {
                    $courseids[$context->id] = $context->instanceid;
                    unset($coursecontextids[$context->id]);
                    continue;
                }
                // Otherwise, we need to check all the course context paths, to see if this context is a descendant.
                foreach ($coursecontextids as $contextid => $instanceid) {
                    if (stripos($context->path, '/' . $contextid . '/') !== false) {
                        $courseids[$contextid] = $instanceid;
                        unset($coursecontextids[$contextid]);
                    }
                }
            }
        }
        if (empty($courseids)) {
            return;
        }

        // Export general data for these contexts.
        list($sql, $params) = $DB->get_in_or_equal($courseids);
        $sql = 'id ' . $sql;
        $coursedata = $DB->get_records_select('course', $sql, $params);

        foreach ($coursedata as $course) {
            $context = \context_course::instance($course->id);
            $courseformat = $course->format !== 'site' ? get_string('pluginname', 'format_' . $course->format) : get_string('site');
            $data = (object) [
                'fullname' => $course->fullname,
                'shortname' => $course->shortname,
                'idnumber' => $course->idnumber,
                'summary' => writer::with_context($context)->rewrite_pluginfile_urls([], 'course', 'summary', 0,
                                                                                     format_string($course->summary)),
                'format' => $courseformat,
                'startdate' => transform::datetime($course->startdate),
                'enddate' => transform::datetime($course->enddate)
            ];
            writer::with_context($context)
                    ->export_area_files([], 'course', 'summary', 0)
                    ->export_area_files([], 'course', 'overviewfiles', 0)
                    ->export_data([], $data);
        }
    }