@@ -94,7 +94,7 @@ function xmldb_auth_oidc_upgrade($oldversion) {
94
94
95
95
// Populate token oidcusername.
96
96
if (empty ($ user ->oidcusername )) {
97
- $ updatedtoken = new \ stdClass ;
97
+ $ updatedtoken = new stdClass ;
98
98
$ updatedtoken ->id = $ user ->tokenid ;
99
99
$ updatedtoken ->oidcusername = $ oidcusername ;
100
100
$ DB ->update_record ('auth_oidc_token ' , $ updatedtoken );
@@ -105,12 +105,12 @@ function xmldb_auth_oidc_upgrade($oldversion) {
105
105
// Old username, update to upn/sub.
106
106
if ($ oidcusername != $ user ->username ) {
107
107
// Update username.
108
- $ updateduser = new \ stdClass ;
108
+ $ updateduser = new stdClass ;
109
109
$ updateduser ->id = $ user ->userid ;
110
110
$ updateduser ->username = $ oidcusername ;
111
111
$ DB ->update_record ('user ' , $ updateduser );
112
112
113
- $ updatedtoken = new \ stdClass ;
113
+ $ updatedtoken = new stdClass ;
114
114
$ updatedtoken ->id = $ user ->tokenid ;
115
115
$ updatedtoken ->username = $ oidcusername ;
116
116
$ DB ->update_record ('auth_oidc_token ' , $ updatedtoken );
@@ -144,7 +144,7 @@ function xmldb_auth_oidc_upgrade($oldversion) {
144
144
foreach ($ authtokensrs as $ authtokenrec ) {
145
145
$ newusername = trim (\core_text::strtolower ($ authtokenrec ->username ));
146
146
if ($ newusername !== $ authtokenrec ->username ) {
147
- $ updatedrec = new \ stdClass ;
147
+ $ updatedrec = new stdClass ;
148
148
$ updatedrec ->id = $ authtokenrec ->id ;
149
149
$ updatedrec ->username = $ newusername ;
150
150
$ DB ->update_record ('auth_oidc_token ' , $ updatedrec );
@@ -181,7 +181,7 @@ function xmldb_auth_oidc_upgrade($oldversion) {
181
181
JOIN {user} u ON u.username = tok.username ' ;
182
182
$ records = $ DB ->get_recordset_sql ($ sql );
183
183
foreach ($ records as $ record ) {
184
- $ newrec = new \ stdClass ;
184
+ $ newrec = new stdClass ;
185
185
$ newrec ->id = $ record ->id ;
186
186
$ newrec ->userid = $ record ->userid ;
187
187
$ DB ->update_record ('auth_oidc_token ' , $ newrec );
@@ -504,5 +504,48 @@ function xmldb_auth_oidc_upgrade($oldversion) {
504
504
upgrade_plugin_savepoint (true , 2022112836 , 'auth ' , 'oidc ' );
505
505
}
506
506
507
+ if ($ oldversion < 2022112842 ) {
508
+ // Define table auth_oidc_sid to be created.
509
+ $ table = new xmldb_table ('auth_oidc_sid ' );
510
+
511
+ // Adding fields to table auth_oidc_sid.
512
+ $ table ->add_field ('id ' , XMLDB_TYPE_INTEGER , '10 ' , null , XMLDB_NOTNULL , XMLDB_SEQUENCE , null );
513
+ $ table ->add_field ('userid ' , XMLDB_TYPE_INTEGER , '20 ' , null , XMLDB_NOTNULL , null , null );
514
+ $ table ->add_field ('sid ' , XMLDB_TYPE_CHAR , '36 ' , null , XMLDB_NOTNULL , null , null );
515
+ $ table ->add_field ('timecreated ' , XMLDB_TYPE_INTEGER , '10 ' , null , XMLDB_NOTNULL , null , null );
516
+
517
+ // Adding keys to table auth_oidc_sid.
518
+ $ table ->add_key ('primary ' , XMLDB_KEY_PRIMARY , ['id ' ]);
519
+
520
+ // Conditionally launch create table for auth_oidc_sid.
521
+ if (!$ dbman ->table_exists ($ table )) {
522
+ $ dbman ->create_table ($ table );
523
+ }
524
+
525
+ // Migrate existing sid values from auth_oidc_tokens to auth_oidc_sid.
526
+ $ tokenrecords = $ DB ->get_records ('auth_oidc_token ' );
527
+ foreach ($ tokenrecords as $ tokenrecord ) {
528
+ if ($ tokenrecord ->sid ) {
529
+ $ sidrecord = new stdClass ();
530
+ $ sidrecord ->userid = $ tokenrecord ->userid ;
531
+ $ sidrecord ->sid = $ tokenrecord ->sid ;
532
+ $ sidrecord ->timecreated = time ();
533
+ $ DB ->insert_record ('auth_oidc_sid ' , $ sidrecord );
534
+ }
535
+ }
536
+
537
+ // Define field sid to be dropped from auth_oidc_token.
538
+ $ table = new xmldb_table ('auth_oidc_token ' );
539
+ $ field = new xmldb_field ('sid ' );
540
+
541
+ // Conditionally launch drop field sid.
542
+ if ($ dbman ->field_exists ($ table , $ field )) {
543
+ $ dbman ->drop_field ($ table , $ field );
544
+ }
545
+
546
+ // Oidc savepoint reached.
547
+ upgrade_plugin_savepoint (true , 2022112842 , 'auth ' , 'oidc ' );
548
+ }
549
+
507
550
return true ;
508
551
}
0 commit comments