• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/classes/general/tasksync.php
  • Класс: CTaskSync
  • Вызов: CTaskSync::UpdateItem
static function UpdateItem($arFields, $arTask)
{
	global $DB;

	// do not call static::checkExchangeAvailable() untill you sure exchange is needed for the task, or else you`ll load the module with no purpose

	$isResponsibleChanged = isset($arFields['RESPONSIBLE_ID'])
		&& isset($arTask['RESPONSIBLE_ID'])
		&& ((int)$arFields['RESPONSIBLE_ID'] !== (int)$arTask['RESPONSIBLE_ID']);

	// If responsible changed, we must reassign task to other Exchange-account,
	// but not update the existing task in account of prev. responsible
	if ($isResponsibleChanged && static::checkExchangeAvailable())
	{
		// Prevent unexpected resynchronization of this task in case if DeleteItem() or AddItem() will not complete they work
		$strSql = "UPDATE b_tasks SET EXCHANGE_ID = NULL, EXCHANGE_MODIFIED = NULL WHERE ID = " . (int) $arTask['ID'];
		$DB->Query($strSql, false, "File: ".__FILE__."
Line: ".__LINE__); self::DeleteItem($arTask); $arActualTaskData = array_merge($arTask, $arFields); self::AddItem($arActualTaskData); return; } // If item is not in Exchange, skip it ... if ( ! ($arTask["EXCHANGE_ID"] && $arTask["EXCHANGE_MODIFIED"]) ) { // ... but if there is responsible changed - create task in Exchange if ($isResponsibleChanged && static::checkExchangeAvailable()) { $arActualTaskData = array_merge($arTask, $arFields); self::AddItem($arActualTaskData); } return; } if(!static::checkExchangeAvailable()) { return; } $bodyType = 'html'; if (isset($arFields['DESCRIPTION_IN_BBCODE'])) { if ($arFields['DESCRIPTION_IN_BBCODE'] === 'Y') $bodyType = 'text'; } $priorityMapping = array_flip(self::$PriorityMapping); $arModifyEventArray = array( "USER_ID" => $arFields["RESPONSIBLE_ID"] ? $arFields["RESPONSIBLE_ID"] : $arTask["RESPONSIBLE_ID"], "BODY_TYPE" => $bodyType ); if ($arFields["TITLE"]) { $arModifyEventArray["SUBJECT"] = $arFields["TITLE"]; } if ($arFields["DESCRIPTION"]) { $arModifyEventArray["BODY"] = $arFields["DESCRIPTION"]; } if ($arFields["PRIORITY"]) { $arModifyEventArray["IMPORTANCE"] = $priorityMapping[mb_strtolower($arFields["PRIORITY"])]; } if (isset($arFields['GUID'])) $arModifyEventArray['GUID'] = $arFields['GUID']; //$arModifyEventArray['SERIALIZED_DATA'] = serialize($arFields); if ($arFields["DURATION_FACT"]) { $arModifyEventArray["ACTUAL_WORK"] = $arFields["DURATION_FACT"] * 60; } if ($arFields["START_DATE_PLAN"]) { $arModifyEventArray["START_DATE"] = $arFields["START_DATE_PLAN"]; } if ($arFields["DEADLINE"]) { $arModifyEventArray["DUE_DATE"] = $arFields["DEADLINE"]; } if ($arFields["STATUS"]) { $arModifyEventArray["STATUS"] = self::$StatusMappingReverse[$arFields["STATUS"]]; } if ($arFields["DURATION_PLAN"]) { $arModifyEventArray["TOTAL_WORK"] = $arFields["DURATION_PLAN"] * 60; } $result = CDavExchangeTasks::DoUpdateItem($arModifyEventArray["USER_ID"], $arTask["EXCHANGE_ID"], $arTask["EXCHANGE_MODIFIED"], $arModifyEventArray); if (array_key_exists("XML_ID", $result)) { $arExchangeFields = array( "EXCHANGE_MODIFIED" => $result["MODIFICATION_LABEL"] ); $strUpdate = $DB->PrepareUpdate("b_tasks", $arExchangeFields, "tasks"); $strSql = "UPDATE b_tasks SET ".$strUpdate." WHERE ID=".$arFields["ID"]; $DB->Query($strSql, false, "File: ".__FILE__."
Line: ".__LINE__); } }