Remove contributors

@param Site $site
@param int|int[] $userIdList
779105
public function removeContributors(Site $site, $userIdList)
    {
        $this->removeUsersWithRole($site, $userIdList, Access::ROLE_CONTRIB);
    }
938182
public static function get_users_in_context(userlist $userlist) {
        $context = $userlist->get_context();
        $params = ['contextid' => $context->id];

        // Add users who have modified the frameworks and related data in the context.
        $sql = "
             SELECT cf.usermodified
               FROM {" . competency_framework::TABLE . "} cf
              WHERE cf.contextid = :contextid";
        $userlist->add_from_sql('usermodified', $sql, $params);

        $sql = "
             SELECT c.usermodified
               FROM {" . competency_framework::TABLE . "} cf
               JOIN {" . competency::TABLE . "} c
                 ON c.competencyframeworkid = cf.id
              WHERE cf.contextid = :contextid";
        $userlist->add_from_sql('usermodified', $sql, $params);

        $sql = "
             SELECT cr.usermodified
               FROM {" . competency_framework::TABLE . "} cf
               JOIN {" . competency::TABLE . "} c
                 ON c.competencyframeworkid = cf.id
               JOIN {" . related_competency::TABLE . "} cr
                 ON cr.competencyid = c.id
              WHERE cf.contextid = :contextid";
        $userlist->add_from_sql('usermodified', $sql, $params);

        // Add users who have modified the templates and related data in the context.
        $sql = "
             SELECT tpl.usermodified
               FROM {" . template::TABLE . "} tpl
              WHERE tpl.contextid = :contextid";
        $userlist->add_from_sql('usermodified', $sql, $params);

        $sql = "
             SELECT tch.usermodified
               FROM {" . template::TABLE . "} tpl
               JOIN {" . template_cohort::TABLE . "} tch
                 ON tch.templateid = tpl.id
              WHERE tpl.contextid = :contextid";
        $userlist->add_from_sql('usermodified', $sql, $params);

        $sql = "
             SELECT tc.usermodified
               FROM {" . template::TABLE . "} tpl
               JOIN {" . template_competency::TABLE . "} tc
                 ON tc.templateid = tpl.id
              WHERE tpl.contextid = :contextid";
        $userlist->add_from_sql('usermodified', $sql, $params);

        // Add users if userlist is in course context.
        if (is_a($context, \context_course::class)) {
            $params = ['courseid' => $context->instanceid];

            $sql = "
                 SELECT cc.usermodified
                   FROM {" . course_competency::TABLE . "} cc
                  WHERE cc.courseid = :courseid";
            $userlist->add_from_sql('usermodified', $sql, $params);

            $sql = "
                 SELECT ccs.usermodified
                   FROM {" . course_competency_settings::TABLE . "} ccs
                  WHERE ccs.courseid = :courseid";
            $userlist->add_from_sql('usermodified', $sql, $params);

            $sql = "
                 SELECT ucc.userid, ucc.usermodified
                   FROM {" . user_competency_course::TABLE . "} ucc
                  WHERE ucc.courseid = :courseid";
            $userlist->add_from_sql('userid', $sql, $params);
            $userlist->add_from_sql('usermodified', $sql, $params);

        } else if (is_a($context, \context_module::class)) {
            // Add users if userlist is in module context.
            $params = ['moduleid' => $context->instanceid];

            $sql = "
                 SELECT cmc.usermodified
                   FROM {" . course_module_competency::TABLE . "} cmc
                  WHERE cmc.cmid = :moduleid";
            $userlist->add_from_sql('usermodified', $sql, $params);

        } else if (is_a($context, \context_user::class)) {
            $params = ['userid' => $context->instanceid];

            // Add users through plan related data.
            $sql = "
                 SELECT p.userid, p.usermodified, p.reviewerid
                   FROM {" . plan::TABLE . "} p
                  WHERE p.userid = :userid";
            $userlist->add_from_sql('userid', $sql, $params);
            $userlist->add_from_sql('usermodified', $sql, $params);
            $userlist->add_from_sql('reviewerid', $sql, $params);

            $sql = "
                 SELECT pc.usermodified
                   FROM {" . plan::TABLE . "} p
                   JOIN {" . plan_competency::TABLE . "} pc
                     ON pc.planid = p.id
                  WHERE p.userid = :userid";
            $userlist->add_from_sql('usermodified', $sql, $params);

            $sql = "
                 SELECT upc.usermodified
                   FROM {" . user_competency_plan::TABLE . "} upc
                  WHERE upc.userid = :userid";
            $userlist->add_from_sql('usermodified', $sql, $params);

            // Add users through competency data.
            $sql = "
                 SELECT uc.userid, uc.usermodified, uc.reviewerid
                   FROM {" . user_competency::TABLE . "} uc
                  WHERE uc.userid = :userid";
            $userlist->add_from_sql('userid', $sql, $params);
            $userlist->add_from_sql('usermodified', $sql, $params);
            $userlist->add_from_sql('reviewerid', $sql, $params);

            $sql = "
                 SELECT e.usermodified, e.actionuserid
                   FROM {" . user_competency::TABLE . "} uc
                   JOIN {" . evidence::TABLE . "} e
                     ON e.usercompetencyid = uc.id
                  WHERE uc.userid = :userid";
            $userlist->add_from_sql('usermodified', $sql, $params);
            $userlist->add_from_sql('actionuserid', $sql, $params);

            // Add users through evidence data.
            $sql = "
                 SELECT ue.userid, ue.usermodified
                   FROM {" . user_evidence::TABLE . "} ue
                  WHERE ue.userid = :userid";
            $userlist->add_from_sql('userid', $sql, $params);
            $userlist->add_from_sql('usermodified', $sql, $params);

            $sql = "
                 SELECT ue.usermodified
                   FROM {" . user_evidence::TABLE . "} ue
                   JOIN {" . user_evidence_competency::TABLE . "} uec
                     ON uec.userevidenceid = ue.id
                  WHERE ue.userid = :userid";
            $userlist->add_from_sql('usermodified', $sql, $params);
        }

        // Add users who commented in the context.
        // Note: Comment component must be competency and not core_competency.
        \core_comment\privacy\provider::get_users_in_context_from_sql(
                $userlist, 'com', 'competency', 'plan', $context->id);

        \core_comment\privacy\provider::get_users_in_context_from_sql(
                $userlist, 'com', 'competency', 'user_competency', $context->id);
    }
