29 if (!Loader::includeModule(self::$moduleId))
31 return self::CONTINUE_EXECUTION;
34 $numOfIterations = (int)Option::get(self::$moduleId, self::OPTION_NAME_ITERATION_COUNT, self::ITERATION_COUNT_DEFAULT);
36 $result = self::CONTINUE_EXECUTION;
37 for (
$i = 0;
$i < $numOfIterations; ++
$i)
41 if (
$result === self::FINISH_EXECUTION)
50 private function makeMigrationIteration(
array &
$option): bool
52 $isFinished = Option::get(self::$moduleId, self::OPTION_NAME,
'');
54 if ($isFinished ===
'')
56 Option::set(self::$moduleId, self::OPTION_NAME,
'N');
59 if ($isFinished ===
'Y')
61 return self::FINISH_EXECUTION;
69 Option::set(self::$moduleId, self::OPTION_NAME,
'Y');
70 if (\
Bitrix\
Main\Loader::includeModule(
'pull'))
73 Event::SHARED_CHANNEL,
76 'command' =>
'linkFileMigrationFinished',
83 return self::FINISH_EXECUTION;
86 $ids =
$params->getParamValueList();
88 $this->changeMigrationFlag(
true);
89 $fileCollection =
new FileCollection();
90 $fileEntities = \Bitrix\Im\V2\Entity\File\FileCollection::initByDiskFilesIds($ids);
93 $fileEntity = $fileEntities->getById((
int)$param->getParamValue());
94 if ($fileEntity ===
null)
103 $file =
new FileItem();
106 ->setAuthorId(
$message->getAuthorId())
107 ->setMessageId($param->getMessageId())
108 ->setEntity($fileEntity)
109 ->setDateCreate(
$message->getDateCreate())
111 $fileCollection->add($file);
113 $fileCollection->save(
true);
114 $this->changeMigrationFlag(
false);
116 $steps = LinkFileTable::getCount();
117 $count = MessageParamTable::getCount(Query::filter()->where(
'PARAM_NAME',
'FILE_ID'));
121 return self::CONTINUE_EXECUTION;
124 private function getParams(
int $lastId): EO_MessageParam_Collection
126 $params = MessageParamTable::query()
128 ->where(
'PARAM_NAME',
'FILE_ID')
130 ->setOrder([
'ID' =>
'ASC'])
131 ->setLimit((
int)Option::get(self::$moduleId, self::OPTION_NAME_LIMIT, self::LIMIT_DEFAULT))
140 $params->fill([
'MESSAGE_ID',
'PARAM_VALUE']);
142 $messageIds =
$params->getMessageIdList();
144 if (empty($messageIds))
150 ->setSelect([
'ID',
'AUTHOR_ID',
'DATE_CREATE',
'CHAT_ID'])
151 ->whereIn(
'ID', $messageIds)
167 private function changeMigrationFlag(
bool $flag): void
169 $this->changeMigrationFlagForClass(FileCollection::class, $flag);
170 $this->changeMigrationFlagForClass(FileItem::class, $flag);
173 private function changeMigrationFlagForClass(
string $className,
bool $flag): void
175 $migrationFlagName =
'isMigrationFinished';
176 $migrationFlag = new \ReflectionProperty($className, $migrationFlagName);
177 $migrationFlag->setAccessible(
true);
178 $migrationFlag->setValue($flag);