- Модуль: webdav
- Путь к файлу: ~/bitrix/modules/webdav/classes/iblock.php
- Класс: CWebDavIblock
- Вызов: CWebDavIblock::_set_lock
function _set_lock(&$options, $op)
{
$lock = ($op == 'LOCK');
$is_dir = false;
$ID = 0;
$bFirstElement = false;
$arProps = $this->_get_lock($options);
if(!$this->CheckWebRights("", array('action' => 'lock', 'arElement' => $this->arParams)))
return $this->ThrowAccessDenied(__LINE__);
if (!is_array($arProps)) // arProps == 404 not found
{
if ($lock && $this->arParams['not_found'] === true) // create file by lock
{
if (!$this->CheckName($this->arParams["basename"]))
{
return "400 bad request";
}
elseif ($this->check_creator && $this->arParams["is_file"] === true &&
$this->arParams["element_array"]["CREATED_BY"] != $GLOBALS["USER"]->GetID())
{
return $this->ThrowAccessDenied(__LINE__);
}
elseif ($this->arParams["parent_id"] !== false)
{
$options1 = array(
'path' => $options["path"],
'content_length' => 0,
'content_type' => "",
'WF_COMMENTS' => GetMessage("WD_FILE_IS_CREATED_BY_LOCK"));
$stat = $this->PUT($options1);
if ($stat === false)
{
return $this->ThrowAccessDenied(__LINE__);
}
elseif (is_string($stat))
{
return $stat;
}
else
{
if (
is_resource($stat)
&& get_resource_type($stat) == 'stream'
)
fclose($stat);
if (
!$this->CheckWebRights(
"",
array(
"action" => "create",
"arElement" => $this->arParams
)
)
)
return $this->ThrowAccessDenied(__LINE__);
$this->put_commit($options1);
}
$ID = intval($options1["ELEMENT_ID"]);
if ($ID <= 0)
return "409 Conflict";
else
return "200 OK";
}
else
{
return $arProps; // 404 not found
}
}
return $arProps; // error in _get_lock
}
$ID = $this->arParams['item_id'];
$is_dir = $this->arParams["is_dir"];
if ($lock)
{
if ($is_dir && !empty($options["depth"]))
{
return "409 Conflict";
}
elseif (!$is_dir && CIBlockElement::WF_IsLocked($ID, $locked_by, $date_lock))
{
return false;
}
$options["timeout"] = time() + 300; // 5min. hardcoded
if (isset($options["update"]) )
{
$token = $options["update"];
$arProps["LOCK"] = (is_array($arProps["LOCK"]) ? $arProps["LOCK"] : array());
if (array_key_exists($token, $arProps["LOCK"]) && $arProps["LOCK"][$token]["exclusivelock"] <> '')
{
$arProps["LOCK"][$token]["expires"] = $options["timeout"];
$arProps["LOCK"][$token]["modified"] = time();
if (array_key_exists("owner", $arProps["LOCK"][$token]))
{
$options["owner"] = $arProps["LOCK"][$token]["owner"];
}
$options["scope"] = $arProps["LOCK"][$token]["exclusivelock"] ? "exclusive" : "shared";
$options["type"] = $arProps["LOCK"][$token]["exclusivelock"] ? "write" : "read";
if ($bFirstElement)
{
$arProps["FIRST"] = "Y";
}
CIBlockElement::SetPropertyValues($ID, $this->IBLOCK_ID, serialize($arProps), "WEBDAV_INFO");
CIBlockElement::WF_Lock($ID);
$this->_onEvent('Lock', $ID);
return true;
}
else
{
return false;
}
}
$arProps["LOCK"][$options["locktoken"]] = array(
"created" => time(),
"modified" => time(),
"owner" => $options["owner"],
"expires" => $options["timeout"],
"locktoken" => $options["locktoken"],
"exclusivelock" => ($options["scope"] === "exclusive" ? 1 : 0)
);
}
else
{
if (!empty($options["token"]))
{
$token = $options["token"];
unset($arProps["LOCK"][$token]);
}
else
{
unset($arProps["LOCK"]);
}
if ($this->workflow == 'bizproc'
&& $GLOBALS['USER']->CanDoOperation('webdav_change_settings')) // admin can remove bizproc locks
{
$arDocId = $this->wfParams["DOCUMENT_TYPE"];
$arDocId[2] = $ID;
$arStates = CBPDocument::GetDocumentStates($this->wfParams["DOCUMENT_TYPE"], $arDocId);
foreach ($arStates as $workflowId => $arState)
{
CIBlockDocumentWebdav::UnlockDocument($ID, $workflowId);
}
}
}
if ($is_dir)
{
$se = new CIBlockSection();
$x = $se->Update($ID, array("DESCRIPTION" => serialize($arProps)));
}
else
{
if ($lock && $bFirstElement)
$arProps["FIRST"] = "Y";
CIBlockElement::SetPropertyValues($ID, $this->IBLOCK_ID, serialize($arProps), "WEBDAV_INFO");
if ($lock)
CIBlockElement::WF_Lock($ID, ($this->workflow == "workflow"));
else
CIBlockElement::WF_UnLock($ID, ($this->workflow == "workflow"));
$this->_onEvent(($lock ? 'Lock' : 'Unlock'), $ID);
$x = true;
}
return $x ? ($lock ? "200 OK" : "204 No Content") : "409 Conflict";
}