Пример #1
0
 /**
  * @return EditSession|null
  */
 protected function getOnlineEditSessionForFile()
 {
     if ($this->isSpecificVersion()) {
         return null;
     }
     return EditSession::load(array('OBJECT_ID' => $this->file->getId(), 'VERSION_ID' => null, 'IS_EXCLUSIVE' => false));
 }
Пример #2
0
 protected function processActionCopyToMe()
 {
     $userStorage = Driver::getInstance()->getStorageByUserId($this->getUser()->getId());
     if (!$userStorage) {
         $this->errorCollection->add(array(new Error("Could not find storage for current user")));
         $this->sendJsonErrorResponse();
     }
     $folder = $userStorage->getFolderForSavedFiles($this->getUser()->getId());
     if (!$folder) {
         $this->errorCollection->add(array(new Error("Could not find folder for created files")));
         $this->sendJsonErrorResponse();
     }
     $newFile = $this->file->copyTo($folder, $this->getUser()->getId(), true);
     if (!$newFile) {
         $this->errorCollection->add(array(new Error("Could not copy file to storage for current user")));
         $this->sendJsonErrorResponse();
     }
     $crumbs = array();
     foreach ($newFile->getParents(Driver::getInstance()->getFakeSecurityContext()) as $parent) {
         if ($parent->getId() == $userStorage->getRootObjectId()) {
             continue;
         }
         $crumbs[] = $parent->getName();
     }
     unset($parent);
     $viewUrl = Driver::getInstance()->getUrlManager()->encodeUrn($userStorage->getProxyType()->getStorageBaseUrl() . 'path/' . implode('/', $crumbs));
     $this->sendJsonSuccessResponse(array('newId' => $newFile->getId(), 'viewUrl' => $viewUrl . '#hl-' . $newFile->getId()));
 }
 public static function getDocument($documentId)
 {
     $documentId = (int) $documentId;
     if ($documentId <= 0) {
         throw new CBPArgumentNullException("documentId");
     }
     $file = File::loadById($documentId);
     if (!$file) {
         return null;
     }
     $ufFields = Driver::getInstance()->getUserFieldManager()->getFieldsForObject($file);
     $ufFileRow = array();
     if (!empty($ufFields)) {
         foreach ($ufFields as $fieldKey => $fieldData) {
             $ufFileRow[$fieldKey] = $fieldData['VALUE'];
             $ufFileRow[$fieldData['XML_ID']] = $fieldData['VALUE'];
         }
     }
     $fileRow = File::getList(array('with' => array('CREATE_USER', 'UPDATE_USER', 'DELETE_USER'), 'filter' => array('ID' => $documentId)))->fetch();
     if (!$fileRow) {
         return null;
     }
     if (empty($fileRow["CODE"])) {
         $fileRow["CODE"] = Loc::getMessage("DISK_BZ_D_NAME_NOT_CODE");
     }
     return array_merge(array("ID" => $fileRow["ID"], "CREATE_TIME" => $fileRow["CREATE_TIME"], "CREATED_BY" => $fileRow["CREATED_BY"], "CREATED_BY_PRINTABLE" => $fileRow['CREATE_USERREF_NAME'] . ' ' . $fileRow['CREATE_USERREF_LAST_NAME'], "UPDATE_TIME" => $fileRow["UPDATE_TIME"], "UPDATED_BY" => $fileRow["UPDATED_BY"], "UPDATED_BY_PRINTABLE" => $fileRow['UPDATE_USERREF_NAME'] . ' ' . $fileRow['UPDATE_USERREF_LAST_NAME'], "DELETE_TIME" => $fileRow["DELETE_TIME"], "DELETED_BY" => $fileRow["DELETED_BY"], "DELETED_BY_PRINTABLE" => $fileRow['DELETE_USERREF_NAME'] . ' ' . $fileRow['DELETE_USERREF_LAST_NAME'], "STORAGE_ID" => $fileRow["STORAGE_ID"], "NAME" => $fileRow["NAME"], "SIZE" => $fileRow["SIZE"], "CODE" => $fileRow["CODE"], "TIMESTAMP_X" => $fileRow["UPDATE_TIME"], "MODIFIED_BY" => $fileRow["CREATED_BY"], "MODIFIED_BY_PRINTABLE" => $fileRow['UPDATE_USERREF_NAME'] . ' ' . $fileRow['UPDATE_USERREF_LAST_NAME'], "DATE_CREATE" => $fileRow["CREATE_TIME"], "FILE_SIZE" => $fileRow["SIZE"]), $ufFileRow);
 }
