private static function needProxyToDiskByDocProp(array $documentProperties, array $arDocumentFields) { if (!(\Bitrix\Main\Config\Option::get('disk', 'successfully_converted', false) && CModule::includeModule('disk'))) { return false; } if (empty($arDocumentFields['ID'])) { return false; } return File::load(array('XML_ID' => $arDocumentFields['ID'])); }
protected function processActionUploadFile($hash, &$file, &$package, &$upload, &$error) { $update = isset($_POST["REPLACE_FILE"]) && is_array($_POST["REPLACE_FILE"]) && in_array($file["id"], $_POST["REPLACE_FILE"]); /** @var Folder $folder */ $folder = Folder::loadById((int) $_POST['targetFolderId'], array('STORAGE')); if (!$folder) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_FILE_UPLOAD_ERROR_COULD_NOT_FIND_FOLDER'), self::ERROR_COULD_NOT_FIND_FOLDER))); $error = implode(" ", $this->errorCollection->toArray()); return true; } else { if ($update) { /** @var File $fileModel */ $fileModel = File::load(array('NAME' => $file['name'], 'PARENT_ID' => $folder->getRealObjectId())); if (!$fileModel) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_FILE_UPLOAD_ERROR_COULD_NOT_FIND_FILE'), self::ERROR_COULD_NOT_FIND_FILE))); } else { if (!$fileModel->canUpdate($fileModel->getStorage()->getCurrentUserSecurityContext())) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_FILE_UPLOAD_ERROR_BAD_RIGHTS'), self::ERROR_BAD_RIGHTS))); } else { if (!$fileModel->uploadVersion($file["files"]["default"], $this->getUser()->getId())) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_FILE_UPLOAD_ERROR_COULD_UPLOAD_VERSION'), self::ERROR_COULD_UPLOAD_VERSION))); } } } } elseif (!$folder->canAdd($folder->getStorage()->getCurrentUserSecurityContext())) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_FILE_UPLOAD_ERROR_BAD_RIGHTS'), self::ERROR_BAD_RIGHTS))); } else { $fileModel = $folder->uploadFile($file["files"]["default"], array('NAME' => $file['name'], 'CREATED_BY' => $this->getUser()->getId())); if (!$fileModel) { $this->errorCollection->add($folder->getErrors()); } if ($fileModel && isset($_POST['checkBp'])) { $workflowParameters = array(); $search = 'bizproc'; foreach ($_POST as $idParameter => $valueParameter) { $res = strpos($idParameter, $search); if ($res === 0) { $workflowParameters[$idParameter] = $valueParameter; } } $autoExecute = intval($_POST['autoExecute']); \Bitrix\Disk\BizProcDocument::startAutoBizProc($fileModel->getStorageId(), $fileModel->getId(), $autoExecute, $workflowParameters); } } } $error = implode(" ", $folder->getErrors() + $this->errorCollection->toArray()); if ($folder->getErrorByCode($folder::ERROR_NON_UNIQUE_NAME)) { $file["isNotUnique"] = true; } return empty($error); }
public static function GetLocalDiskMolel() { if (!self::Enabled()) { return false; } $storageModel = \Bitrix\Disk\Driver::getInstance()->getStorageByUserId(self::GetUserId()); if (!$storageModel) { return false; } $folderModel = \Bitrix\Disk\Folder::load(array('STORAGE_ID' => $storageModel->getId(), 'PARENT_ID' => $storageModel->getRootObjectId(), 'TYPE' => \Bitrix\Disk\Internals\ObjectTable::TYPE_FOLDER, 'CODE' => 'IM_SAVED')); if (!$folderModel) { $folderName = GetMessage(IsModuleInstalled('intranet') ? 'IM_DISK_LOCAL_FOLDER_B24_TITLE' : 'IM_DISK_LOCAL_FOLDER_TITLE'); $folderModel = $storageModel->addFolder(array('NAME' => $folderName, 'CREATED_BY' => self::GetUserId(), 'CODE' => 'IM_SAVED')); if (!$folderModel) { if ($storageModel->getErrorByCode(\Bitrix\Disk\Folder::ERROR_NON_UNIQUE_NAME)) { $badFileModel = \Bitrix\Disk\File::load(array('STORAGE_ID' => $storageModel->getId(), 'TYPE' => \Bitrix\Disk\Internals\ObjectTable::TYPE_FILE, 'NAME' => $folderName)); if ($badFileModel) { $badFileModel->delete(\Bitrix\Disk\SystemUser::SYSTEM_USER_ID); $folderModel = $storageModel->addFolder(array('NAME' => $folderName, 'CREATED_BY' => self::GetUserId(), 'CODE' => 'IM_SAVED')); } else { $folderModel = \Bitrix\Disk\Folder::load(array('STORAGE_ID' => $storageModel->getId(), 'PARENT_ID' => $storageModel->getRootObjectId(), 'TYPE' => \Bitrix\Disk\Internals\ObjectTable::TYPE_FOLDER, 'NAME' => $folderName)); $folderModel->changeCode('IM_SAVED'); } } else { $folderModel = $storageModel->addFolder(array('NAME' => $folderName, 'CREATED_BY' => self::GetUserId(), 'CODE' => 'IM_SAVED'), array(), true); } } } return $folderModel; }
return 0; } } else { $APPLICATION->RestartBuffer(); // ajax usage only while (ob_end_clean()) { true; } ShowError(GetMessage("WD_ERROR_ELEMENT_NOT_FOUND")); die; } } } if (\Bitrix\Main\Config\Option::get('disk', 'successfully_converted', false) && CModule::includeModule('disk')) { /** @var \Bitrix\Disk\File $diskFile */ $diskFile = \Bitrix\Disk\File::load(array('XML_ID' => $arResult['ELEMENT']['ID']), array('STORAGE')); if ($diskFile) { LocalRedirect(\Bitrix\Disk\Driver::getInstance()->getUrlManager()->getPathFileDetail($diskFile)); } } $ob->_get_file_info_arr($arResult["ELEMENT"]); $arResult["WRITEABLE"] = $arResult['ELEMENT']['SHOW']['EDIT']; if (in_array($arParams["ACTION"], array("EDIT", "PULL")) && $arParams["DOCUMENT_LOCK"] != "N") { CIBlockElement::WF_Lock($arParams["ELEMENT_ID"], $ob->workflow == "workflow"); /** * This part of code is necessary because info about element is got * already but information about locking is absent. We can not lock * element until check all rulles. */ $arResult["ELEMENT"]["LOCK_STATUS"] = CIBlockElement::WF_GetLockStatus($arParams["ELEMENT_ID"], $arResult['ELEMENT']['WF_LOCKED_BY'], $arResult['ELEMENT']['WF_DATE_LOCK']); }
return false; } } elseif ($componentPage == "section_edit" && isset($_REQUEST["use_light_view"]) && strToUpper($_REQUEST["use_light_view"]) == "Y") { $componentPage = "section_edit_simple"; } elseif ($componentPage == "element_upload" && isset($_REQUEST["use_light_view"]) && strToUpper($_REQUEST["use_light_view"]) == "Y") { $componentPage = "element_upload_simple"; } elseif ($componentPage == "sections") { $arResult["VARIABLES"]["PATH"] = $ob->_path; if (!empty($ob->_path)) { $ob->IsDir(array('check_permissions' => false)); if ($ob->arParams["not_found"]) { $ob->SetStatus('404 not found'); } elseif (!empty($ob->arParams['file_name'])) { if (\Bitrix\Main\Config\Option::get('disk', 'successfully_converted', false) && CModule::includeModule('disk')) { /** @var \Bitrix\Disk\File $diskFile */ $diskFile = \Bitrix\Disk\File::load(array('XML_ID' => $ob->arParams['element_array']['ID']), array('STORAGE')); if ($diskFile && $diskFile->getStorage()) { if ($diskFile->canRead($diskFile->getStorage()->getCurrentUserSecurityContext())) { CFile::viewByUser($diskFile->getFile(), array("force_download" => false)); } } } $APPLICATION->RestartBuffer(); $ob->base_GET(); die; } if (!empty($needToRedirectPageUrl)) { LocalRedirect($needToRedirectPageUrl); } $arResult["VARIABLES"]["SECTION_ID"] = $ob->arParams["item_id"]; }
/** * @param array $arResult From PUT(&$arResult) * @return string String like '204 No Content', '403 Forbidden', '404 Not Found' or file pointer if we have to load file */ protected function PUT(&$arResult) { /** @var CDavRequest $request */ $request = $this->request; //todo откуда мы узнаем хранилище относительно которого вести поиск? list($storage, $path) = $this->parsePath($request->getPath()); if (!$storage) { return '404 Not Found'; } $withoutFilename = explode('/', $path); $filename = array_pop($withoutFilename); $folderId = Driver::getInstance()->getUrlManager()->resolveFolderIdFromPath($storage, implode('/', $withoutFilename)); if (!$folderId) { return '404 Not Found'; //"409 Conflict"? } /** @var Folder $folder */ $folder = Folder::loadById($folderId); if (!$folder) { return '404 Not Found'; //"409 Conflict"? } /** @var File $file */ $file = File::load(array('NAME' => $filename, 'PARENT_ID' => $folder->getRealObjectId())); $securityContext = $folder->getStorage()->getCurrentUserSecurityContext(); if (!$file) { if (!$folder->canAdd($securityContext)) { return '403 Forbidden'; } $tmpFile = CTempFile::GetFileName($filename); CheckDirPath($tmpFile); $fp = fopen($tmpFile, "w"); $arResult['new'] = true; $arResult['filename'] = $filename; $arResult['tmpFile'] = $tmpFile; $arResult['targetFolder'] = $folder; return $fp; } $arResult['new'] = false; if (!$file->canUpdate($securityContext)) { return '403 Forbidden'; } $tmpFile = CTempFile::GetFileName($filename); CheckDirPath($tmpFile); $fp = fopen($tmpFile, "w"); $arResult['tmpFile'] = $tmpFile; $arResult['targetFolder'] = $folder; $arResult['file'] = $file; return $fp; }