Пример #1
1
 /**
  * Gets specific folder in storage by code. If folder does not exist, creates it.
  * @param Storage $storage Target storage.
  * @param string $code Code of specific folder.
  * @return Folder|null|static
  */
 public static function getFolder(Storage $storage, $code)
 {
     $folder = Folder::load(array('=CODE' => $code, 'STORAGE_ID' => $storage->getId()));
     if ($folder) {
         return $folder;
     }
     return static::createFolder($storage, $code);
 }
Пример #2
1
 /**
  * Copies object to target folder.
  * @param Folder $targetFolder Target folder.
  * @param int    $updatedBy Id of user.
  * @param bool   $generateUniqueName Generates unique name for object in directory.
  * @return BaseObject|null
  */
 public function copyTo(Folder $targetFolder, $updatedBy, $generateUniqueName = false)
 {
     $this->errorCollection->clear();
     /** @noinspection PhpDynamicAsStaticMethodCallInspection */
     $forkFileId = \CFile::copyFile($this->getFileId(), true);
     if (!$forkFileId) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_FILE_MODEL_ERROR_COULD_NOT_COPY_FILE'), self::ERROR_COULD_NOT_COPY_FILE)));
         return null;
     }
     /** @noinspection PhpDynamicAsStaticMethodCallInspection */
     $fileArray = \CFile::getFileArray($forkFileId);
     $fileModel = $targetFolder->addFile(array('NAME' => $this->getName(), 'FILE_ID' => $forkFileId, 'SIZE' => $fileArray['FILE_SIZE'], 'CREATED_BY' => $updatedBy), array(), $generateUniqueName);
     if (!$fileModel) {
         $this->errorCollection->add($targetFolder->getErrors());
         return null;
     }
     return $fileModel;
 }
Пример #3
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));
 }
Пример #4
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'];
 }
Пример #5
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;
 }
Пример #6
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;
 }
Пример #7
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);
 }
Пример #8
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']));
 }
Пример #9
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;
 }
Пример #10
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())));
 }
Пример #11
0
 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;
 }
Пример #12
0
//Turn off by default
/********************************************************************
				/Input params
********************************************************************/
$bDialog = isset($_REQUEST['dialog']) || isset($_REQUEST['dialog2']);
if ($arParams["PERMISSION"] < "R") {
    ShowError(GetMessage("WD_ACCESS_DENIED"));
    return 0;
} elseif (isset($ob->meta_state) && $arParams["PERMISSION"] < $ob->meta_names[$ob->meta_state]['rights']) {
    ShowError(GetMessage("WD_ACCESS_DENIED"));
    return 0;
}
if (\Bitrix\Main\Config\Option::get('disk', 'successfully_converted', false) && CModule::includeModule('disk') && !empty($arParams['OBJECT'])) {
    if (!empty($arParams['OBJECT']->arParams['dir_array'])) {
        /** @var \Bitrix\Disk\File $diskFolder */
        $diskFolder = \Bitrix\Disk\Folder::load(array('XML_ID' => $arParams['OBJECT']->arParams['dir_array']['ID']), array('STORAGE'));
        if ($diskFolder) {
            LocalRedirect(\Bitrix\Disk\Driver::getInstance()->getUrlManager()->getPathInListing($diskFolder) . '/' . $diskFolder->getName());
        }
    } elseif ($arParams['OBJECT']->_path == '/') {
        if (!empty($arParams['OBJECT']->attributes['user_id'])) {
            $diskStorage = \Bitrix\Disk\Driver::getInstance()->getStorageByUserId($arParams['OBJECT']->attributes['user_id']);
        } elseif (!empty($arParams['OBJECT']->attributes['group_id'])) {
            $diskStorage = \Bitrix\Disk\Driver::getInstance()->getStorageByGroupId($arParams['OBJECT']->attributes['group_id']);
        }
        if ($diskStorage) {
            LocalRedirect(\Bitrix\Disk\Driver::getInstance()->getUrlManager()->getPathInListing($diskStorage->getRootObject()));
        }
    }
}
/********************************************************************
Пример #13
0
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="">
Пример #14
0
 protected function formatFolderToResponse(Folder $folder, $markIsShared = false)
 {
     if (empty($folder) || !$folder->getName()) {
         return array();
     }
     $path = $this->getBreadcrumbs($folder);
     if (!$path) {
         return array();
     }
     $result = array('id' => $this->generateId(array('FILE' => false, 'ID' => $folder->getId())), 'isDirectory' => true, 'isShared' => (bool) $markIsShared, 'isSymlinkDirectory' => $folder instanceof \Bitrix\Disk\FolderLink, 'isDeleted' => false, 'storageId' => $this->getStringStorageId(), 'path' => '/' . trim($path, '/'), 'name' => (string) $folder->getName(), 'version' => (string) $this->generateTimestamp($folder->getUpdateTime()->getTimestamp()), 'extra' => array('id' => (string) $folder->getId(), 'iblockId' => (string) $folder->getStorageId(), 'sectionId' => (string) $folder->getParentId(), 'linkSectionId' => (string) ($folder->isLink() ? $folder->getRealObjectId() : ''), 'rootSectionId' => (string) $this->storage->getRootObjectId(), 'name' => (string) $folder->getName()), 'permission' => 'W', 'createdBy' => (string) $folder->getCreatedBy(), 'modifiedBy' => (string) $folder->getUpdatedBy());
     if ($this->storage->getRootObjectId() != $folder->getParentId()) {
         $result['parentId'] = $this->generateId(array('FILE' => false, 'ID' => $folder->getParentId()));
     }
     return $result;
 }
Пример #15
0
 protected function processActionWithDeleted()
 {
     $gridId = 'folder_list';
     $this->arResult = array('GRID' => $this->getGridData($gridId, true), 'FOLDER' => array('ID' => $this->folder->getId(), 'NAME' => $this->folder->getName(), 'IS_DELETED' => $this->folder->isDeleted(), 'CREATE_TIME' => $this->folder->getCreateTime(), 'UPDATE_TIME' => $this->folder->getUpdateTime()), 'BREADCRUMBS' => $this->getBreadcrumbs());
     $this->includeComponentTemplate();
 }
Пример #16
0
 private function getFolderToSaveFile($targetFolderId)
 {
     /** @var Folder $folder */
     $folder = Folder::loadById($targetFolderId, array('STORAGE'));
     if (!$folder) {
         return null;
     }
     return $folder;
 }