Пример #4
0
 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']));
 }
Пример #5
0
 /**
  * @param bool $getFromFileIfPossible
  * @return string|null
  */
 public function getSrc($getFromFileIfPossible = true)
 {
     if (!$this->src && $getFromFileIfPossible && $this->file instanceof File) {
         $fileArray = \CFile::makeFileArray($this->file->getFileId());
         if (!is_array($fileArray)) {
             return null;
         }
         $this->src = $fileArray['tmp_name'];
     }
     return $this->src;
 }
Пример #6
0
 /**
  * Returns true if current user has read access to the file.
  * @param array $params Allowed keys: fileId.
  * @param int $userId Current user's id.
  * @return bool
  */
 public static function checkUserReadAccess(array $params, $userId)
 {
     $result = false;
     $fileId = $params['fileId'];
     if ($file = \Bitrix\Disk\File::loadById($fileId)) {
         $securityContext = $file->getStorage()->getSecurityContext($userId);
         if ($file->canRead($securityContext)) {
             $result = true;
         }
     }
     return $result;
 }
 /**
  * @param FieldType $fieldType Document field object.
  * @param mixed $value Field value.
  * @param string $toTypeClass Type class manager name.
  * @return null|mixed
  */
 public static function convertTo(FieldType $fieldType, $value, $toTypeClass)
 {
     if (is_array($value) && isset($value['VALUE'])) {
         $value = $value['VALUE'];
     }
     $value = (int) $value;
     /** @var Base $toTypeClass */
     $type = $toTypeClass::getType();
     switch ($type) {
         case FieldType::FILE:
             $diskFile = File::getById($value);
             $value = $diskFile ? $diskFile->getFileId() : null;
             break;
         default:
             $value = null;
     }
     return $value;
 }
Пример #8
0
 protected function processActionOpenFileDetail()
 {
     if (!$this->checkRequiredGetParams(array('fileId'))) {
         $this->sendJsonErrorResponse();
     }
     /** @var File $file */
     $file = File::loadById((int) $this->request->getQuery('fileId'), array('STORAGE'));
     if (!$file) {
         $this->errorCollection->addOne(new Error('Could not find file', self::ERROR_COULD_NOT_FIND_FILE));
         $this->sendJsonErrorResponse();
     }
     if (!$file->canRead($file->getStorage()->getCurrentUserSecurityContext())) {
         $this->errorCollection->addOne(new Error('Could not find file', self::ERROR_COULD_NOT_READ_FILE));
         $this->sendJsonErrorResponse();
     }
     $urlManager = Driver::getInstance()->getUrlManager();
     LocalRedirect($urlManager->encodeUrn($urlManager->getPathFileDetail($file)));
 }
 protected function processActionCommit()
 {
     $this->checkRequiredFilesParams(array('file'));
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     $this->checkUpdatePermissions();
     //todo fix Cherezov. Ban encoding 1251
     $fileArray = $this->request->getFile('file');
     $fileArray['name'] = $this->file->getName();
     $userId = $this->getUser()->getId();
     if (!$this->file->uploadVersion($fileArray, $userId)) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_ADD_VERSION'), self::ERROR_COULD_NOT_ADD_VERSION)));
         $this->sendJsonErrorResponse();
     }
     Driver::getInstance()->sendEvent($userId, 'live', array('objectId' => $this->file->getId(), 'action' => 'commit'));
     $this->sendJsonSuccessResponse();
 }
