- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/lib/integration/recyclebin/task.php
- Класс: BitrixTasksIntegrationRecyclebinTask
- Вызов: Task::moveFromRecyclebin
static function moveFromRecyclebin(Entity $entity)
{
$result = new Result();
$taskId = $entity->getEntityId();
$taskData = $entity->getData();
try
{
$cache = Cache::createInstance();
$cache->clean(CacheConfig::UNIQUE_CODE, CacheConfig::DIRECTORY);
}
catch (Exception $e)
{
$result->addError(new Error($e->getMessage(), $e->getCode()));
}
try
{
if (!$taskData)
{
return false;
}
// we should to restore task first
$taskRestored = false;
foreach ($taskData as $key => $value)
{
if ($value['ACTION'] !== 'TASK')
{
continue;
}
$restore = self::restoreAdditionalData($taskId, $value);
if (!$restore->isSuccess())
{
return false;
}
unset($taskData[$key]);
$taskRestored = true;
}
if (!$taskRestored)
{
return false;
}
foreach ($taskData as $value)
{
$restore = self::restoreAdditionalData($taskId, $value);
if (!$restore->isSuccess())
{
$result->addErrors($restore->getErrors());
}
}
$task = CTaskItem::getInstance($taskId, User::getAdminId());
$task->update([], [
'FORCE_RECOUNT_COUNTER' => 'Y',
'PIN_IN_STAGE' => false,
]);
$logFields = [
"TASK_ID" => $taskId,
"USER_ID" => User::getId(),
"CREATED_DATE" => new DateTime(),
"FIELD" => 'RENEW'
];
$log = new CTaskLog();
$log->Add($logFields);
CounterCounterService::addEvent(
CounterEventEventDictionary::EVENT_AFTER_TASK_RESTORE,
$task->getData(false)
);
IntegrationSocialNetworkLog::showLogByTaskId($taskId);
ItemTable::activateBySourceId($taskId);
(new TimeLineManager($taskId, User::getId()))->onTaskCreated(true)->save();
}
catch (Exception $e)
{
AddMessage2Log('Tasks RecycleBin: '.$e->getMessage().'. TaskId: '.$taskId.'. Data: '.var_export($taskData, true), 'tasks');
return false;
}
return $result;
}