Exemple #1
0
 protected function processActionShowSubFolders()
 {
     if (!$this->checkRequiredPostParams(array('objectId'))) {
         $this->sendJsonErrorResponse();
     }
     $showOnlyDeleted = (bool) $this->request->getPost('showOnlyDeleted');
     $isRoot = (bool) $this->request->getPost('isRoot');
     /** @var Folder $folder */
     $folder = Folder::loadById((int) $this->request->getPost('objectId'), array('STORAGE'));
     if (!$folder) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_BREADCRUMBS_ERROR_COULD_NOT_FIND_FOLDER'), self::ERROR_COULD_NOT_FIND_FOLDER)));
         $this->sendJsonErrorResponse();
     }
     $securityContext = $folder->getStorage()->getCurrentUserSecurityContext();
     $subFolders = array();
     $filter = array('TYPE' => ObjectTable::TYPE_FOLDER);
     if ($showOnlyDeleted) {
         $filter['!=DELETED_TYPE'] = ObjectTable::DELETED_TYPE_NONE;
     }
     if ($showOnlyDeleted && $isRoot) {
         $filter['DELETED_TYPE'] = ObjectTable::DELETED_TYPE_ROOT;
         $children = $folder->getDescendants($securityContext, array('filter' => $filter));
     } else {
         $children = $folder->getChildren($securityContext, array('filter' => $filter));
     }
     foreach ($children as $subFolder) {
         /** @var Folder $subFolder */
         $subFolders[] = array('id' => $subFolder->getId(), 'name' => $subFolder->getName(), 'isLink' => $subFolder->isLink());
     }
     unset($subFolder);
     \Bitrix\Main\Type\Collection::sortByColumn($subFolders, 'name');
     $this->sendJsonSuccessResponse(array('items' => $subFolders));
 }
Exemple #2
0
 protected function findFolder()
 {
     $this->folder = \Bitrix\Disk\Folder::loadById($this->arParams['FOLDER_ID']);
     if (!$this->folder) {
         throw new \Bitrix\Main\SystemException("Invalid folder.");
     }
     return $this;
 }
Exemple #3
0
 /**
  * @return Folder
  */
 protected function getFolder()
 {
     if (isset($this->arParams['FOLDER'])) {
         return $this->arParams['FOLDER'];
     }
     $this->arParams['FOLDER'] = Folder::loadById($this->arParams['FOLDER_ID']);
     return $this->arParams['FOLDER'];
 }
Exemple #4
0
 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);
 }