Пример #10
0
 private function getFileAndExternalLink()
 {
     if (!$this->checkRequiredPostParams(array('externalId', 'objectId'))) {
         $this->sendJsonErrorResponse();
     }
     /** @var File $file */
     $file = File::loadById((int) $this->request->getPost('objectId'), array('STORAGE'));
     if (!$file) {
         $this->errorCollection->addOne(new Error(Loc::getMessage('DISK_BREADCRUMBS_ERROR_COULD_NOT_FIND_OBJECT'), self::ERROR_COULD_NOT_FIND_OBJECT));
         $this->sendJsonErrorResponse();
     }
     $securityContext = $file->getStorage()->getCurrentUserSecurityContext();
     if (!$file->canRead($securityContext)) {
         $this->sendJsonAccessDeniedResponse();
     }
     $extLinks = $file->getExternalLinks(array('filter' => array('ID' => (int) $this->request->getPost('externalId'), 'OBJECT_ID' => $file->getId(), 'CREATED_BY' => $this->getUser()->getId(), 'TYPE' => \Bitrix\Disk\Internals\ExternalLinkTable::TYPE_MANUAL, 'IS_EXPIRED' => false), 'limit' => 1));
     return array($file, array_pop($extLinks));
 }
Пример #11
0
 protected function processActionCopyToMe()
 {
     $userStorage = Driver::getInstance()->getStorageByUserId($this->getUser()->getId());
     if (!$userStorage) {
         $this->errorCollection->addOne(new Error('Could not find storage for current user'));
         $this->sendJsonErrorResponse();
     }
     $folder = $userStorage->getFolderForSavedFiles();
     if (!$folder) {
         $this->errorCollection->addOne(new Error('Could not find folder for created files'));
         $this->sendJsonErrorResponse();
     }
     $newFile = $this->file->copyTo($folder, $this->getUser()->getId(), true);
     if (!$newFile) {
         $this->errorCollection->addOne(new Error('Could not copy file to storage for current user'));
         $this->sendJsonErrorResponse();
     }
     $urlManager = Driver::getInstance()->getUrlManager();
     $viewUrl = $urlManager->encodeUrn($urlManager->getUrlFocusController('showObjectInGrid', array('objectId' => $newFile->getId())));
     $runViewerUrl = $urlManager->encodeUrn($urlManager->getUrlFocusController('showObjectInGrid', array('objectId' => $newFile->getId(), 'cmd' => 'show')));
     $this->sendJsonSuccessResponse(array('newId' => $newFile->getId(), 'viewUrl' => $viewUrl, 'runViewUrl' => $runViewerUrl));
 }
Пример #12
0
 /**
  * Called before record transformed for log writing.
  *
  * @param array &$record Database record.
  *
  * @return void
  */
 public function beforeLogFormat(array &$record)
 {
     global $USER;
     if ($record["PARAM_NAME"] !== "FILE_ID" || $record["PARAM_VALUE"] <= 0) {
         return;
     }
     if (!\Bitrix\Main\Loader::includeModule('disk')) {
         AddMessage2Log('MessageParamHandler::beforeLogFormat: failed to load disk module.');
         return;
     }
     if (!is_object($USER) || $USER->GetID() < 0) {
         AddMessage2Log('MessageParamHandler::beforeLogFormat: no user provided.');
         return;
     }
     /** @var \Bitrix\Disk\File $file */
     $fileId = $record["PARAM_VALUE"];
     $userId = $USER->GetID();
     $file = \Bitrix\Disk\File::loadById($fileId);
     if (!$file) {
         AddMessage2Log('MessageParamHandler::beforeLogFormat: file (' . $fileId . ') not found for user (' . $userId . ').');
         return;
     }
     $externalLink = $file->addExternalLink(array('CREATED_BY' => $userId, 'TYPE' => \Bitrix\Disk\Internals\ExternalLinkTable::TYPE_MANUAL));
     if (!$externalLink) {
         AddMessage2Log('MessageParamHandler::beforeLogFormat: failed to get external link for file (' . $fileId . ').');
         AddMessage2Log($file->getErrors());
         return;
     }
     $url = \Bitrix\Disk\Driver::getInstance()->getUrlManager()->getUrlExternalLink(array('hash' => $externalLink->getHash(), 'action' => 'default'), true);
     $fileName = $file->getName();
     $fileSize = $file->getSize();
     $attach = new \CIMMessageParamAttach(null, \CIMMessageParamAttach::CHAT);
     $attach->AddFiles(array(array("NAME" => $fileName, "LINK" => $url, "SIZE" => $fileSize)));
     $record["PARAM_NAME"] = 'ATTACH';
     $record["PARAM_VALUE"] = 1;
     $record["PARAM_JSON"] = $attach->GetJSON();
 }
