31 if (!Loader::includeModule(self::$moduleId))
36 $numOfIterations = (int)Option::get(self::$moduleId, self::OPTION_NAME_ITERATION_COUNT, self::ITERATION_COUNT_DEFAULT);
39 for ($i = 0; $i < $numOfIterations; ++$i)
41 $result = $this->makeMigrationIteration($option);
43 if ($result === self::FINISH_EXECUTION)
52 private function makeMigrationIteration(array &$option): bool
54 $isFinished = Option::get(self::$moduleId, self::OPTION_NAME,
'');
56 if ($isFinished ===
'')
58 Option::set(self::$moduleId, self::OPTION_NAME,
'N');
61 if ($isFinished ===
'Y')
66 $lastId = $option[
'lastId'] ?? 0;
67 $params = $this->getParams($lastId);
69 if ($params->count() === 0)
71 Option::set(self::$moduleId, self::OPTION_NAME,
'Y');
72 if (\
Bitrix\Main\Loader::includeModule(
'pull'))
75 Event::SHARED_CHANNEL,
78 'command' =>
'linkUrlMigrationFinished',
81 \CPullChannel::TYPE_SHARED
88 $ids = $params->getParamValueList();
89 $lastId = max($params->getIdList());
91 $urlsPreview = \Bitrix\Main\UrlPreview\UrlPreview::getMetadataByIds($ids);
92 $urlCollection =
new EO_LinkUrl_Collection();
94 foreach ($params as $param)
96 $urlPreview = $urlsPreview[$param->getParamValue()];
97 $uri =
new Uri($urlPreview[
'URL']);
98 if ($uri->getHost() ===
'')
102 $message = $param->getMessage();
103 if ($message ===
null)
107 $url =
new EO_LinkUrl();
109 ->setChatId($message->getChatId())
110 ->setAuthorId($message->getAuthorId())
111 ->setMessageId($param->getMessageId())
112 ->setDateCreate($message->getDateCreate())
113 ->setPreviewUrlId((
int)$urlPreview[
'ID'])
114 ->setUrl($urlPreview[
'URL'])
116 $urlCollection[] = $url;
118 $urlCollection->save(
true);
119 LinkUrlIndexTable::index((
int)Option::get(self::$moduleId, self::OPTION_NAME_LIMIT, self::LIMIT_DEFAULT));
120 $option[
'lastId'] = $lastId;
122 $count = MessageParamTable::getCount(Query::filter()->where(
'PARAM_NAME',
'URL_ID'));
123 $option[
'steps'] = $steps;
124 $option[
'count'] = $count;
129 private function getParams(
int $lastId): EO_MessageParam_Collection
131 $params = MessageParamTable::query()
133 ->where(
'PARAM_NAME',
'URL_ID')
134 ->where(
'ID',
'>', $lastId)
135 ->setOrder([
'ID' =>
'ASC'])
136 ->setLimit((
int)Option::get(self::$moduleId, self::OPTION_NAME_LIMIT, self::LIMIT_DEFAULT))
140 if ($params->count() === 0)
145 $params->fill([
'MESSAGE_ID',
'PARAM_VALUE']);
147 $messageIds = $params->getMessageIdList();
149 if (empty($messageIds))
154 $messages = MessageTable::query()
155 ->setSelect([
'ID',
'AUTHOR_ID',
'DATE_CREATE',
'CHAT_ID'])
156 ->whereIn(
'ID', $messageIds)
160 foreach ($params as $param)
162 $message = $messages->getByPrimary($param->getMessageId());
163 if ($message !==
null)
165 $param->setMessage($message);
static getCount($filter=array(), array $cache=array())