Delete all use data which matches the specified context.

@param \context $context The module context.
345743
public static function delete_data_for_all_users_in_context(\context $context) {
        global $DB;

        if ($context->contextlevel == CONTEXT_MODULE) {
            $cm = get_coursemodule_from_id('assign', $context->instanceid);
            if ($cm) {
                // Get the assignment related to this context.
                $assign = new \assign($context, null, null);
                // What to do first... Get sub plugins to delete their stuff.
                $requestdata = new assign_plugin_request_data($context, $assign);
                manager::plugintype_class_callback('assignsubmission', self::ASSIGNSUBMISSION_INTERFACE,
                    'delete_submission_for_context', [$requestdata]);
                $requestdata = new assign_plugin_request_data($context, $assign);
                manager::plugintype_class_callback('assignfeedback', self::ASSIGNFEEDBACK_INTERFACE,
                    'delete_feedback_for_context', [$requestdata]);
                $DB->delete_records('assign_grades', ['assignment' => $assign->get_instance()->id]);

                // Delete advanced grading information.
                $gradingmanager = get_grading_manager($context, 'mod_assign', 'submissions');
                $controller = $gradingmanager->get_active_controller();
                if (isset($controller)) {
                    \core_grading\privacy\provider::delete_instance_data($context);
                }

                // Time to roll my own method for deleting overrides.
                static::delete_overrides_for_users($assign);
                $DB->delete_records('assign_submission', ['assignment' => $assign->get_instance()->id]);
                $DB->delete_records('assign_user_flags', ['assignment' => $assign->get_instance()->id]);
                $DB->delete_records('assign_user_mapping', ['assignment' => $assign->get_instance()->id]);
            }
        }
    }
130019
public static function delete_data_for_user(approved_contextlist $contextlist) {
        global $DB;

        // Don't remove data from role_capabilities.
        // Because this data affects the whole Moodle, there are override capabilities.
        // Don't belong to the modifier user.

        // Remove data from role_assignments.
        if (empty($contextlist->count())) {
            return;
        }
        $userid = $contextlist->get_user()->id;
        $contextids = $contextlist->get_contextids();

        list($contextsql, $contextparams) = $DB->get_in_or_equal($contextids, SQL_PARAMS_NAMED);
        $params = ['userid' => $userid] + $contextparams;

        // Only delete the roles assignments where the user is assigned in all contexts.
        $DB->delete_records_select('role_assignments',
            "userid = :userid AND contextid {$contextsql}", $params);
    }
688245
public static function delete_instance_data(\context $context, int $itemid = null) {
        if (is_null($itemid)) {
            self::delete_data_for_instances($context);
        } else {
            self::delete_data_for_instances($context, [$itemid]);
        }
    }
418694
protected function _afterEntityDelete(AnCommandContext $context)
    {
        $this->getSpace()->setEntityState($context->entity, AnDomain::STATE_DESTROYED);
    }
580577
protected function _actionRemovephoto($context)
    {
        $lastPhoto = ($this->getItem()->photos->getTotal() > 1) ? false : true;
        $this->getItem()->removePhoto($this->photo);

        if ($lastPhoto) {
            $this->getResponse()->status = 204;

            return;
        } else {
            return $this->getItem();
        }
    }
26180
public static function delete_data_for_all_users_in_context(\context $context) {
        global $DB;

        if (!$context instanceof \context_module) {
            return;
        }

        if ($cm = get_coursemodule_from_id('choice', $context->instanceid)) {
            $DB->delete_records('choice_answers', ['choiceid' => $cm->instance]);
        }
    }
1197406
private static void cleanup(ContextFromVertx context) {
        // Release all resources, especially uploaded file.
        if (context != null) {
            context.cleanup();
        }
        Context.CONTEXT.remove();
    }