Пример #13
0
 /**
  * Gets url to show file.
  * @param File  $file Target file.
  * @param array $params Parameters to add in query.
  * @param bool  $absolute Generate absolute url with host url.
  * @return string
  */
 public function getUrlForShowFile(File $file, array $params = array(), $absolute = false)
 {
     if (isset($params['width']) && isset($params['height'])) {
         $params['signature'] = ParameterSigner::getImageSignature($file->getId(), $params['width'], $params['height']);
     }
     return $this->getUrlDownloadController('showFile', array_merge($params, array('fileId' => $file->getId(), 'filename' => $file->getName())), $absolute);
 }
Пример #14
0
 private function getFileContent(File $file)
 {
     static $maxFileSize = null;
     if (!isset($maxFileSize)) {
         $maxFileSize = Option::get("search", "max_file_size", 0) * 1024;
     }
     $searchData = '';
     $searchData .= strip_tags($file->getName()) . "\r\n";
     if ($maxFileSize > 0 && $file->getSize() > $maxFileSize) {
         return '';
     }
     $searchDataFile = array();
     $fileArray = CFile::makeFileArray($file->getFileId());
     if ($fileArray && $fileArray['tmp_name']) {
         $fileAbsPath = \CBXVirtualIo::getInstance()->getLogicalName($fileArray['tmp_name']);
         foreach (GetModuleEvents('search', 'OnSearchGetFileContent', true) as $event) {
             if ($searchDataFile = executeModuleEventEx($event, array($fileAbsPath, getFileExtension($fileArray['name'])))) {
                 break;
             }
         }
         return is_array($searchDataFile) ? $searchData . "\r\n" . $searchDataFile['CONTENT'] : $searchData;
     }
     return $searchData;
 }
Пример #15
0
 /**
  * Returns the list attributes which is connected with another models.
  * @return array
  */
 public static function getMapReferenceAttributes()
 {
     return array('CREATE_USER' => array('class' => User::className(), 'select' => User::getFieldsForSelect()), 'FILE' => array('orm_alias' => 'OBJECT', 'class' => File::className()), 'VERSION' => Version::className());
 }