502868
public static function delete_data_for_users(approved_userlist $userlist) {
        global $DB;
        $context = $userlist->get_context();

        list($usersql, $userparams) = $DB->get_in_or_equal($userlist->get_userids(), SQL_PARAMS_NAMED);
        list($ownersql, $ownerparams) = $DB->get_in_or_equal($userlist->get_userids(), SQL_PARAMS_NAMED);

        $select = "contextid = :contextid AND (userid {$usersql} OR owneruserid {$ownersql})";
        $params = ['contextid' => $context->id] + $userparams + $ownerparams;

        $DB->delete_records_select('search_simpledb_index', $select, $params);
    }
966289
public static function delete_data_for_users(approved_userlist $userlist) {
        $context = $userlist->get_context();
        $userids = $userlist->get_userids();

        // Since this falls within a user context, only that user should be valid.
        if ($context->contextlevel != CONTEXT_USER || count($userids) != 1 || $context->instanceid != $userids[0]) {
            return;
        }

        static::delete_user_data($userids[0]);
    }
231882
@Override
    public void removeUser(int userID) {
        super.removeUser(userID);
        ratingsUser.remove(userID);
        usersStats.remove(userID);
    }
1016032
public static function delete_data_for_users(approved_userlist $userlist) {
        global $DB;

        $context = $userlist->get_context();
        // If the context isn't for a module then return early.
        if ($context->contextlevel != CONTEXT_MODULE) {
            return;
        }
        // Fetch the assignment.
        $assignment = self::get_assignment_by_context($context);
        $userids = $userlist->get_userids();

        list($inorequalsql, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
        $params['assignmentid'] = $assignment->id;

        // Get submission ids.
        $sql = "
            SELECT s.id
            FROM {assignment_submissions} s
            JOIN {assignment} a ON s.assignment = a.id
            WHERE a.id = :assignmentid
            AND s.userid $inorequalsql
        ";

        $submissionids = $DB->get_records_sql($sql, $params);
        list($submissionidsql, $submissionparams) = $DB->get_in_or_equal(array_keys($submissionids), SQL_PARAMS_NAMED);
        $fs = get_file_storage();
        $fs->delete_area_files_select($context->id, 'mod_assignment', 'submission', $submissionidsql, $submissionparams);
        // Delete related tables.
        $DB->delete_records_list('assignment_submissions', 'id', array_keys($submissionids));
    }
323667
public static function get_users_in_context(userlist $userlist) {
        $context = $userlist->get_context();

        // When we process user deletions and expiries, we always delete from the user context.
        // As a result the cohort role assignments would be deleted, which has a knock-on effect with courses
        // as roles may change and data may be removed earlier than it should be.

        $allowedcontextlevels = [
            CONTEXT_SYSTEM,
            CONTEXT_COURSECAT
        ];

        if (!in_array($context->contextlevel, $allowedcontextlevels)) {
            return;
        }

        $sql = "SELECT tc.userid as userid
                  FROM {tool_cohortroles} tc
                  JOIN {cohort} c
                       ON tc.cohortid = c.id
                 WHERE c.contextid = :contextid";

        $params = [
            'contextid' => $context->id
        ];

        $userlist->add_from_sql('userid', $sql, $params);
    }
1193108
public function removeUsers(array $userIds)
    {
        $userMongoIds = array();
        foreach ($userIds as $userId) {
            $userMongoIds[] = new \MongoId($userId);
        }

        $qb = $this->createQueryBuilder();
        $qb->remove()
           ->field('id')->in($userMongoIds)
           ->getQuery()
           ->execute();
    }
267862
public function removeMember($id, $userId)
    {
        try {
            $result = $this->service->remove(Auth::user(), $id, $userId);

            if ($result) {
                return back()->with('message', 'Successfully removed member');
            }

            return back()->with('message', 'Failed to remove member');
        } catch (Exception $e) {
            return back()->withErrors($e->getMessage());
        }
    }
113095
public static function delete_data_for_users(approved_userlist $userlist) {
        global $DB;
        $context = $userlist->get_context();
        $userids = $userlist->get_userids();

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

        // Remove only individual subwikis. Contributions to collaborative wikis is not considered personal contents.
        list($insql, $inparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
        $params = [
            'wiki' => 'wiki',
            'contextmod' => CONTEXT_MODULE,
            'contextid' => $context->id,
        ];

        $params = array_merge($inparams, $params);
        $sql = "SELECT s.id
                  FROM {context} ctx
                  JOIN {course_modules} cm ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextmod
                  JOIN {modules} m ON m.name = :wiki AND cm.module = m.id
                  JOIN {wiki_subwikis} s ON s.wikiid = cm.instance
                 WHERE ctx.id = :contextid
                   AND s.userid {$insql}";

        $subwikis = $DB->get_fieldset_sql($sql, $params);

        if ($subwikis) {
            // We found individual subwikis that need to be deleted completely.

            $fs = get_file_storage();
            foreach ($subwikis as $subwikiid) {
                $fs->delete_area_files($context->id, 'mod_wiki', 'attachments', $subwikiid);
                \core_comment\privacy\provider::delete_comments_for_all_users_select(context::instance_by_id($context->id),
                    'mod_wiki', 'wiki_page', "IN (SELECT id FROM {wiki_pages} WHERE subwikiid=:subwikiid)",
                    ['subwikiid' => $subwikiid]);
            }

            list($insql, $inparams) = $DB->get_in_or_equal($subwikis, SQL_PARAMS_NAMED);
            $params = ['component' => 'mod_wiki', 'itemtype' => 'page'];
            $params = array_merge($inparams, $params);
            $sql = "DELETE FROM {tag_instance}
                          WHERE component=:component
                            AND itemtype=:itemtype
                            AND itemid IN
                                (SELECT id
                                FROM {wiki_pages}
                                WHERE subwikiid $insql)";

            $DB->execute($sql, $params);

            $DB->delete_records_select('wiki_locks', "pageid IN (SELECT id FROM {wiki_pages} WHERE subwikiid {$insql})", $params);
            $DB->delete_records_select('wiki_versions', "pageid IN (SELECT id FROM {wiki_pages} WHERE subwikiid {$insql})",
                    $params);
            $DB->delete_records_select('wiki_synonyms', "subwikiid {$insql}", $params);
            $DB->delete_records_select('wiki_links', "subwikiid {$insql}", $params);
            $DB->delete_records_select('wiki_pages', "subwikiid {$insql}", $params);
            $DB->delete_records_select('wiki_subwikis', "id {$insql}", $params);
        }

        // Remove comments made by this user on all other wiki pages.
        \core_comment\privacy\provider::delete_comments_for_users($userlist, 'mod_wiki', 'wiki_page');
    }
1181279
public void removeResourceFromUsersPubList(CmsRequestContext context, Collection<CmsUUID> structureIds)
    throws CmsException {

        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
        try {
            m_driverManager.removeResourceFromUsersPubList(dbc, context.getCurrentUser().getId(), structureIds);
        } catch (Exception e) {
            dbc.report(
                null,
                Messages.get().container(
                    Messages.ERR_REMOVE_RESOURCE_FROM_PUBLIST_2,
                    context.getCurrentUser().getName(),
                    structureIds),
                e);

        } finally {
            dbc.clear();
        }
    }
1047952
public static function delete_data_for_users(approved_userlist $userlist) {
        global $DB;

        $context = $userlist->get_context();

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

        $cm = get_coursemodule_from_id('choice', $context->instanceid);

        if (!$cm) {
            // Only choice module will be handled.
            return;
        }

        $userids = $userlist->get_userids();
        list($usersql, $userparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);

        $select = "choiceid = :choiceid AND userid $usersql";
        $params = ['choiceid' => $cm->instance] + $userparams;
        $DB->delete_records_select('choice_answers', $select, $params);
    }
1156859
public function addWebmasters(Site $site, $userIdList)
    {
        $this->mergeUsersWithRole($site, $userIdList, Access::ROLE_WEBMASTER);
    }
848283
public function deleteForce(array $userIds): void
    {
        $deleted = $this->getRepository()->deleteForce($userIds);

        event(new HCUserForceDeleted($deleted));
    }
1328370
public function batchDeleteUser(array $userIdList)
    {
        $result = $this->httpRaw(self::WECHAT_USER_BATCH_DELETE_PREFIX, [
            'useridlist' => $userIdList
        ], [
            'access_token' => $this->getAccessToken()
        ]);
        return isset($result['errcode']) && ($result['errcode'] ? $this->dump([$result,$this->getAccessToken()]) : !$result['errcode']);
    }
838152
public static function delete_data_for_users(approved_userlist $userlist) {
        global $DB;

        $context = $userlist->get_context();
        $cm = $DB->get_record('course_modules', ['id' => $context->instanceid]);
        $chat = $DB->get_record('chat', ['id' => $cm->instance]);

        list($userinsql, $userinparams) = $DB->get_in_or_equal($userlist->get_userids(), SQL_PARAMS_NAMED);
        $params = array_merge(['chatid' => $chat->id], $userinparams);
        $sql = "chatid = :chatid AND userid {$userinsql}";

        $DB->delete_records_select('chat_messages', $sql, $params);
        $DB->delete_records_select('chat_messages_current', $sql, $params);
        $DB->delete_records_select('chat_users', $sql, $params);
    }
208823
function removeAuthors( $removeList )
    {
        if ( count( $removeList ) > 0 )
            foreach ( $removeList as $id )
            {
                foreach ( $this->Authors as $authorKey => $author )
                {
                    if ( $author['id'] == $id )
                    {
                        array_splice( $this->Authors, $authorKey, 1 );
                        $this->AuthorCount --;
                    }
                }
            }
    }