-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsocial_auth.post_update.php
More file actions
59 lines (45 loc) · 1.34 KB
/
social_auth.post_update.php
File metadata and controls
59 lines (45 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* @file
* Method hook_post_update_NAME.
*/
/**
* Encrypts all tokens currently stored by Social Auth.
*/
function social_auth_post_update_encrypt_tokens(&$sandbox = NULL) {
$ids = \Drupal::entityQuery('social_auth')->execute();
$total = count($ids);
// Initializes some variables during the first pass through.
if (!isset($sandbox['total'])) {
$sandbox['total'] = $total;
$sandbox['progress'] = 0;
}
$nodes_per_batch = 25;
// Handles one pass through.
$ids = \Drupal::entityQuery('social_auth')
->range($sandbox['progress'], $sandbox['progress'] + $nodes_per_batch)
->execute();
/** @var \Drupal\social_auth\Entity\SocialAuth[] $social_auth_users */
$social_auth_users = \Drupal::entityTypeManager()
->getStorage('social_auth')
->loadMultiple($ids);
foreach ($social_auth_users as $user) {
$token = $user->get('token')->value;
// Sets token take care of the encryption.
$user->setToken($token)->save();
$sandbox['progress']++;
}
if ($sandbox['total'] == 0) {
$sandbox['#finished'] = 1;
}
else {
$sandbox['#finished'] = ($sandbox['progress'] / $sandbox['total']);
}
// Once finished.
if ($sandbox['#finished']) {
$ids = \Drupal::entityQuery('social_auth')->execute();
return t('Updated %n Social Auth users', [
'%n' => count($ids),
]);
}
}