Пример #16
0
 private function loadFilesData()
 {
     if (empty($this->arParams['PARAMS']['arUserField'])) {
         return array();
     }
     $userId = $this->getUser()->getId();
     $values = $this->arParams['PARAMS']['arUserField']['VALUE'];
     if (!is_array($this->arParams['PARAMS']['arUserField']['VALUE'])) {
         $values = array($values);
     }
     $files = array();
     $driver = \Bitrix\Disk\Driver::getInstance();
     $urlManager = $driver->getUrlManager();
     $userFieldManager = $driver->getUserFieldManager();
     $userFieldManager->loadBatchAttachedObject($values);
     foreach ($values as $id) {
         $attachedModel = null;
         list($type, $realValue) = FileUserType::detectType($id);
         if ($realValue <= 0) {
             continue;
         } elseif ($type == FileUserType::TYPE_NEW_OBJECT) {
             /** @var File $fileModel */
             $fileModel = File::loadById($realValue);
             if (!$fileModel || !$fileModel->canRead($fileModel->getStorage()->getCurrentUserSecurityContext())) {
                 continue;
             }
         } else {
             /** @var \Bitrix\Disk\AttachedObject $attachedModel */
             $attachedModel = $userFieldManager->getAttachedObjectById($realValue);
             if (!$attachedModel) {
                 continue;
             }
             if (!$this->editMode) {
                 $attachedModel->setOperableEntity(array('ENTITY_ID' => $this->arParams['PARAMS']['arUserField']['ENTITY_ID'], 'ENTITY_VALUE_ID' => $this->arParams['PARAMS']['arUserField']['ENTITY_VALUE_ID']));
             }
             /** @var File $fileModel */
             $fileModel = $attachedModel->getFile();
         }
         $name = $fileModel->getName();
         $data = array('ID' => $id, 'NAME' => $name, 'CONVERT_EXTENSION' => DocumentHandler::isNeedConvertExtension($fileModel->getExtension()), 'EDITABLE' => DocumentHandler::isEditable($fileModel->getExtension()), 'CAN_UPDATE' => $attachedModel ? $attachedModel->canUpdate($userId) : $fileModel->canUpdate($fileModel->getStorage()->getCurrentUserSecurityContext()), 'FROM_EXTERNAL_SYSTEM' => $fileModel->getContentProvider() && $fileModel->getCreatedBy() == $userId, 'EXTENSION' => $fileModel->getExtension(), 'SIZE' => \CFile::formatSize($fileModel->getSize()), 'XML_ID' => $fileModel->getXmlId(), 'FILE_ID' => $fileModel->getId(), 'VIEW_URL' => $urlManager->getUrlToShowAttachedFileByService($id, 'gvdrive'), 'EDIT_URL' => $urlManager->getUrlToStartEditUfFileByService($id, 'gdrive'), 'DOWNLOAD_URL' => $urlManager->getUrlUfController('download', array('attachedId' => $id)), 'COPY_TO_ME_URL' => $urlManager->getUrlUfController('copyToMe', array('attachedId' => $id)), 'DELETE_URL' => "");
         if (\Bitrix\Disk\TypeFile::isImage($fileModel)) {
             $this->arParams['PARAMS']['THUMB_SIZE'] = $this->arParams['PARAMS']['THUMB_SIZE'] > 0 ? $this->arParams['PARAMS']['THUMB_SIZE'] : 100;
             $data["PREVIEW_URL"] = $attachedModel === null ? $urlManager->getUrlForShowFile($fileModel) : $urlManager->getUrlUfController('show', array('attachedId' => $id));
             $data["IMAGE"] = $fileModel->getFile();
         }
         if ($this->editMode) {
             $data['STORAGE'] = $fileModel->getStorage()->getProxyType()->getTitleForCurrentUser() . ' / ' . $fileModel->getParent()->getName();
         } else {
             $data['ATTRIBUTES_FOR_VIEWER'] = Ui\Viewer::getAttributesByAttachedObject($attachedModel, array('canUpdate' => $data['CAN_UPDATE'], 'canFakeUpdate' => true, 'showStorage' => false, 'externalId' => false, 'relativePath' => false));
         }
         $files[] = $data;
     }
     unset($id);
     return $files;
 }
Пример #17
0
 /**
  * Returns the list attributes which is connected with another models.
  * @return array
  */
 public static function getMapReferenceAttributes()
 {
     return array('OBJECT' => File::className(), 'VERSION' => Version::className());
 }
