function put_commit(&$options)
{
if(!empty($options["IBLOCK_SECTION_ID"]))
{
$sectionData = $this->getSectionDataForLinkAnalyze($options["IBLOCK_SECTION_ID"], $this->getObject(array('section_id' => $options["IBLOCK_SECTION_ID"])));
//simple detect link
list($contextType, $contextEntityId) = $this->getContextData();
$isSymlink = !$this->_symlinkMode && CWebDavSymlinkHelper::isLink($contextType, $contextEntityId, $sectionData);
if($isSymlink)
{
$symlinkSectionData = CWebDavSymlinkHelper::getLinkData($contextType, $contextEntityId, $sectionData);
if($symlinkSectionData)
{
$linkWebdav = new self($symlinkSectionData[self::UF_LINK_IBLOCK_ID], $this->base_url . $this->_path, array_merge($this->_originalParams, array(
'ROOT_SECTION_ID' => $symlinkSectionData[self::UF_LINK_SECTION_ID],
'symlinkMode' => true,
'symlinkSectionData' => $symlinkSectionData,
'symlinkRealRootSectionData' => $this->arRootSection,
)));
$options = array_merge($options, array(
'IBLOCK_ID' => $symlinkSectionData[self::UF_LINK_IBLOCK_ID],
'IBLOCK_SECTION_ID' => $sectionData['ID'],
));
return $linkWebdav->put_commit($options);
}
}
}
$ID = intval($options["ELEMENT_ID"]);
$arError = array();
$arFile = array(
"name" => $options["FILE_NAME"],
"size" => $options["content_length"],
"tmp_name" => $options["TMP_FILE"],
"type" => "",
"error" => 0);
if(!empty($options['HEIGHT']))
{
$arFile['HEIGHT'] = $options['HEIGHT'];
}
if(!empty($options['WIDTH']))
{
$arFile['WIDTH'] = $options['WIDTH'];
}
if (is_set($options, "arFile"))
$arFile = $options["arFile"];
if (isset($arFile['tmp_name']) && is_file($arFile['tmp_name']))
{
if (intval($arFile["size"]) <= 0)
$arFile["size"] = filesize($arFile["tmp_name"]);
if (($arFile['type'] == '') && ($arFile["size"] > 0))
{
$arFile["type"] = CFile::GetContentType($arFile['tmp_name'], true);
}
if (($arFile['type'] == '')
|| ($arFile['type'] == 'application/zip') // fix old magic.mime
)
$arFile['type'] = $this->get_mime_type($arFile['name']);
}
if (isset($arFile['tmp_name']) && $arFile["type"] == '')
$arFile["type"] = $this->get_mime_type($options["FILE_NAME"]);
$bDropped = isset($options['dropped']) ? $options['dropped'] : false;
@set_time_limit(1000);
if (is_set($options, "~path") && $_SESSION["WEBDAV_DATA"]["PUT_MAC_OS"] == $options["~path"])
{
// "For Mac OS";
if ($options["new"])
{
$arr = array(
"ACTIVE" => "N",
"IBLOCK_ID" => $this->IBLOCK_ID,
"IBLOCK_SECTION_ID" => $options["IBLOCK_SECTION_ID"],
"NAME" => $options["FILE_NAME"],
"MODIFIED_BY" => $GLOBALS["USER"]->GetID(),
"PROPERTY_VALUES" => array(
$this->file_prop => $arFile,
"WEBDAV_SIZE" => $arFile['size']
));
if ($arFile["size"] <= 0)
unset($arr["PROPERTY_VALUES"]);
$ID = $this->_ib_elm_add($arr, false, false, false);
if (!$ID)
{
return false;
}
else
{
$this->arParams["changed_element_id"] = $ID;
}
}
else
{
$arr = array(
"MODIFIED_BY" => $GLOBALS["USER"]->GetID(),
"PROPERTY_VALUES" => array(
$this->file_prop => $arFile,
"WEBDAV_SIZE" => $arFile['size']
));
$res = $this->_ib_elm_update($options["ELEMENT_ID"], $arr, false);
if(!$res) return false;
}
}
elseif (is_set($options, "~path") && $this->workflow && !$options["set_now"] && $_SESSION["WEBDAV_DATA"]["PUT_EMPTY"] == $options["~path"])
{
$arr = array(
"MODIFIED_BY" => $GLOBALS["USER"]->GetID(),
"PROPERTY_VALUES" => array(
$this->file_prop => $arFile,
"WEBDAV_SIZE" => $arFile['size']
));
$res = $this->_ib_elm_update($options["ELEMENT_ID"], $arr, ($this->workflow == 'workflow'));
if(!$res) return false;
//if ($this->workflow == 'bizproc_limited' || $this->workflow == 'bizproc')
//{
/**
* Update history comments
*/
//$documentId = array($this->wfParams['DOCUMENT_TYPE'][0], $this->wfParams['DOCUMENT_TYPE'][1], $options["ELEMENT_ID"]);
//$history = new CBPHistoryService();
//$db_res = $history->GetHistoryList(
//array("ID" => "DESC"),
//array("DOCUMENT_ID" => $documentId),
//false,
//false,
//array("ID", "DOCUMENT", "NAME")
//);
//if ($db_res && $arr = $db_res->Fetch())
//{
//$fullpath = $_SERVER["DOCUMENT_ROOT"].$arr["DOCUMENT"]["PROPERTIES"][$this->file_prop]["VALUE"];
//if (!file_exists($fullpath) || filesize($fullpath) <= 0)
//CBPHistoryService::Delete($arr["ID"], $documentId);
//CBPDocument::AddDocumentToHistory($documentId, $arr["NAME"], $GLOBALS["USER"]->GetID());
//}
//}
$_SESSION["WEBDAV_DATA"] = array();
WDPackCookie();
}
else
{
if ($this->workflow == "workflow" && $this->permission < "W")
// && (is_set($options, "WF_STATUS_ID") || $options["ELEMENT_ID"] <= 0))
{
$fw_status_id = (is_set($options, "WF_STATUS_ID") ? $options["WF_STATUS_ID"] : false);
$arStatusesPermission = array();
$db_res = CWorkflowStatus::GetDropDownList("N", "desc");
while ($db_res && $res = $db_res->Fetch())
{
$perm = CIBlockElement::WF_GetStatusPermission($res["REFERENCE_ID"]);
if ($perm < 1)
continue;
$arStatusesPermission[intval($res["REFERENCE_ID"])] = $perm;
if ((($fw_status_id === false) && $perm >= 2) || $fw_status_id == $res["REFERENCE_ID"])
{
$fw_status_id = $res["REFERENCE_ID"];
break;
}
}
if (empty($arStatusesPermission))
{
$this->LAST_ERROR = GetMessage("WD_FILE_ERROR_EMPTY_STATUSES");
return false;
}
elseif ($options["WF_STATUS_ID"] == $fw_status_id && !array_key_exists($fw_status_id, $arStatusesPermission))
{
$res = array_flip($arStatusesPermission);
$fw_status_id = (isset($res[2]) ? $res[2] : reset($res));
}
$options["WF_STATUS_ID"] = $fw_status_id;
}
/**
* Validate bizproc input parameters for begining BP
*/
elseif (
($this->workflow == 'bizproc')
&& (! $bDropped)
)
{
$arDocumentStates = array();
if (is_set($options, "arDocumentStates"))
{
$arDocumentStates = $options["arDocumentStates"];
}
elseif (is_set($this->wfParams, "arDocumentStates"))
{
$arDocumentStates = $this->wfParams["arDocumentStates"];
}
else
{
$arDocumentStates = CBPDocument::GetDocumentStates(
$this->wfParams['DOCUMENT_TYPE'],
(
$options["ELEMENT_ID"] > 0 ?
array(
$this->wfParams['DOCUMENT_TYPE'][0],
$this->wfParams['DOCUMENT_TYPE'][1],
$options["ELEMENT_ID"]) :
null
)
);
}
foreach ($arDocumentStates as $key => $arDocumentState)
{
if ($arDocumentState["ID"] == '' && is_array($arDocumentState["TEMPLATE_PARAMETERS"]))
{
$templateId = $arDocumentState["TEMPLATE_ID"];
foreach ($arDocumentState["TEMPLATE_PARAMETERS"] as $key => $arWorkflowParameters)
$_REQUEST["bizproc".$templateId."_".$key] = (array_key_exists("bizproc".$templateId."_".$key, $_REQUEST) ?
$_REQUEST["bizproc".$templateId."_".$key] : $arWorkflowParameters["Default_printable"]);
}
}
$arBizProcParametersValues = $arErrors = array();
if (!CIBlockDocumentWebdav::StartWorkflowsParametersValidate($this->wfParams["DOCUMENT_TYPE"], $arDocumentStates, $arBizProcParametersValues, $arErrors))
{
$e = new CAdminException($arErrors);
$this->LAST_ERROR = $e->GetString();
return false;
}
}
/**
* Add or update or clone elements
*/
if ($options["clone"])
{
$arr = array(
"CREATED_BY" => $GLOBALS["USER"]->GetID(),
"MODIFIED_BY" => $GLOBALS["USER"]->GetID(),
"PROPERTY_VALUES" => array(
$this->file_prop => $arFile,
"WEBDAV_SIZE" => $arFile['size'],
static::PROPERTY_VERSION => 1,
));
foreach (array("NAME", "TAGS", "PREVIEW_TEXT", "PREVIEW_TEXT_TYPE", "ACTIVE", "WF_COMMENTS", "WF_STATUS_ID") as $key)
if (is_set($options, $key))
$arr[$key] = $options[$key];
if ($arFile["size"] <= 0)
unset($arr["PROPERTY_VALUES"]);
$options["ELEMENT_ID"] = $ID = call_user_func_array(
array($this->wfParams['DOCUMENT_TYPE'][1], "CloneElement"),
array($options["PARENT_ELEMENT_ID"], $arr));
CIBlockElement::SetPropertyValues($options["ELEMENT_ID"], $this->IBLOCK_ID, array(0), "FORUM_MESSAGE_CNT");
CIBlockElement::SetPropertyValues($options["ELEMENT_ID"], $this->IBLOCK_ID, array(0), "FORUM_TOPIC_ID");
}
elseif ($options["new"])
{
$arr = array(
"ACTIVE" => "Y",
"IBLOCK_ID" => $this->IBLOCK_ID,
"IBLOCK_SECTION_ID" => $options["IBLOCK_SECTION_ID"],
"NAME" => $options["FILE_NAME"],
"TAGS" => $options["TAGS"],
"MODIFIED_BY" => $GLOBALS["USER"]->GetID(),
"PREVIEW_TEXT_TYPE" => "html",
"PREVIEW_TEXT" => $options["PREVIEW_TEXT"],
"WF_COMMENTS" => (!empty($options["WF_COMMENTS"]) ? $options["WF_COMMENTS"] : GetMessage("WD_FILE_IS_CREATED")),
"PROPERTY_VALUES" => array(
$this->file_prop => $arFile,
"WEBDAV_SIZE" => $arFile['size'],
static::PROPERTY_VERSION => 1,
),
);
if (isset($options['USER_FIELDS']))
$arr["USER_FIELDS"] = $options['USER_FIELDS'];
if (
($this->workflow == 'workflow')
&& isset($options["WF_STATUS_ID"])
)
$arr["WF_STATUS_ID"] = $options["WF_STATUS_ID"];
else
$arr["WF_STATUS_ID"] = 1;
if ($this->workflow == 'bizproc')
$arr["BP_PUBLISHED"] = (($this->wfParams["AUTO_PUBLISH"] == "Y") || $bDropped) ? "Y" : "N";
$options["ELEMENT_ID"] = $ID = $this->_ib_elm_add(
$arr,
(($_SERVER['REQUEST_METHOD'] != "LOCK" || $this->workflow != "workflow") && $this->workflow != false),
($arFile['size'] > 0),
false
);
if (!$ID)
{
return false;
}
else
{
$this->arParams["changed_element_id"] = $ID;
}
}
else // update
{
$arUpdateType = array();
$arr = array(
"MODIFIED_BY" => $GLOBALS["USER"]->GetID(),
"WF_COMMENTS" => GetMessage("WD_FILE_IS_MODIFIED")
);
if (isset($options['USER_FIELDS']))
$arr["USER_FIELDS"] = $options['USER_FIELDS'];
if (!empty($arFile))
{
$arr["PROPERTY_VALUES"] = array(
$this->file_prop => $arFile,
"WEBDAV_SIZE" => $arFile['size'],
);
$arUpdateType[] = 'FILE';
}
$element = $this->GetObject(array('element_id' => $options["ELEMENT_ID"]));
foreach (array("NAME", "TAGS", "PREVIEW_TEXT", "ACTIVE", "IBLOCK_SECTION_ID", "WF_COMMENTS", "WF_STATUS_ID") as $key)
{
if (is_set($options, $key))
{
$arr[$key] = $options[$key];
if (
isset($element['element_array'][$key])
&& ($element['element_array'][$key] != $options[$key])
)
{
$arUpdateType[] = $key;
}
}
}
//if ($arFile["size"] <= 0)
//unset($arr["PROPERTY_VALUES"]);
if (is_set($arr, "PREVIEW_TEXT"))
$arr["PREVIEW_TEXT_TYPE"] = 'html';
if (is_set($arr, "IBLOCK_SECTION_ID"))
{
$arr["IBLOCK_SECTION_ID"] = intval($arr["IBLOCK_SECTION_ID"]);
if ($this->arRootSection && $arr["IBLOCK_SECTION_ID"] <= 0)
$arr["IBLOCK_SECTION_ID"] = $this->arRootSection["ID"];
}
if ($_SERVER['REQUEST_METHOD'] != "LOCK" && !$options["clone"] &&
($this->workflow == 'bizproc_limited' || $this->workflow == 'bizproc'))
{
if(empty($arr["PROPERTY_VALUES"]))
{
$arr["PROPERTY_VALUES"] = array();
}
if(empty($element['element_array']['PROPERTY_' . static::PROPERTY_VERSION . '_VALUE']))
{
//+1 - version from HEAD
$countAlreadyInHistory = (int)$this->countHistoryDocumentByFileId($options["ELEMENT_ID"]) + 1;
}
else
{
$countAlreadyInHistory = $element['element_array']['PROPERTY_' . static::PROPERTY_VERSION . '_VALUE'];
}
$arr["PROPERTY_VALUES"][static::PROPERTY_VERSION] = $countAlreadyInHistory + 1;
$options['THROUGH_VERSION'] = $arr["PROPERTY_VALUES"][static::PROPERTY_VERSION];
$this->AddDocumentToHistory($ID, $options['FILE_NAME']);
}
$res = $this->_ib_elm_update($options["ELEMENT_ID"], $arr, ($this->workflow == "workflow"));
if(!$res)
{
return false;
}
$ID = $options["ELEMENT_ID"];
$this->_onEvent('Update', $ID, 'FILE', array('UPDATE_TYPE' => $arUpdateType));
if ($this->workflow == 'bizproc' && is_set($arr, "IBLOCK_SECTION_ID"))
{
$db_res2 = CIBlockElement::GetList(array(), array("WF_PARENT_ELEMENT_ID" => $options["ELEMENT_ID"], "SHOW_HISTORY" => "Y"), false, false, array("ID"));
if ($db_res2 && $res2 = $db_res2->Fetch())
{
do
{
$ar = array("IBLOCK_SECTION_ID" => $arr["IBLOCK_SECTION_ID"]);
$res = $this->_ib_elm_update($res2["ID"], $ar, false);
} while ($res2 = $db_res2->Fetch());
}
}
}
$documentId = $this->wfParams["DOCUMENT_TYPE"];
$documentId[2] = $ID;
if (
($this->workflow == 'bizproc')
&& (! $bDropped)
)
{
if (!CIBlockDocumentWebdav::StartWorkflowsExecuting($documentId, $arDocumentStates, $arBizProcParametersValues, $options["arUserGroups"], $arErrors, $this->wfParams))
{
$e = new CAdminException($arErrors);
$this->LAST_ERROR = $e->GetString();
}
}
}
$this->CACHE['CWebDavIblock::GetObject'] = array();
return true;
}