Пример #17
0
 private function getFolderContent(Folder $folder)
 {
     return strip_tags($folder->getName()) . "\r\n";
 }
Пример #18
0
    }
} 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 {
Пример #19
0
 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__);
 }
Пример #20
0
 /**
  * Saves file in destination folder from entry of cloud import.
  * @param Entry  $entry Cloud import entry.
  * @param Folder $folder Destination folder.
  * @return \Bitrix\Disk\File|null New file object.
  */
 public function saveFile(Entry $entry, Folder $folder)
 {
     if (!$entry->getTmpFile()) {
         $this->errorCollection->addOne(new Error('Could not find cloud import', self::ERROR_COULD_NOT_FIND_CLOUD_IMPORT));
         return null;
     }
     if ($entry->getContentSize() != $entry->getDownloadedContentSize()) {
         $this->errorCollection->addOne(new Error('Content size != downloaded content size'));
         return null;
     }
     $fileData = new Document\FileData();
     $fileData->setId($entry->getServiceObjectId());
     $fileMetadata = $this->documentHandler->getFileMetadata($fileData);
     if (!$fileMetadata || empty($fileMetadata['name'])) {
         $this->errorCollection->add($this->documentHandler->getErrors());
         return null;
     }
     $name = $fileMetadata['name'];
     if (!getFileExtension($name)) {
         $name = $this->recoverExtensionInName($name, $fileMetadata['mimeType']);
     }
     $tmpFile = $entry->getTmpFile();
     $fileArray = \CFile::makeFileArray($tmpFile->getAbsolutePath());
     $file = $folder->uploadFile($fileArray, array('NAME' => $name, 'CREATED_BY' => $this->documentHandler->getUserId(), 'CONTENT_PROVIDER' => $this->documentHandler->getCode()), array(), true);
     if (!$file) {
         $tmpFile->delete();
         $this->errorCollection->add($folder->getErrors());
         return null;
     }
     $entry->linkObject($file);
     return $file;
 }
Пример #21
0
 /**
  * @param int $typeID
  * @param string $siteID
  * @return \Bitrix\Disk\Folder|null
  */
 public static function ensureFolderCreated($typeID, $siteID = '')
 {
     if (!Loader::includeModule('disk')) {
         return null;
     }
     if (!StorageFileType::isDefined($typeID)) {
         return null;
     }
     if ($siteID === '') {
         $siteID = self::getDefaultSiteID();
     }
     $xmlID = StorageFileType::getFolderXmlID($typeID);
     $name = StorageFileType::getFolderName($typeID);
     $storage = self::getStorage($siteID);
     if (!$storage) {
         return null;
     }
     $folderModel = Folder::load(array('STORAGE_ID' => $storage->getId(), 'PARENT_ID' => $storage->getRootObjectId(), '=XML_ID' => $xmlID));
     if ($folderModel) {
         return $folderModel;
     }
     return $storage->addFolder(array('NAME' => $name, 'XML_ID' => $xmlID, 'CREATED_BY' => SystemUser::SYSTEM_USER_ID), array(), true);
 }
Пример #22
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));
 }
Пример #23
0
 public static function getMapReferenceAttributes()
 {
     return array('ROOT_OBJECT' => Folder::className());
 }
 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)));
 }
Пример #25
0
 /**
  * Returns path to list folder.
  * @param Folder $folder Target folder.
  * @return string
  */
 public function getPathFolderList(Folder $folder)
 {
     if ($folder->getStorage()->getRootObjectId() == $folder->getId()) {
         return $folder->getStorage()->getProxyType()->getBaseUrlFolderList();
     }
     $crumbs = implode('/', CrumbStorage::getInstance()->getByObject($folder));
     if ($crumbs) {
         $crumbs .= '/';
     }
     $crumbs .= $folder->getName();
     return $folder->getStorage()->getProxyType()->getBaseUrlFolderList() . $crumbs;
 }