Пример #18
0
 private function notifySonetGroup(File $fileModel)
 {
     //todo create NotifyManager, which provides notify (not only group)
     if (!Loader::includeModule('socialnetwork')) {
         return;
     }
     $storage = $fileModel->getStorage();
     if (!$storage->getProxyType() instanceof Group) {
         return;
     }
     $groupId = (int) $storage->getEntityId();
     if ($groupId <= 0) {
         return;
     }
     $fileUrl = Driver::getInstance()->getUrlManager()->getPathFileDetail($fileModel);
     $fileCreatedBy = $fileModel->getCreatedBy();
     $fileName = $fileModel->getName();
     /** @noinspection PhpDynamicAsStaticMethodCallInspection */
     \CSocNetSubscription::notifyGroup(array('LOG_ID' => false, 'GROUP_ID' => array($groupId), 'NOTIFY_MESSAGE' => '', 'FROM_USER_ID' => $fileCreatedBy, 'URL' => $fileUrl, 'MESSAGE' => Loc::getMessage('DISK_FOLDER_MODEL_IM_NEW_FILE', array('#TITLE#' => '<a href="#URL#" class="bx-notifier-item-action">' . $fileName . '</a>')), 'MESSAGE_OUT' => Loc::getMessage('DISK_FOLDER_MODEL_IM_NEW_FILE', array('#TITLE#' => $fileName)) . ' (#URL#)', 'EXCLUDE_USERS' => array($fileCreatedBy)));
 }
Пример #19
0
 private function checkDownloadToken(File $file, $token)
 {
     return $_SESSION['DISK_PUBLIC_VERIFICATION'][$file->getId()] === $token;
 }
Пример #20
0
 public static function writeFileToResponse($fileID)
 {
     if (!Loader::includeModule('disk')) {
         return;
     }
     $file = File::loadById($fileID);
     if (!$file) {
         return;
     }
     $fileData = $file->getFile();
     if (!$fileData) {
         return;
     }
     \CFile::viewByUser($fileData, array('force_download' => true, 'cache_time' => 0, 'attachment_name' => $file->getName()));
 }
Пример #21
0
 /**
  * Returns list of recently files by user.
  * @param mixed|int|User|\CAllUser $user User.
  * @param array                    $filter Filter.
  * @return File[]
  * @internal
  */
 public function getFileModelListByUser($user, array $filter = array())
 {
     $userId = User::resolveUserId($user);
     if (!$userId) {
         $this->errorCollection->addOne(new Error('Could not get user id.'));
         return array();
     }
     $driver = Driver::getInstance();
     $storage = $driver->getStorageByUserId($userId);
     if (!$storage) {
         $this->errorCollection->addOne(new Error('Could not get storage by user id.'));
         return array();
     }
     if ($this->isFirstRun($userId)) {
         if (!$this->hasData($userId)) {
             $this->fixColdStart($userId);
         }
         $this->saveFirstRun($userId);
     }
     $securityContext = $storage->getCurrentUserSecurityContext();
     $parameters = array('filter' => array('RECENTLY_USED.USER_ID' => $userId, 'DELETED_TYPE' => ObjectTable::DELETED_TYPE_NONE, 'TYPE' => ObjectTable::TYPE_FILE), 'order' => array('RECENTLY_USED.CREATE_TIME' => 'DESC'), 'limit' => RecentlyUsedTable::MAX_COUNT_FOR_USER);
     if ($filter) {
         $parameters['filter'] = array_merge($parameters['filter'], $filter);
     }
     $parameters = $driver->getRightsManager()->addRightsCheck($securityContext, $parameters, array('ID', 'CREATED_BY'));
     return File::getModelList($parameters);
 }
Пример #22
0
 protected function processActionRenameFile()
 {
     $this->checkRequiredPostParams(array('newName', 'attachedId'));
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     list($type, $realValue) = FileUserType::detectType($this->request->getPost('attachedId'));
     if ($type == FileUserType::TYPE_NEW_OBJECT) {
         /** @var File $model */
         $model = File::loadById((int) $realValue, array('STORAGE'));
         if (!$model) {
             $this->errorCollection->add(array(new Error("Could not find file")));
             $this->sendJsonErrorResponse();
         }
         if (!$model->canRename($model->getStorage()->getCurrentUserSecurityContext())) {
             $this->errorCollection->add(array(new Error("Bad permission. Could not read this file")));
             $this->sendJsonErrorResponse();
         }
         $newName = Text::correctFilename($this->request->getPost('newName'));
         if (!$model->renameInternal($newName, true)) {
             $this->errorCollection->add($model->getErrors());
             $this->sendJsonErrorResponse();
         }
         Driver::getInstance()->getIndexManager()->indexFile($model);
         $this->sendJsonSuccessResponse(array('id' => $this->request->getPost('attachedId'), 'name' => $model->getName()));
     } else {
         $this->sendJsonErrorResponse();
     }
 }
