- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/lib/update/tagconverter.php
- Класс: BitrixTasksUpdateTagConverter
- Вызов: TagConverter::run
private function run(): string
{
if (!Loader::includeModule('tasks'))
{
$this->convertDone();
return '';
}
$oldTags = $this->getOldList();
if (empty($oldTags))
{
$this->convertDone();
return '';
}
$taskTagRelations = [];
foreach ($oldTags as $tag)
{
$id = $this->getIdInLabelTable($tag);
if (is_null($id))
{
try
{
$result = LabelTable::add([
'NAME' => trim($tag['NAME']),
'USER_ID' => (int)$tag['GROUP_ID'] === 0 ? $tag['USER_ID'] : 0,
'GROUP_ID' => $tag['GROUP_ID'],
]);
}
catch (Exception $e)
{
(new Log())->collect("Unable to convert tag {$tag['NAME']}: {$e->getMessage()}");
continue;
}
$id = $result->isSuccess() ? $result->getId() : null;
}
if (!is_null($id))
{
$taskTagRelations[] = [
'TAG_ID' => $id,
'TASK_ID' => $tag['TASK_ID'],
];
}
}
try
{
$this->saveRelations($taskTagRelations);
$this->markTagsAsConverted($oldTags);
}
catch (Exception $e)
{
(new Log())->collect("Unable to convert tags: {$e->getMessage()}");
return '';
}
if ($this->needToStop())
{
$this->convertDone();
return '';
}
Option::set('tasks', self::OPTION_KEY, 'process', '-');
return self::getAgentName();
}