Exemple #5
0
 protected function processActionCalculate()
 {
     if (!$this->checkRequiredPostParams(array('objectId'))) {
         $this->sendJsonErrorResponse();
     }
     /** @var Folder $folder */
     $folder = Folder::loadById((int) $this->request->getPost('objectId'), array('STORAGE'));
     if (!$folder) {
         $this->errorCollection->addOne(new Error(Loc::getMessage('DISK_TRASHCAN_ERROR_COULD_NOT_FIND_OBJECT'), self::ERROR_COULD_NOT_FIND_OBJECT));
         $this->sendJsonErrorResponse();
     }
     $securityContext = $folder->getStorage()->getCurrentUserSecurityContext();
     if (!$folder->canRead($securityContext)) {
         $this->sendJsonAccessDeniedResponse();
     }
     $countQuery = new Bitrix\Main\Entity\Query(FolderTable::getEntity());
     $totalCount = $countQuery->setFilter(array('PATH_CHILD.PARENT_ID' => $folder->getId(), '!PATH_CHILD.OBJECT_ID' => $folder->getId(), '!=DELETED_TYPE' => ObjectTable::DELETED_TYPE_NONE, '=RIGHTS_CHECK' => true))->registerRuntimeField('RIGHTS_CHECK', new ExpressionField('RIGHTS_CHECK', 'CASE WHEN ' . $securityContext->getSqlExpressionForList('%1$s', '%2$s') . ' THEN 1 ELSE 0 END', array('ID', 'CREATED_BY')))->addSelect(new \Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(1)'))->setLimit(null)->setOffset(null)->exec()->fetch();
     $this->sendJsonSuccessResponse(array('countItems' => $totalCount['CNT']));
 }
Exemple #6
0
 /**
  * @param      $targetFolderId
  * @param bool $detectSubFoldersOnObject
  * @throws \Bitrix\Main\ArgumentOutOfRangeException
  * @return array
  */
 protected function getSubFolders($targetFolderId, $detectSubFoldersOnObject = true)
 {
     /** @var Folder $folder */
     $folder = Folder::loadById($targetFolderId);
     if (!$folder) {
         $this->errorCollection->addOne(new Error(Loc::getMessage('DISK_BREADCRUMBS_TREE_ERROR_COULD_NOT_FIND_FOLDER'), self::ERROR_COULD_NOT_FIND_FOLDER));
         $this->sendJsonErrorResponse();
     }
     $securityContext = $folder->getStorage()->getCurrentUserSecurityContext();
     $subFolders = array();
     $parameters = array('filter' => array('TYPE' => ObjectTable::TYPE_FOLDER));
     if ($detectSubFoldersOnObject) {
         $parameters['select'] = array('*', 'HAS_SUBFOLDERS');
     }
     foreach ($folder->getChildren($securityContext, $parameters) as $subFolder) {
         /** @var Folder $subFolder */
         $subFolders[] = array('id' => $subFolder->getId(), 'name' => $subFolder->getName(), 'isLink' => $subFolder->isLink(), 'hasSubFolders' => $subFolder->hasSubFolders());
     }
     unset($subFolder);
     \Bitrix\Main\Type\Collection::sortByColumn($subFolders, 'name');
     return $subFolders;
 }
Exemple #7
0
 protected function processActionAddFolder()
 {
     if (!$this->checkRequiredPostParams(array('name', 'targetFolderId'))) {
         $this->sendJsonErrorResponse();
     }
     /** @var Folder $folder */
     $folder = Folder::loadById((int) $this->request->getPost('targetFolderId'), array('STORAGE'));
     if (!$folder) {
         $this->errorCollection->addOne(new Error(Loc::getMessage('DISK_FOLDER_TOOLBAR_ERROR_COULD_NOT_FIND_OBJECT'), self::ERROR_COULD_NOT_FIND_OBJECT));
         $this->sendJsonErrorResponse();
     }
     $securityContext = $folder->getStorage()->getCurrentUserSecurityContext();
     if (!$folder->canAdd($securityContext)) {
         $this->sendJsonAccessDeniedResponse();
     }
     $name = $this->request->getPost('name');
     $subFolderModel = $folder->addSubFolder(array('NAME' => Ui\Text::correctFolderName($name), 'CREATED_BY' => $this->getUser()->getId()));
     if ($subFolderModel === null) {
         $this->errorCollection->add($folder->getErrors());
         $this->sendJsonErrorResponse();
     }
     $this->sendJsonSuccessResponse(array('folder' => array('id' => $subFolderModel->getId())));
 }
 private function getFolderToSaveFile($targetFolderId)
 {
     /** @var Folder $folder */
     $folder = Folder::loadById($targetFolderId, array('STORAGE'));
     if (!$folder) {
         return null;
     }
     return $folder;
 }
 protected function processActionOpenFolderList()
 {
     if (!$this->checkRequiredGetParams(array('folderId'))) {
         $this->sendJsonErrorResponse();
     }
     /** @var Folder $folder */
     $folder = Folder::loadById((int) $this->request->getQuery('folderId'), array('STORAGE'));
     if (!$folder) {
         $this->errorCollection->addOne(new Error('Could not find folder', self::ERROR_COULD_NOT_FIND_FILE));
         $this->sendJsonErrorResponse();
     }
     if (!$folder->canRead($folder->getStorage()->getCurrentUserSecurityContext())) {
         $this->errorCollection->addOne(new Error('Could not find folder', self::ERROR_COULD_NOT_READ_FILE));
         $this->sendJsonErrorResponse();
     }
     $urlManager = Driver::getInstance()->getUrlManager();
     LocalRedirect($urlManager->encodeUrn($urlManager->getPathFolderList($folder)));
 }
 protected function migrateTrashFolders()
 {
     if ($this->isStepFinished(__METHOD__)) {
         return;
     }
     $lastId = $this->getStorageId();
     //first migrate folder from trash
     $trashQuery = $this->connection->query("\n\t\t\tSELECT\n\t\t\t\tobj.*,\n\t\t\t\ts.ROOT_OBJECT_ID ROOT_OBJECT_ID,\n\t\t\t\tsecta.DESCRIPTION DESCRIPTION\n\t\t\tFROM b_disk_object obj\n\t\t\t\tINNER JOIN b_disk_storage s ON s.ID = obj.STORAGE_ID\n\t\t\t\tINNER JOIN b_disk_object trash ON trash.ID = obj.PARENT_ID AND trash.PARENT_ID = s.ROOT_OBJECT_ID\n\t\t\t\tINNER JOIN b_iblock_section secta ON secta.ID = obj.ID\n\n\t\t\tWHERE obj.TYPE=2 AND trash.NAME = '.Trash' AND obj.ID > {$lastId} ORDER BY s.ID\n\t\t");
     while ($trashChild = $trashQuery->fetch()) {
         $this->abortIfNeeded();
         $undeletePath = $this->getSectionInTrash($trashChild);
         if (empty($undeletePath)) {
             $this->log(array("Skip item {$trashChild['ID']} from .Trash", "Empty WEBDAV_INFO (DESCRIPTION)"));
             $this->storeStorageId($trashChild['ID']);
             continue;
         }
         $undeletePath = trim($undeletePath, '/');
         $filter = array('TYPE' => \Bitrix\Disk\Internals\ObjectTable::TYPE_FOLDER, 'STORAGE_ID' => $trashChild['STORAGE_ID'], 'PARENT_ID' => $trashChild['ROOT_OBJECT_ID']);
         $mustCreatePathPieces = array();
         $undeletePathPieces = explode('/', $undeletePath);
         $parentId = $filter['PARENT_ID'];
         $parentDeletedType = null;
         $filename = array_pop($undeletePathPieces);
         foreach ($undeletePathPieces as $i => $pieceOfPath) {
             $filter['NAME'] = $this->sqlHelper->forSql($pieceOfPath);
             $folder = $this->connection->query("\n\t\t\t\t\tSELECT ID, NAME, REAL_OBJECT_ID, STORAGE_ID, PARENT_ID, DELETED_TYPE FROM b_disk_object obj\n\t\t\t\t\tWHERE obj.PARENT_ID = {$filter['PARENT_ID']} AND obj.STORAGE_ID = {$filter['STORAGE_ID']}  AND obj.TYPE = {$filter['TYPE']} AND obj.NAME = '{$filter['NAME']}'\n\t\t\t\t")->fetch();
             if ($folder) {
                 $filter['PARENT_ID'] = $parentId = $folder['ID'];
                 if (!empty($folder['DELETED_TYPE'])) {
                     $parentDeletedType = $folder['DELETED_TYPE'];
                 }
                 continue;
             }
             if (!$folder) {
                 $this->log(array("Folder with name {$pieceOfPath} does not exist"));
                 $mustCreatePathPieces = array_slice($undeletePathPieces, $i);
                 break;
             }
         }
         unset($pieceOfPath);
         if ($parentId) {
             $success = true;
             /** @var Folder $parentFolder */
             $parentFolder = Folder::loadById($parentId);
             $folderData = array('CREATE_TIME' => $trashChild['CREATE_TIME'], 'UPDATE_TIME' => $trashChild['UPDATE_TIME'], 'CREATED_BY' => $trashChild['CREATED_BY'], 'UPDATED_BY' => $trashChild['UPDATED_BY']);
             foreach ($mustCreatePathPieces as $i => $pieceOfPath) {
                 $deletedType = FolderTable::DELETED_TYPE_CHILD;
                 if ($i == 0 && !$parentDeletedType) {
                     $deletedType = FolderTable::DELETED_TYPE_ROOT;
                 }
                 $folderData['NAME'] = Text::correctFilename($pieceOfPath);
                 if ($deletedType == FolderTable::DELETED_TYPE_ROOT) {
                     $folderData['NAME'] = self::appendTrashCanSuffix($folderData['NAME']);
                 }
                 $folder = $parentFolder->addSubFolder($folderData, array(), true);
                 if (!$folder) {
                     $this->log(array("Skip item {$trashChild['ID']} from .Trash", "Could not create subfolder {$folderData['NAME']}"));
                     $this->storeStorageId($trashChild['ID']);
                     $success = false;
                     break;
                 }
                 $updateResult = FolderTable::update($folder->getId(), array('DELETED_TYPE' => $deletedType, 'DELETE_TIME' => $folder->getUpdateTime(), 'DELETED_BY' => $folder->getUpdatedBy()));
                 if (!$updateResult->isSuccess()) {
                     $this->log(array("Skip item {$trashChild['ID']} from .Trash", "Could not markDeleted subfolder {$folder->getId()}"));
                     $this->storeStorageId($trashChild['ID']);
                     $success = false;
                     break;
                 }
                 $parentFolder = $folder;
             }
             unset($pieceOfPath, $folder, $undeletePath);
             if ($success) {
                 //move trashChild into new folder
                 if ($this->isMysql || $this->isMssql) {
                     $this->connection->queryExecute("\n\t\t\t\t\t\t\tDELETE a FROM b_disk_object_path a\n\t\t\t\t\t\t\t\tJOIN b_disk_object_path d\n\t\t\t\t\t\t\t\t\tON a.OBJECT_ID = d.OBJECT_ID\n\t\t\t\t\t\t\t\tLEFT JOIN b_disk_object_path x\n\t\t\t\t\t\t\t\t\tON x.PARENT_ID = d.PARENT_ID AND x.OBJECT_ID = a.PARENT_ID\n\t\t\t\t\t\t\t\tWHERE d.PARENT_ID = {$trashChild['ID']} AND x.PARENT_ID IS NULL;\n\t\t\t\t\t\t");
                 } elseif ($this->isOracle) {
                     $this->connection->queryExecute("\n\t\t\t\t\t\t\tDELETE FROM b_disk_object_path WHERE ID IN (SELECT a.ID FROM b_disk_object_path a\n\t\t\t\t\t\t\t\tJOIN b_disk_object_path d\n\t\t\t\t\t\t\t\t\tON a.OBJECT_ID = d.OBJECT_ID\n\t\t\t\t\t\t\t\tLEFT JOIN b_disk_object_path x\n\t\t\t\t\t\t\t\t\tON x.PARENT_ID = d.PARENT_ID AND x.OBJECT_ID = a.PARENT_ID\n\t\t\t\t\t\t\t\tWHERE d.PARENT_ID = {$trashChild['ID']} AND x.PARENT_ID IS NULL)\n\t\t\t\t\t\t");
                 }
                 $this->connection->queryExecute("\n\t\t\t\t\t\tINSERT INTO b_disk_object_path (PARENT_ID, OBJECT_ID, DEPTH_LEVEL)\n\t\t\t\t\t\t\tSELECT stree.PARENT_ID, subtree.OBJECT_ID, stree.DEPTH_LEVEL+subtree.DEPTH_LEVEL+1\n\t\t\t\t\t\t\tFROM b_disk_object_path stree INNER JOIN b_disk_object_path subtree\n\t\t\t\t\t\t\t\tON subtree.PARENT_ID = {$trashChild['ID']} AND stree.OBJECT_ID = {$parentFolder->getId()};\n\t\t\t\t\t");
                 //update all objects under trashChild (DELETED_TYPE)
                 $deletedType = FolderTable::DELETED_TYPE_CHILD;
                 if ($this->isMysql) {
                     $sql = "\n\t\t\t\t\t\t\tUPDATE b_disk_object obj\n\t\t\t\t\t\t\t\tINNER JOIN b_disk_object_path p ON obj.ID = p.OBJECT_ID\n\t\t\t\t\t\t\t\tSET obj.DELETED_TYPE = {$deletedType}, obj.DELETED_BY=obj.UPDATED_BY, obj.DELETE_TIME=obj.UPDATE_TIME\n\t\t\t\t\t\t\tWHERE p.PARENT_ID = {$trashChild['ID']}\n\t\t\t\t\t\t";
                 } elseif ($this->isOracle || $this->isMssql) {
                     $sql = "\n\t\t\t\t\t\t\tUPDATE b_disk_object\n\t\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t\tDELETED_TYPE = {$deletedType},\n\t\t\t\t\t\t\t\t\tDELETED_BY=(SELECT obj.UPDATED_BY FROM b_disk_object obj INNER JOIN b_disk_object_path p ON obj.ID = p.OBJECT_ID\n\t\t\t\t\t\t\tWHERE p.PARENT_ID = {$trashChild['ID']} and obj.ID = b_disk_object.ID),\n\n\t\t\t\t\t\t\t\t\tDELETE_TIME=(SELECT obj.UPDATE_TIME FROM b_disk_object obj INNER JOIN b_disk_object_path p ON obj.ID = p.OBJECT_ID\n\t\t\t\t\t\t\tWHERE p.PARENT_ID = {$trashChild['ID']} and obj.ID = b_disk_object.ID)\n\n\t\t\t\t\t\t\tWHERE EXISTS((SELECT 'x' FROM b_disk_object obj INNER JOIN b_disk_object_path p ON obj.ID = p.OBJECT_ID\n\t\t\t\t\t\t\tWHERE p.PARENT_ID = {$trashChild['ID']} and obj.ID = b_disk_object.ID))\n\t\t\t\t\t\t";
                 }
                 $this->connection->queryExecute($sql);
                 $deletedType = FolderTable::DELETED_TYPE_ROOT;
                 $newName = $this->sqlHelper->forSql(self::appendTrashCanSuffix(Text::correctFilename($filename)));
                 $this->connection->queryExecute("\n\t\t\t\t\t\tUPDATE b_disk_object SET NAME='{$newName}', PARENT_ID = {$parentFolder->getId()}, DELETED_TYPE = {$deletedType}, DELETED_BY=UPDATED_BY, DELETE_TIME=UPDATE_TIME\n\t\t\t\t\t\tWHERE ID={$trashChild['ID']} AND STORAGE_ID={$trashChild['STORAGE_ID']}\n\t\t\t\t\t");
                 $this->connection->queryExecute("\n\t\t\t\t\t\tINSERT INTO b_disk_deleted_log (STORAGE_ID, OBJECT_ID, TYPE, USER_ID, CREATE_TIME)\n\t\t\t\t\t\tSELECT {$trashChild['STORAGE_ID']}, p.OBJECT_ID, obj.TYPE, obj.UPDATED_BY, " . $this->sqlHelper->getCurrentDateTimeFunction() . " FROM b_disk_object obj\n\t\t\t\t\t\t\tINNER JOIN b_disk_object_path p ON obj.ID = p.OBJECT_ID\n\t\t\t\t\t\tWHERE p.PARENT_ID = {$trashChild['ID']}\n\t\t\t\t\t");
                 $this->storeStorageId($trashChild['ID']);
             }
         }
         $this->storeStorageId($trashChild['ID']);
     }
     $this->abortIfNeeded();
     $this->storeStorageId(0);
     $this->setStepFinished(__METHOD__);
 }
Exemple #11
0
 /**
  * Returns parent model.
  * If object does not have parent, then returns null.
  * @return Folder|null
  * @throws \Bitrix\Main\NotImplementedException
  */
 public function getParent()
 {
     if (!$this->parentId) {
         return null;
     }
     if (isset($this->parent) && $this->parentId === $this->parent->getId()) {
         return $this->parent;
     }
     //todo - BaseObject - knows about Folder ^( Nu i pust'
     $this->parent = Folder::loadById($this->getParentId());
     return $this->parent;
 }
Exemple #12
0
 protected function processActionShowSubFoldersToAdd()
 {
     $this->checkRequiredPostParams(array('objectId'));
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     /** @var Folder $folder */
     $folder = Folder::loadById((int) $this->request->getPost('objectId'), array('STORAGE'));
     if (!$folder) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_FOLDER_LIST_ERROR_COULD_NOT_FIND_OBJECT'), self::ERROR_COULD_NOT_FIND_OBJECT)));
         $this->sendJsonErrorResponse();
     }
     $securityContext = $folder->getStorage()->getCurrentUserSecurityContext();
     //we should preload specific rights by object on current level, because we are filtering by canAdd. And we can use fakeSecurityContext by $folder->getChildren
     $securityContext->preloadOperationsForChildren($folder->getRealObjectId());
     $subFolders = array();
     foreach ($folder->getChildren(Driver::getInstance()->getFakeSecurityContext(), array('select' => array('*', 'HAS_SUBFOLDERS'), 'filter' => array('TYPE' => ObjectTable::TYPE_FOLDER))) as $subFolder) {
         /** @var Folder $subFolder */
         if ($subFolder->canAdd($securityContext)) {
             $subFolders[] = array('id' => $subFolder->getId(), 'name' => $subFolder->getName(), 'isLink' => $subFolder->isLink(), 'hasSubFolders' => $subFolder->hasSubFolders());
         }
     }
     unset($subFolder);
     \Bitrix\Main\Type\Collection::sortByColumn($subFolders, 'name');
     $this->sendJsonSuccessResponse(array('items' => $subFolders));
 }
