Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
chatdiskaccess.php
1<?php
2namespace Bitrix\Im\Update;
3
8
9
11{
12 const OPTION_NAME = 'disk_access_convert_stepper';
13 protected static $moduleId = 'im';
14
18 public function execute(array &$result)
19 {
20 if (!Loader::includeModule(self::$moduleId))
21 {
22 return false;
23 }
24
25 global $pPERIOD;
26 $pPERIOD = 30;
28 $startTime = time();
29 $isCronRun =
30 !\Bitrix\Main\ModuleManager::isModuleInstalled('bitrix24') &&
31 (php_sapi_name() === 'cli');
32
33 $return = false;
34
35 $params = Option::get(self::$moduleId, self::OPTION_NAME, '');
36 $params = $params !== '' ? @unserialize($params, ['allowed_classes' => false]) : [];
37 $params = is_array($params) ? $params : [];
38
39 if (empty($params))
40 {
41 $params = [
42 'lastId' => 0,
43 'number' => 0,
44 'count' => ChatTable::getCount([
45 '>DISK_FOLDER_ID' => 0,
46 ]),
47 ];
48 }
49
50 if ($params['count'] > 0)
51 {
52 $result['title'] = Loc::getMessage('IM_UPDATE_CHAT_DISK_ACCESS');
53 $result['progress'] = 1;
54 $result['steps'] = '';
55 $result['count'] = $params['count'];
56
57 $filter = [
58 '>DISK_FOLDER_ID' => 0,
59 ];
60 if (isset($params['lastId']) && (int)$params['lastId'] > 0)
61 {
62 $filter['<ID'] = (int)$params['lastId'];
63 }
64 $chatList = ChatTable::getList([
65 'select' => ['ID', 'DISK_FOLDER_ID'],
66 'filter' => $filter,
67 'order' => ['ID' => 'DESC'],
68 'offset' => 0,
69 'limit' => 1000,
70 ]);
71
72 $connection = \Bitrix\Main\Application::getConnection();
73
74 $accessProvider = new \Bitrix\Im\Access\ChatAuthProvider;
75
76 $found = false;
77 while ($row = $chatList->fetch())
78 {
79 $chatId = (int)$row['ID'];
80 $folderId = (int)$row['DISK_FOLDER_ID'];
81
82 $accessProvider->updateChatCodesByRelations($chatId);
83
84 $accessCode = $accessProvider->generateAccessCode($chatId);
85
86 $connection->queryExecute("
87 INSERT INTO b_disk_simple_right (OBJECT_ID, ACCESS_CODE)
88 SELECT P.OBJECT_ID, '{$accessCode}'
89 FROM
90 b_disk_object_path P
91 WHERE
92 P.OBJECT_ID != {$folderId}
93 AND P.PARENT_ID = {$folderId}
94 ");
95
96 $params['lastId'] = $chatId;
97 $params['number']++;
98 $found = true;
99
100 if (!$isCronRun && (time() - $startTime >= 30))
101 {
102 break;
103 }
104 }
105
106 if ($found)
107 {
108 Option::set(self::$moduleId, self::OPTION_NAME, serialize($params));
109 $return = true;
110 }
111
112 $result['progress'] = floor($params['number'] * 100 / $params['count']);
113 $result['steps'] = $params['number'];
114
115 if ($found === false)
116 {
117 Option::delete(self::$moduleId, array('name' => self::OPTION_NAME));
118 }
119 }
120
121 return $return;
122 }
123}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29