Пример #23
0
                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']);
}
Пример #24
0
 /**
  * @param $id
  * @return File|null
  */
 protected static function getFileById($id)
 {
     if (!isset(self::$loadedFiles[$id])) {
         self::$loadedFiles[$id] = File::loadById($id, array('STORAGE'));
     }
     return self::$loadedFiles[$id];
 }
Пример #25
0
 public static function RemoveTmpFileAgent()
 {
     $storageModel = self::GetStorage();
     if (!$storageModel) {
         return "CIMDisk::RemoveTmpFileAgent();";
     }
     $date = new \Bitrix\Main\Type\DateTime();
     $date->add('YESTERDAY');
     $fileModels = \Bitrix\Disk\File::getModelList(array('filter' => array('GLOBAL_CONTENT_VERSION' => 1, 'STORAGE_ID' => $storageModel->getId(), '<CREATE_TIME' => $date), 'limit' => 200));
     foreach ($fileModels as $fileModel) {
         $fileModel->delete(\Bitrix\Disk\SystemUser::SYSTEM_USER_ID);
     }
     return "CIMDisk::RemoveTmpFileAgent();";
 }
Пример #26
0
 private function formatFileToResponse(File $file)
 {
     if (empty($file) || !$file->getName()) {
         return array();
     }
     $path = $this->getBreadcrumbs($file);
     if (!$path) {
         return array();
     }
     $result = array('id' => $this->generateId(array('FILE' => true, 'ID' => $file->getId())), 'isDirectory' => false, 'isDeleted' => false, 'storageId' => $this->getStringStorageId(), 'path' => '/' . trim($path, '/'), 'name' => (string) $file->getName(), 'revision' => $file->getFileId(), 'version' => (string) $this->generateTimestamp($file->getUpdateTime()->getTimestamp()), 'extra' => array('id' => (string) $file->getId(), 'iblockId' => (string) $file->getStorageId(), 'sectionId' => (string) $file->getParentId(), 'rootSectionId' => (string) $this->storage->getRootObjectId(), 'name' => (string) $file->getName()), 'size' => (string) $file->getSize(), 'permission' => 'W', 'createdBy' => (string) $file->getCreatedBy(), 'modifiedBy' => (string) $file->getUpdatedBy());
     if ($this->storage->getRootObjectId() != $file->getParentId()) {
         $result['parentId'] = $this->generateId(array('FILE' => false, 'ID' => $file->getParentId()));
     }
     return $result;
 }
Пример #27
0
 /**
  * @return array
  */
 public static function getMapReferenceAttributes()
 {
     $userClassName = User::className();
     $fields = User::getFieldsForSelect();
     return array('OBJECT' => File::className(), 'VERSION' => Version::className(), 'USER' => array('class' => $userClassName, 'select' => $fields), 'OWNER' => array('class' => $userClassName, 'select' => $fields));
 }
Пример #28
0
         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"];
     }