use Bitrix\Main\Localization\Loc;
if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) {
    die;
}
/** @var array $arParams */
/** @var array $arResult */
/** @global CMain $APPLICATION */
/** @global CUser $USER */
/** @global CDatabase $DB */
/** @var CBitrixComponentTemplate $this */
/** @var string $templateName */
/** @var string $templateFile */
/** @var string $templateFolder */
/** @var string $componentPath */
/** @var \Bitrix\Disk\Internals\BaseComponent $component */
$folder = \Bitrix\Disk\Folder::loadById($arResult['VARIABLES']['FOLDER_ID']);
?>
<div class="bx-disk-container posr" id="bx-disk-container">
	<table style="width: 100%;" cellpadding="0" cellspacing="0">
		<tr>
			<td>
				<div class="bx-disk-interface-toolbar-container">
					<?php 
$APPLICATION->IncludeComponent('bitrix:disk.folder.toolbar', '', array('STORAGE' => $arResult['STORAGE'], 'FOLDER' => $arResult['STORAGE']->getRootObject(), 'URL_TO_TRASHCAN_LIST' => CComponentEngine::makePathFromTemplate($arResult['PATH_TO_TRASHCAN_LIST'], array('TRASH_PATH' => '')), 'URL_TO_FOLDER_LIST' => CComponentEngine::makePathFromTemplate($arResult['PATH_TO_FOLDER_LIST'], array('PATH' => '')), 'PATH_TO_FOLDER_LIST' => $arResult['PATH_TO_FOLDER_LIST'], 'PATH_TO_FILE_VIEW' => $arResult['PATH_TO_FILE_VIEW'], 'PATH_TO_TRASHCAN_LIST' => $arResult['PATH_TO_TRASHCAN_LIST'], 'PATH_TO_EXTERNAL_LINK_LIST' => $arResult['PATH_TO_EXTERNAL_LINK_LIST'], 'MODE' => 'external_link_list'), $component);
?>
				</div>
				<?php 