970835
public static function delete_data_for_user(approved_contextlist $contextlist) {
        global $DB;

        foreach ($contextlist as $context) {
            // Let's be super certain that we have the right information for this user here.
            if ($context->contextlevel == CONTEXT_USER && $contextlist->get_user()->id == $context->instanceid) {
                $DB->delete_records('block_recentlyaccesseditems', ['userid' => $context->instanceid]);
            }
        }
    }
548673
public static function delete_data_for_user(approved_contextlist $contextlist) {
        // The only way to delete data for the html block is to delete the block instance itself.
        foreach ($contextlist as $context) {

            if (!$context instanceof \context_block) {
                continue;
            }
            if ($blockinstance = static::get_instance_from_context($context)) {
                blocks_delete_instance($blockinstance);
            }
        }
    }
1160022
public static function delete_data_for_all_users_in_context(context $context) {
        global $DB;

        if ($context->contextlevel != CONTEXT_MODULE) {
            return;
        }

        $subwikis = $DB->get_fieldset_sql('SELECT s.id
              FROM {course_modules} cm
              JOIN {modules} m ON m.name = :wiki AND cm.module = m.id
              JOIN {wiki_subwikis} s ON s.wikiid = cm.instance
             WHERE cm.id = :cmid',
            ['cmid' => $context->instanceid, 'wiki' => 'wiki']);
        if (!$subwikis) {
            return;
        }

        $fs = get_file_storage();
        $fs->delete_area_files($context->id, 'mod_wiki', 'attachments');

        \core_tag\privacy\provider::delete_item_tags($context, 'mod_wiki', 'page');

        \core_comment\privacy\provider::delete_comments_for_all_users($context, 'mod_wiki', 'wiki_page');

        list($sql, $params) = $DB->get_in_or_equal($subwikis);
        $DB->delete_records_select('wiki_locks', 'pageid IN (SELECT id FROM {wiki_pages} WHERE subwikiid '.$sql.')', $params);
        $DB->delete_records_select('wiki_versions', 'pageid IN (SELECT id FROM {wiki_pages} WHERE subwikiid '.$sql.')', $params);
        $DB->delete_records_select('wiki_synonyms', 'subwikiid '.$sql, $params);
        $DB->delete_records_select('wiki_links', 'subwikiid '.$sql, $params);
        $DB->delete_records_select('wiki_pages', 'subwikiid '.$sql, $params);
        $DB->delete_records_select('wiki_subwikis', 'id '.$sql, $params);

        $DB->delete_records('tag_instance', ['contextid' => $context->id, 'component' => 'mod_wiki', 'itemtype' => 'page']);
    }
344147
public static function delete_data_for_user(approved_contextlist $contextlist) {
        global $DB;
        list($sql, $params) = static::get_sql_where_from_contexts($contextlist->get_contexts());
        if (empty($sql)) {
            return;
        }
        $userid = $contextlist->get_user()->id;
        $DB->delete_records_select('log', "$sql AND userid = :userid", array_merge($params, ['userid' => $userid]));
    }
123464
public static function delete_data_for_user(approved_contextlist $contextlist) {
        global $DB;

        // If the user has repository_instances data, then only the User context should be present so get the first context.
        $contexts = $contextlist->get_contexts();
        if (count($contexts) == 0) {
            return;
        }
        $context = reset($contexts);

        // Sanity check that context is at the User context level, then get the userid.
        if ($context->contextlevel !== CONTEXT_USER) {
            return;
        }
        $userid = $context->instanceid;

        // Delete the repository_instances records created for the userid.
        $DB->delete_records('repository_instances', ['userid' => $userid]);
    }
780284
public static function delete_data_for_all_users_in_context(context $context) {
        global $DB;
        list($sql, $params) = static::get_sql_where_from_contexts([$context]);
        if (empty($sql)) {
            return;
        }
        $DB->delete_records_select('log', $sql, $params);
    }
