20 if (!Loader::includeModule(self::$moduleId))
30 !\Bitrix\Main\ModuleManager::isModuleInstalled(
'bitrix24') &&
31 (php_sapi_name() ===
'cli');
35 $params = Option::get(self::$moduleId, self::OPTION_NAME,
'');
36 $params = $params !==
'' ? @unserialize($params, [
'allowed_classes' =>
false]) : [];
37 $params = is_array($params) ? $params : [];
44 'count' => ChatTable::getCount([
45 '>DISK_FOLDER_ID' => 0,
50 if ($params[
'count'] > 0)
53 $result[
'progress'] = 1;
54 $result[
'steps'] =
'';
55 $result[
'count'] = $params[
'count'];
58 '>DISK_FOLDER_ID' => 0,
60 if (isset($params[
'lastId']) && (
int)$params[
'lastId'] > 0)
62 $filter[
'<ID'] = (int)$params[
'lastId'];
64 $chatList = ChatTable::getList([
65 'select' => [
'ID',
'DISK_FOLDER_ID'],
67 'order' => [
'ID' =>
'DESC'],
72 $connection = \Bitrix\Main\Application::getConnection();
74 $accessProvider = new \Bitrix\Im\Access\ChatAuthProvider;
77 while ($row = $chatList->fetch())
79 $chatId = (int)$row[
'ID'];
80 $folderId = (int)$row[
'DISK_FOLDER_ID'];
82 $accessProvider->updateChatCodesByRelations($chatId);
84 $accessCode = $accessProvider->generateAccessCode($chatId);
86 $connection->queryExecute(
"
87 INSERT INTO b_disk_simple_right (OBJECT_ID, ACCESS_CODE)
88 SELECT P.OBJECT_ID, '{$accessCode}'
92 P.OBJECT_ID != {$folderId}
93 AND P.PARENT_ID = {$folderId}
96 $params[
'lastId'] = $chatId;
100 if (!$isCronRun && (time() - $startTime >= 30))
108 Option::set(self::$moduleId, self::OPTION_NAME, serialize($params));
112 $result[
'progress'] = floor($params[
'number'] * 100 / $params[
'count']);
113 $result[
'steps'] = $params[
'number'];
115 if ($found ===
false)
117 Option::delete(self::$moduleId, array(
'name' => self::OPTION_NAME));