Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
agent.php
1<?php
3
6use Bitrix\Main\Entity\ReferenceField;
7use Bitrix\Socialservices\EncryptedToken\UserTable as EncryptedTokenUserTable;
9
10class Agent
11{
12 public static function init()
13 {
14 Option::set("socialservices", "allow_encrypted_tokens", true);
15 $interval = IsModuleInstalled('bitrix24') ? 600 : 0;
16 \CAgent::AddAgent(
17 __CLASS__.'::runAgent();',
18 "socialservices",
19 "N",
20 60,
21 "",
22 "Y",
23 ConvertTimeStamp((time() + \CTimeZone::GetOffset() + $interval), 'FULL')
24 );
25 }
26
27 public static function runAgent()
28 {
29 if (self::run())
30 {
31 return __CLASS__.'::runAgent();';
32 }
33
34 UserTable::enableCrypto('OATOKEN');
35 UserTable::enableCrypto('OASECRET');
36 UserTable::enableCrypto('REFRESH_TOKEN');
37 return '';
38 }
39
40 public static function run()
41 {
42 $limit = Option::get("socialservices", "encrypt_tokens_step_limit", 500);
43 $lastEncryptedUserId = Option::get("socialservices", "last_encrypted_user_id", 0);
44 $users = UserTable::getList([
45 'order' => ['ID' => 'ASC'],
46 'select' => [
47 'ID', 'OATOKEN', 'OASECRET', 'REFRESH_TOKEN'
48 ],
49 'filter' => ['>ID' => $lastEncryptedUserId],
50 'limit' => $limit
51 ]);
52 $found = 0;
53 while ($user = $users->fetch())
54 {
55 $found++;
56
57 UserTable::update($user['ID'], [
58 'OATOKEN' => $user['OATOKEN'],
59 'OASECRET' => $user['OASECRET'],
60 'REFRESH_TOKEN' => $user['REFRESH_TOKEN'],
61 ]);
62
63 $lastEncryptedUserId = $user['ID'];
64 }
65 Option::set("socialservices", "last_encrypted_user_id", $lastEncryptedUserId);
66 return ($found >= $limit);
67 }
68}