Пример #26
0
 /**
  * Restores object from trash can.
  * @param int $restoredBy Id of user (or SystemUser::SYSTEM_USER_ID).
  * @return bool
  */
 public function restore($restoredBy)
 {
     $this->errorCollection->clear();
     $needRecalculate = $this->deletedType == ObjectTable::DELETED_TYPE_CHILD;
     $status = parent::restoreNonRecursive($restoredBy);
     if ($status && $needRecalculate) {
         $this->recalculateDeletedTypeAfterRestore($restoredBy);
     }
     if ($status) {
         Driver::getInstance()->sendChangeStatusToSubscribers($this);
     }
     return $status;
 }
Пример #27
0
 public static function GetFolderModel($siteId = SITE_ID)
 {
     if (!self::Enabled()) {
         return false;
     }
     $storageModel = self::GetStorageModel($siteId);
     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, '=XML_ID' => 'VI_CALLS'));
     if (!$folderModel) {
         // Access codes
         $rightsManager = \Bitrix\Disk\Driver::getInstance()->getRightsManager();
         $fullAccessTaskId = $rightsManager->getTaskIdByName($rightsManager::TASK_FULL);
         $rights = $rightsManager->getAllListNormalizeRights($storageModel->getRootObject());
         $accessCodes = array();
         foreach ($rights as $right) {
             $accessCodes[] = array('ACCESS_CODE' => $right['ACCESS_CODE'], 'TASK_ID' => $right['TASK_ID'], 'NEGATIVE' => 1);
         }
         $accessCodes[] = array('ACCESS_CODE' => 'G1', 'TASK_ID' => $fullAccessTaskId);
         // Folder name
         $dbSite = CSite::GetByID($siteId);
         $arSite = $dbSite->Fetch();
         IncludeModuleLangFile(__FILE__, $arSite && isset($arSite['LANGUAGE_ID']) ? $arSite['LANGUAGE_ID'] : false);
         $folderModel = $storageModel->addFolder(array('NAME' => GetMessage('VI_DISK_CALL_RECORD_SECTION'), 'XML_ID' => 'VI_CALLS', 'CREATED_BY' => \Bitrix\Disk\SystemUser::SYSTEM_USER_ID), $accessCodes);
         if (!$folderModel) {
             if ($storageModel->getErrorByCode(\Bitrix\Disk\Folder::ERROR_NON_UNIQUE_NAME)) {
                 $folderModel = \Bitrix\Disk\Folder::load(array('STORAGE_ID' => $storageModel->getId(), 'PARENT_ID' => $storageModel->getRootObjectId(), 'TYPE' => \Bitrix\Disk\Internals\ObjectTable::TYPE_FOLDER, 'NAME' => GetMessage('VI_DISK_CALL_RECORD_SECTION')));
                 $folderModel->changeXmlId('VI_CALLS');
             } else {
                 $folderModel = $storageModel->addFolder(array('NAME' => GetMessage('VI_DISK_CALL_RECORD_SECTION'), 'XML_ID' => 'VI_CALLS', 'CREATED_BY' => \Bitrix\Disk\SystemUser::SYSTEM_USER_ID), $accessCodes, true);
             }
         }
     }
     return $folderModel;
 }
Пример #28
0
	public function Execute()
	{
		if (!CModule::IncludeModule("disk"))
			return CBPActivityExecutionStatus::Closed;

		$groupId = (int)$this->GroupId;
		$files = $this->Files;
		$folderName = \Bitrix\Disk\Ui\Text::correctFolderName($this->FolderName);

		$storage = \Bitrix\Disk\Driver::getInstance()->getStorageByGroupId($groupId);
		if (!$storage)
		{
			$storage = \Bitrix\Disk\Driver::getInstance()->addGroupStorage($groupId);
		}

		if (!$storage)
		{
			return CBPActivityExecutionStatus::Closed;
		}

		$folder = null;
		if (strlen($folderName) > 0)
		{
			$targetFolder = \Bitrix\Disk\Folder::load(array('=NAME' => $folderName,
				'STORAGE_ID' => $storage->getId(),
				'PARENT_ID' => $storage->getRootObjectId()
			));

			if ($targetFolder)
			{
				$folder = $targetFolder;
			}
			else
			{
				$folder = $storage->addFolder(array(
					'NAME' => $folderName,
					'CREATED_BY' => \Bitrix\Disk\SystemUser::SYSTEM_USER_ID
				), array(), true);
			}
		}

		if (!$folder)
		{
			$folder = $storage->getRootObject();
		}

		foreach ($files as $file)
		{
			if (!(int)$file)
				continue;

			$fileArray = CFile::MakeFileArray($file);
			if (!is_array($fileArray))
				continue;

			$folder->uploadFile($fileArray, array(
					'NAME' => $fileArray['name'],
					'CREATED_BY' => \Bitrix\Disk\SystemUser::SYSTEM_USER_ID,
				), array(), true
			);
		}

		return CBPActivityExecutionStatus::Closed;
	}
Пример #29
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();
 }
Пример #30
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;
 }