$APPLICATION->IncludeComponent('bitrix:disk.external.link.list', '', array_merge(array_intersect_key($arResult, array('STORAGE' => true, 'PATH_TO_FOLDER_LIST' => true, 'PATH_TO_FILE_VIEW' => true)), array()), $component);
?>
			</td>
			<td class="bx-disk-table-sidebar-cell" style="">
    }
} elseif ($type == 'group') {
    $entityId = (int) $_REQUEST['entityId'];
    $storage = Driver::getInstance()->getStorageByGroupId($entityId);
    if (!$storage) {
        $data = array('status' => 'not_found');
        return $data;
    }
} else {
    $data = array('status' => 'not_found');
    return $data;
}
$urlManager = Driver::getInstance()->getUrlManager();
$currentFolderId = $urlManager->resolveFolderIdFromPath($storage, $path);
/** @var Folder $folder */
$folder = Folder::loadById($currentFolderId);
if (!$folder) {
    $data = array('status' => 'not_found');
    return $data;
}
$securityContext = $storage->getCurrentUserSecurityContext();
$items = array();
$countFolders = $countFiles = 0;
foreach ($folder->getChildren($securityContext) as $item) {
    /** @var File|Folder $item */
    $isFolder = $item instanceof Folder;
    if ($isFolder) {
        $icon = CMobileHelper::mobileDiskGetIconByFilename($item->getName());
        $items[] = array('NAME' => mobileDiskPrepareForJson($item->getName()), 'TABLE_URL' => SITE_DIR . 'mobile/index.php?' . '&mobile_action=' . 'disk_folder_list' . '&path=' . mobileDiskPrepareForJson($path . '/' . $item->getName()) . '&entityId=' . $entityId . '&type=' . $type, 'IMAGE' => CComponentEngine::makePathFromTemplate('/bitrix/components/bitrix/mobile.disk.file.detail/images/folder.png'), 'TABLE_SETTINGS' => array('type' => 'files', 'useTagsInSearch' => 'NO'));
        $countFolders++;
    } else {
Exemple #15
0
 public function renameDirectory($name, $targetDirectoryId, $parentDirectoryId)
 {
     /** @var Folder $sourceFolder */
     $sourceFolder = Folder::loadById($targetDirectoryId);
     if (!$sourceFolder) {
         $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " by id {$targetDirectoryId}", 111602)));
         return false;
     }
     if (!$sourceFolder->canRename($this->storage->getCurrentUserSecurityContext())) {
         throw new CWebDavAccessDeniedException();
     }
     if ($sourceFolder->rename($name, $this->getUser()->getId())) {
         $this->loadFormattedFolderTreeAndBreadcrumbs();
         return $this->getDirectory(null, array('id' => $sourceFolder->getId()), true);
     }
     $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . ", rename", 111603)));
     $this->errorCollection->add($sourceFolder->getErrors());
     return array();
 }