Пример #29
0
 public static function getUsersFromUserGroup($group, $documentId)
 {
     if (substr($documentId, 0, 8) == "STORAGE_") {
         $storageId = self::getStorageIdByType($documentId);
     } else {
         if (is_array($documentId)) {
             $documentId = intval($documentId[2]);
         }
         /** @var File $file */
         $file = File::loadById($documentId);
         if (!$file) {
             return array();
         }
         $storageId = $file->getStorageId();
     }
     if (strtolower($group) == "author") {
         $documentId = intval($documentId);
         if ($documentId <= 0) {
             return array();
         }
         /** @var File $file */
         $file = File::loadById($documentId);
         if (!$file) {
             return array();
         }
         return array($file->getCreatedBy());
     }
     if ($storageId) {
         $storage = Storage::loadById($storageId, array('ROOT_OBJECT'));
         if ($storage->getProxyType() instanceof ProxyType\Group) {
             $entityId = $storage->getEntityId();
             $group = strtoupper($group);
             if (Loader::includeModule("socialnetwork")) {
                 $listUserGroup = array();
                 if ($group == SONET_ROLES_OWNER) {
                     $listGroup = \CSocNetGroup::getByID($entityId);
                     if ($listGroup) {
                         $listUserGroup[] = $listGroup["OWNER_ID"];
                     }
                 } elseif ($group == SONET_ROLES_MODERATOR) {
                     $dbRes = \CSocNetUserToGroup::getList(array(), array("GROUP_ID" => $entityId, "<=ROLE" => SONET_ROLES_MODERATOR, "USER_ACTIVE" => "Y"), false, false, array("USER_ID"));
                     while ($res = $dbRes->fetch()) {
                         $listUserGroup[] = $res["USER_ID"];
                     }
                 } elseif ($group == SONET_ROLES_USER) {
                     $dbRes = \CSocNetUserToGroup::getList(array(), array("GROUP_ID" => $entityId, "<=ROLE" => SONET_ROLES_USER, "USER_ACTIVE" => "Y"), false, false, array("USER_ID"));
                     while ($res = $dbRes->fetch()) {
                         $listUserGroup[] = $res["USER_ID"];
                     }
                 }
                 return $listUserGroup;
             }
         }
     }
     $group = intval($group);
     if ($group <= 0) {
         return array();
     }
     $userIds = array();
     $filter = array("ACTIVE" => "Y");
     if ($group != 2) {
         $filter["GROUPS_ID"] = $group;
     }
     $query = \CUser::getList($b = "ID", $o = "ASC", $filter);
     while ($user = $query->fetch()) {
         $userIds[] = $user["ID"];
     }
     return $userIds;
 }
Пример #30
0
 /**
  * @param $iblockId
  * @param string $fileId disk file with the prefix 'n'
  * @return int|null
  */
 public static function attachFilesWorkflow($iblockId, $fileId)
 {
     if (!(int) $iblockId) {
         return null;
     }
     $userFieldManager = Driver::getInstance()->getUserFieldManager();
     list($connectorClass, $moduleId) = $userFieldManager->getConnectorDataByEntityType("iblock_workflow");
     list($type, $realId) = FileUserType::detectType($fileId);
     if ($type != FileUserType::TYPE_NEW_OBJECT) {
         return null;
     }
     $errorCollection = new ErrorCollection();
     $fileModel = File::loadById($realId, array('STORAGE'));
     if (!$fileModel) {
         return null;
     }
     $attachedModel = AttachedObject::load(array('OBJECT_ID' => $fileModel->getId(), '=ENTITY_TYPE' => $connectorClass, '=ENTITY_ID' => $iblockId, '=MODULE_ID' => $moduleId));
     if ($attachedModel) {
         return $fileModel->getId();
     }
     global $USER;
     if ($USER instanceof \CUser && $USER->getId()) {
         $userId = $USER->getId();
     } else {
         $userId = SystemUser::SYSTEM_USER_ID;
     }
     $securityContext = $fileModel->getStorage()->getSecurityContext($userId);
     if (!$fileModel->canRead($securityContext)) {
         return null;
     }
     $canUpdate = $fileModel->canUpdate($securityContext);
     $attachedModel = AttachedObject::add(array('MODULE_ID' => $moduleId, 'OBJECT_ID' => $fileModel->getId(), 'ENTITY_ID' => $iblockId, 'ENTITY_TYPE' => $connectorClass, 'IS_EDITABLE' => (int) $canUpdate, 'ALLOW_EDIT' => (int) ($canUpdate && (int) Application::getInstance()->getContext()->getRequest()->getPost('DISK_FILE_' . $iblockId . '_DISK_ATTACHED_OBJECT_ALLOW_EDIT')), 'CREATED_BY' => $userId), $errorCollection);
     if (!$attachedModel || $errorCollection->hasErrors()) {
         return null;
     }
     return $fileModel->getId();
 }