27 if (!Loader::includeModule(self::$moduleId))
31 $haveEventHandlersRestored = Option::get(self::$moduleId,
'have_event_handlers_restored',
'N');
33 if ($haveEventHandlersRestored !==
'Y')
35 $this->restoreEventHandlers();
38 $params = Option::get(self::$moduleId, self::OPTION_NAME,
'');
39 $params = $params !==
'' ? @unserialize($params, [
'allowed_classes' =>
false]) : [];
40 $params = is_array($params) ? $params : [];
45 'default_group_id' => $this->getDefaultGroupId(),
46 'last_recovered_user' => 0,
50 $notRecoveredUserIdList =
51 \Bitrix\Main\UserTable::query()
53 ->registerRuntimeField(
57 \
Bitrix\Im\Model\OptionUserTable::getEntity(),
58 \
Bitrix\Main\ORM\
Query\Join::on(
'this.ID',
'ref.USER_ID')
59 ))->configureJoinType(\
Bitrix\Main\ORM\
Query\Join::TYPE_LEFT)
61 ->whereNull(
'OPTION_USER.USER_ID')
62 ->where(
'IS_REAL_USER',
'Y')
63 ->where(
'ID',
'>', $params[
'last_recovered_user'])
68 if (empty($notRecoveredUserIdList))
70 Option::delete(self::$moduleId, [
'name' => self::OPTION_NAME]);
71 Option::delete(self::$moduleId, [
'name' =>
'have_event_handlers_restored']);
76 $notRecoveredUserIdList = array_map(
static fn($user) => (
int)$user[
'ID'], $notRecoveredUserIdList);
79 OptionGroupTable::query()
81 ->addSelect(
'USER_ID')
82 ->whereIn(
'USER_ID', $notRecoveredUserIdList)
86 $flippedNotRecoveredUserIdList = array_flip($notRecoveredUserIdList);
87 foreach ($userPresetList as $userPreset)
90 'USER_ID' => (int)$userPreset[
'USER_ID'],
91 'GENERAL_GROUP_ID' => (
int)$userPreset[
'ID'],
92 'NOTIFY_GROUP_ID' => (int)$userPreset[
'ID'],
95 'GENERAL_GROUP_ID' => (int)$userPreset[
'ID'],
96 'NOTIFY_GROUP_ID' => (
int)$userPreset[
'ID'],
99 OptionUserTable::merge($insertFields, $updateFields);
101 $params[
'last_recovered_user'] = (int)$userPreset[
'ID'];
102 unset($flippedNotRecoveredUserIdList[(
int)$userPreset[
'USER_ID']]);
105 foreach (array_flip($flippedNotRecoveredUserIdList) as $userId)
108 'USER_ID' => $userId,
109 'GENERAL_GROUP_ID' => $params[
'default_group_id'],
110 'NOTIFY_GROUP_ID' => $params[
'default_group_id']
113 'GENERAL_GROUP_ID' => $params[
'default_group_id'],
114 'NOTIFY_GROUP_ID' => $params[
'default_group_id'],
117 OptionUserTable::merge($insertFields, $updateFields);
119 $params[
'last_recovered_user'] = $userId;
123 $params = serialize($params);
124 Option::set(self::$moduleId, self::OPTION_NAME, $params);