Exemple #16
0
 protected function processActionMoveUploadedFile()
 {
     $this->checkRequiredPostParams(array('attachedId', 'targetFolderId'));
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     list($type, $objectId) = FileUserType::detectType($this->request->getPost('attachedId'));
     if ($type != FileUserType::TYPE_NEW_OBJECT || !$objectId) {
         $this->errorCollection->add(array(new Error('Could not move attached file')));
         $this->sendJsonErrorResponse();
     }
     $targetFolderId = (int) $this->request->getPost('targetFolderId');
     /** @var File $file */
     $file = File::loadById($objectId, array('STORAGE'));
     if (!$file) {
         $this->errorCollection->add(array(new Error('Could not find file')));
         $this->sendJsonErrorResponse();
     }
     if ($file->getCreatedBy() != $this->getUser()->getId()) {
         $this->errorCollection->add(array(new Error('Could not move alien file')));
         $this->sendJsonErrorResponse();
     }
     /** @var Folder $targetFolder */
     $targetFolder = Folder::loadById($targetFolderId, array('STORAGE'));
     if (!$targetFolder) {
         $this->errorCollection->add(array(new Error('Could not find target folder')));
         $this->sendJsonErrorResponse();
     }
     if (!$file->canMove($file->getStorage()->getCurrentUserSecurityContext(), $targetFolder)) {
         $this->errorCollection->add(array(new Error('Bad permission. Could not move this file')));
         $this->sendJsonErrorResponse();
     }
     if (!$file->moveToAnotherFolder($targetFolder, $this->getUser()->getId(), true)) {
         $this->errorCollection->add(array(new Error('Could not move the file')));
         $this->sendJsonErrorResponse();
     }
     $this->sendJsonSuccessResponse();
 }
