- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/lib/item/task.php
- Класс: BitrixTasksItemTask
- Вызов: Task::doPostActions
protected function doPostActions($state)
{
if ($state->isModeCreate())
{
// todo: TODO TODO TODO: create processors instead of this operations
// todo: think about "config object" that will allow to switch off some of these actions,
// todo: this config object may support hierarchy and partial update
// todo: example: ['notification' => ['enable' => true, 'add' => ['enable' => false]], 'cache' => ['reset' = ['enable' => true]]]
// todo: we can use BitrixTasksUtilTypeStructureChecker to check such option structure, set default one, etc...
// todo: refactor this later, get rid of CTasks completely
// todo: NOTE: for add() this is okay, but for update() some fields may be missing,
// todo: so its better to use actual data here, not from state (which eventually may be incomplete)
// todo: BELOW: do other stuff related with SE_ managing and other additional "actions"
// todo: it must not be hardcoded (as we do traditionally),
// todo: but should look as some kind of high-level event handling to be able to register, un-register and optionally turn off additional "actions"
$result = $state->getResult();
$taskId = $this->getId();
$userId = $this->getUserId();
$data = $this->prepareLegacyData();
$fullTaskData = $this->getData();
if ($taskId)
{
StagesTable::pinInStage($taskId);
}
$groupId = $data['GROUP_ID'];
$parentId = (int)$data['PARENT_ID'];
$participants = [$data['CREATED_BY'], $data['RESPONSIBLE_ID']];
if (isset($data['ACCOMPLICES']) && is_array($data['ACCOMPLICES']))
{
$participants = array_merge($participants, $data['ACCOMPLICES']);
}
if (isset($data['AUDITORS']) && is_array($data['AUDITORS']))
{
$participants = array_merge($participants, $data['AUDITORS']);
}
$participants = array_unique($participants);
// add to favorite, if parent is in the favorites too
if ($parentId && FavoriteTable::check(['TASK_ID' => $parentId, 'USER_ID' => $userId]))
{
FavoriteTable::add(['TASK_ID' => $taskId, 'USER_ID' => $userId], ['CHECK_EXISTENCE' => false]);
}
if ($groupId)
{
ProjectLastActivityTable::update($groupId, ['ACTIVITY_DATE' => $fullTaskData['ACTIVITY_DATE']]);
}
// note that setting occur as is deprecated. use access checker switch off instead
$occurAsUserId = (User::getOccurAsId() ?: $userId);
CTaskNotifications::sendAddMessage(
array_merge($data, ['CHANGED_BY' => $occurAsUserId]),
[
'SPAWNED_BY_AGENT' =>
($data['SPAWNED_BY_AGENT'] ?? null) === 'Y'
|| ($data['SPAWNED_BY_AGENT'] ?? null) === true,
]
);
BitrixTasksInternalsUserOptionTask::onTaskAdd($data);
CounterCounterService::addEvent(
CounterEventEventDictionary::EVENT_AFTER_TASK_ADD,
$data
);
// changes log
$this->addLogRecord([
"TASK_ID" => $taskId,
"USER_ID" => $occurAsUserId,
"CREATED_DATE" => $fullTaskData['CREATED_DATE'],
"FIELD" => "NEW",
], $result);
SearchTask::index($data); // todo: move this into a special processor
SearchIndex::setTaskSearchIndex($taskId, $fullTaskData);
CTaskSync::addItem($data); // MS Exchange
$commentPoster = CommentPoster::getInstance($taskId, $data['CREATED_BY'] ?? 0);
$commentPoster->postCommentsOnTaskAdd($data);
$this->sendPullEvents($data, $result);
$batchState = static::getBatchState();
$batchState->accumulateArray('USER', $participants);
if ($groupId)
{
$batchState->accumulateArray('GROUP', [$groupId]);
}
// todo: this should be moved inside PARENT_ID field controller:
if ($parentId)
{
Dependence::attachNew($taskId, $parentId);
}
// todo: move this into a separate processor
$this->processSchedulerAfter();
// if batch state is off, this will fire immediately.
// otherwise, this will fire only when somebody calls ::leaveBatchState() on this class
$batchState->fireLeaveCallback();
BizprocListener::onTaskAdd($taskId, $data);
}
elseif ($state->isModeUpdate())
{
// todo: DO NOT remove template in case of REPLICATE falls to N
$taskId = $this->getId();
if ($taskId)
{
StagesTable::pinInStage($taskId);
}
}
}