1368654
public static function delete_data_for_all_users_in_context(\context $context) {
        global $DB;

        // Check that this is a context_module.
        if (!$context instanceof \context_module) {
            return;
        }

        // Get the course module.
        if (!$cm = get_coursemodule_from_id('forum', $context->instanceid)) {
            return;
        }

        $forumid = $cm->instance;

        $DB->delete_records('forum_track_prefs', ['forumid' => $forumid]);
        $DB->delete_records('forum_subscriptions', ['forum' => $forumid]);
        $DB->delete_records('forum_read', ['forumid' => $forumid]);
        $DB->delete_records('forum_digests', ['forum' => $forumid]);

        // Delete all discussion items.
        $DB->delete_records_select(
            'forum_queue',
            "discussionid IN (SELECT id FROM {forum_discussions} WHERE forum = :forum)",
            [
                'forum' => $forumid,
            ]
        );

        $DB->delete_records_select(
            'forum_posts',
            "discussion IN (SELECT id FROM {forum_discussions} WHERE forum = :forum)",
            [
                'forum' => $forumid,
            ]
        );

        $DB->delete_records('forum_discussion_subs', ['forum' => $forumid]);
        $DB->delete_records('forum_discussions', ['forum' => $forumid]);

        // Delete all files from the posts.
        $fs = get_file_storage();
        $fs->delete_area_files($context->id, 'mod_forum', 'post');
        $fs->delete_area_files($context->id, 'mod_forum', 'attachment');

        // Delete all ratings in the context.
        \core_rating\privacy\provider::delete_ratings($context, 'mod_forum', 'post');

        // Delete all Tags.
        \core_tag\privacy\provider::delete_item_tags($context, 'mod_forum', 'forum_posts');
    }
605374
public static function delete_data_for_all_users_in_context(\context $context) {

        if (!$context instanceof \context_block) {
            return;
        }

        // The only way to delete data for the html block is to delete the block instance itself.
        if ($blockinstance = static::get_instance_from_context($context)) {
            blocks_delete_instance($blockinstance);
        }
    }
886276
public static function delete_all_for_context($contextid) {
        global $DB;

        $areaids = $DB->get_fieldset_select('grading_areas', 'id', 'contextid = ?', array($contextid));
        $methods = array_keys(self::available_methods(false));

        foreach($areaids as $areaid) {
            $manager = get_grading_manager($areaid);
            foreach ($methods as $method) {
                $controller = $manager->get_controller($method);
                $controller->delete_definition();
            }
        }

        $DB->delete_records_list('grading_areas', 'id', $areaids);
    }
428121
public static function delete_data_for_all_users_in_context(\context $context) {
        global $DB;

        // This should not happen, but just in case.
        if ($context->contextlevel != CONTEXT_MODULE) {
            return;
        }

        // Prepare SQL to gather all completed IDs.

        $completedsql = "
            SELECT fc.id
              FROM {%s} fc
              JOIN {modules} m
                ON m.name = :feedback
              JOIN {course_modules} cm
                ON cm.instance = fc.feedback
               AND cm.module = m.id
             WHERE cm.id = :cmid";
        $completedparams = ['cmid' => $context->instanceid, 'feedback' => 'feedback'];

        // Delete temp answers and submissions.
        $completedtmpids = $DB->get_fieldset_sql(sprintf($completedsql, 'feedback_completedtmp'), $completedparams);
        if (!empty($completedtmpids)) {
            list($insql, $inparams) = $DB->get_in_or_equal($completedtmpids, SQL_PARAMS_NAMED);
            $DB->delete_records_select('feedback_valuetmp', "completed $insql", $inparams);
            $DB->delete_records_select('feedback_completedtmp', "id $insql", $inparams);
        }

        // Delete answers and submissions.
        $completedids = $DB->get_fieldset_sql(sprintf($completedsql, 'feedback_completed'), $completedparams);
        if (!empty($completedids)) {
            list($insql, $inparams) = $DB->get_in_or_equal($completedids, SQL_PARAMS_NAMED);
            $DB->delete_records_select('feedback_value', "completed $insql", $inparams);
            $DB->delete_records_select('feedback_completed', "id $insql", $inparams);
        }
    }