Exemple #17
0
 /**
  * @param Storage $storage
  * @param string $path
  */
 private function createFolderPath($storage, $path)
 {
     $path = trim($path, '/');
     if ($path == '') {
         return true;
     }
     $foldersPath = explode('/', $path);
     $urlManager = Driver::getInstance()->getUrlManager();
     /** @var Folder $folder */
     $folderId = $urlManager->resolveFolderIdFromPath($storage, '/');
     $folder = Folder::loadById($folderId);
     $s = '';
     while (!empty($foldersPath)) {
         $subFolderName = array_shift($foldersPath);
         $s .= '/' . $subFolderName;
         $folderId = $urlManager->resolveFolderIdFromPath($storage, $s);
         if ($folderId) {
             $folder = Folder::loadById($folderId);
             if (!$folder) {
                 return '409 Conflict';
             }
         } else {
             if (!$folder->canAdd($storage->getCurrentUserSecurityContext())) {
                 return '403 Forbidden';
             }
             $folder = $folder->addSubFolder(array('NAME' => $subFolderName, 'CREATED_BY' => $this->getUser()->getId()));
         }
     }
     return true;
 }
Exemple #18
0
 /**
  * @return Folder|null
  */
 public function getRootObject()
 {
     if (!$this->rootObjectId) {
         return null;
     }
     if (isset($this->rootObject) && $this->rootObjectId === $this->rootObject->getId()) {
         return $this->rootObject;
     }
     //todo - Storage - knows about Folder ^( Nu i pust'
     $this->rootObject = Folder::loadById($this->rootObjectId);
     return $this->rootObject;
 }
 protected function processActionPublishBlank()
 {
     $this->checkRequiredGetParams(array('type'));
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     $fileData = new BlankFileData($this->request->getQuery('type'));
     if ($this->request->getPost('targetFolderId')) {
         $folder = Folder::loadById((int) $this->request->getPost('targetFolderId'), array('STORAGE'));
         if (!$folder) {
             $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_FOLDER'), self::ERROR_COULD_NOT_FIND_FOLDER)));
             $this->sendJsonErrorResponse();
         }
     } else {
         $userStorage = Driver::getInstance()->getStorageByUserId($this->getUser()->getId());
         if (!$userStorage) {
             $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_STORAGE'), self::ERROR_COULD_NOT_FIND_STORAGE)));
             $this->sendJsonErrorResponse();
         }
         $folder = $userStorage->getFolderForCreatedFiles();
     }
     if (!$folder) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_FOLDER_FOR_CREATED_FILES'), self::ERROR_COULD_NOT_FIND_FOLDER_FOR_CREATED_FILES)));
         $this->sendJsonErrorResponse();
     }
     $storage = $folder->getStorage();
     if (!$folder->canAdd($storage->getCurrentUserSecurityContext())) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_BAD_RIGHTS'), self::ERROR_BAD_RIGHTS)));
         $this->sendJsonErrorResponse();
     }
     $newFile = $folder->addBlankFile(array('NAME' => $fileData->getName(), 'CREATED_BY' => $this->getUser()->getId(), 'MIME_TYPE' => $fileData->getMimeType()), array(), true);
     if (!$newFile) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_CREATE_FILE'), self::ERROR_COULD_NOT_CREATE_FILE)));
         $this->errorCollection->add($folder->getErrors());
         $this->sendJsonErrorResponse();
     }
     $this->sendJsonSuccessResponse(array('ufValue' => FileUserType::NEW_FILE_PREFIX . $newFile->getId(), 'id' => $newFile->getId(), 'object' => array('id' => $newFile->getId(), 'name' => $newFile->getName(), 'sizeInt' => $newFile->getSize(), 'size' => \CFile::formatSize($newFile->getSize()), 'extension' => $newFile->getExtension(), 'nameWithoutExtension' => getFileNameWithoutExtension($newFile->getName())), 'folderName' => $storage->getProxyType()->getTitleForCurrentUser() . ' / ' . $folder->getName(), 'link' => Driver::getInstance()->getUrlManager()->getUrlForStartEditFile($newFile->getId(), self::CODE)));
 }
