public static function remove_all_subscriptions_in_course($coursecontext) {
        global $DB;

        // Store all the subscriptions we have to delete.
        if ($subscriptions = $DB->get_records('tool_monitor_subscriptions', ['courseid' => $coursecontext->instanceid])) {
            // Delete subscriptions in bulk.
            $DB->delete_records('tool_monitor_subscriptions', ['courseid' => $coursecontext->instanceid]);

            // Trigger events one by one.
            foreach ($subscriptions as $subscription) {
                $params = ['objectid' => $subscription->id, 'context' => $coursecontext];
                $event = \tool_monitor\event\subscription_deleted::create($params);
                $event->add_record_snapshot('tool_monitor_subscriptions', $subscription);
                $event->trigger();
            }
        }
    }