Enable CAS for all existing users

Created on 14 September 2022, over 2 years ago
Updated 27 February 2023, about 2 years ago

How can we programmatically enable cas for all existing users?

Created a hook_user_presave(EntityInterface $user) for this. First, a select query for authmap table to see if uid exits. If uid not in the table, use an insert query to add.

If I manually run the query it works and cas is enabled for the user:
INSERT INTO authmap(`provider`, `data`, `uid`, `authname`) VALUES ('cas','N;',uid,username)

If I try out either of the following queries it does not inserts the values into the authmap table:

        //values for uid and username are correct        
        $userID = $user->id();
        $userName = $user->getAccountName();
    $query = \Drupal::database()->insert('authmap')
                ->fields(['uid', 'provider', 'authname', 'data'])
                ->values([
                    'uid' => $userID,
                    'provider' => 'cas',
                    'authname' => $userName,
                    'data' => 'N;',
                ])
                ->execute();
$query = \Drupal::database()->insert('authmap');
            $query->fields([
                'uid',
                'provider',
                'authname',
                'data'
            ]);
            $query->values([
                $userID,
                'cas',
                $userName,
                'N;'
            ]);
            $query->execute();
πŸ’¬ Support request
Status

Active

Version

2.0

Component

CAS

Created by

πŸ‡ΊπŸ‡ΈUnited States emscha

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024