Exemple #20
0
 /**
  * @param $storage
  * @param $path
  * @return array
  */
 protected function listItems(Storage $storage, $path = '/')
 {
     $currentFolderId = Driver::getInstance()->getUrlManager()->resolveFolderIdFromPath($storage, $path);
     /** @var Folder $folder */
     $folder = Folder::loadById($currentFolderId);
     if (!$folder) {
         $this->errorCollection->add(array(new Error('Could not find folder by path')));
         $this->sendJsonErrorResponse();
     }
     $securityContext = $storage->getCurrentUserSecurityContext();
     $urlManager = Driver::getInstance()->getUrlManager();
     $urlForLoadItems = $urlManager->getUrlUfController('loadItems');
     $response = array();
     foreach ($folder->getChildren($securityContext, array('with' => array('UPDATE_USER'))) as $item) {
         /** @var File|Folder $item */
         $isFolder = $item instanceof Folder;
         $id = $item->getId();
         $res = array('id' => $item->getId(), 'type' => $isFolder ? 'folder' : 'file', 'link' => $urlForLoadItems, 'name' => $item->getName(), 'path' => ($path === '/' ? '/' : $path . '/') . $item->getName(), 'size' => $isFolder ? '' : \CFile::formatSize($item->getSize()), 'sizeInt' => $isFolder ? '' : $item->getSize(), 'modifyBy' => $item->getUpdateUser()->getFormattedName(), 'modifyDate' => $item->getUpdateTime()->format('d.m.Y'), 'modifyDateInt' => $item->getUpdateTime()->getTimestamp());
         if (!$isFolder) {
             $extension = $item->getExtension();
             $id = FileUserType::NEW_FILE_PREFIX . $item->getId();
             $res = array_merge($res, array('id' => $id, 'ext' => $extension, 'storage' => $folder->getName()));
             if (TypeFile::isImage($item)) {
                 $res['previewUrl'] = $urlManager->getUrlForShowFile($item);
             }
         }
         $response[$id] = $res;
     }
     unset($item);
     return $response;
 }