/** * Gets fields which Externalizer or Internalizer should modify. * @return array */ public function getFieldsForMap() { return array('ENTITY_TYPE' => array('IN' => function ($externalValue) { switch ($externalValue) { case 'user': return ProxyType\User::className(); case 'group': return ProxyType\Group::className(); case 'common': return ProxyType\Common::className(); } return null; }, 'OUT' => function ($internalValue) { switch ($internalValue) { case ProxyType\User::className(): return 'user'; case ProxyType\Group::className(): return 'group'; case ProxyType\Common::className(): return 'common'; case ProxyType\RestApp::className(): return 'restapp'; } return null; })); }
protected function parsePath($requestUri) { static $storages; if (empty($storages)) { $cache = new \CPHPCache(); if ($cache->initCache(30 * 24 * 3600, 'webdav_disk_common_storage', '/webdav/storage')) { $storages = $cache->getVars(); } else { $storages = \Bitrix\Disk\Storage::getModelList(array('filter' => array('=ENTITY_TYPE' => \Bitrix\Disk\ProxyType\Common::className()))); foreach ($storages as $key => $storage) { $storages[$key] = array('id' => $storage->getEntityId(), 'path' => $storage->getProxyType()->getStorageBaseUrl()); } $cache->startDataCache(); if (defined('BX_COMP_MANAGED_CACHE')) { $taggedCache = \Bitrix\Main\Application::getInstance()->getTaggedCache(); $taggedCache->startTagCache('/webdav/storage'); $taggedCache->registerTag('disk_common_storage'); $taggedCache->endTagCache(); } $cache->endDataCache($storages); } } $patterns = array(array('user', '/(?:company|contacts)/personal/user/(\\d+)/files/lib(.*)$'), array('user', '/(?:company|contacts)/personal/user/(\\d+)/disk/path(.*)$'), array('group', '/workgroups/group/(\\d+)/files(.*)$'), array('group', '/workgroups/group/(\\d+)/disk/path(.*)$')); foreach ($storages as $storage) { $storagePath = trim($storage['path'], '/'); $patterns[] = array('docs', sprintf('^/%s/path(.*)$', $storagePath), $storage['id']); $patterns[] = array('docs', sprintf('^/%s(.*)$', $storagePath), $storage['id']); } // @TODO: aggregator $patterns[] = array('docs', '^/docs/path(.*)$', 'shared_files_s1'); $patterns[] = array('docs', '^/docs(.*)$', 'shared_files_s1'); $type = null; $id = null; $path = null; foreach ($patterns as $pattern) { $matches = array(); if (preg_match('#' . $pattern[1] . '#i', $requestUri, $matches)) { $type = $pattern[0]; list($id, $path) = $type == 'docs' ? array($pattern[2], $matches[1]) : array($matches[1], $matches[2]); break; } } /** @var Storage $storage */ $storage = null; if ($type == 'user') { $storage = Driver::getInstance()->getStorageByUserId((int) $id); } elseif ($type == 'group') { $storage = Driver::getInstance()->getStorageByGroupId((int) $id); } elseif ($type == 'docs') { $storage = Driver::getInstance()->getStorageByCommonId($id); } else { return array(null, null); } $path = static::UrlDecode($path); return array($storage, $path); }
protected function processActionDefault() { $diskSecurityContext = $this->getSecurityContextByUser($this->getUser()); $this->arResult["COMMON_DISK"] = array(); $filterReadableList = array('STORAGE.ENTITY_TYPE' => ProxyType\Common::className()); foreach (Storage::getReadableList($diskSecurityContext, array('filter' => $filterReadableList)) as $storage) { $proxyType = $storage->getProxyType(); if ($storage->getSiteId() != SITE_ID) { continue; } $this->arResult["COMMON_DISK"][$storage->getEntityId()] = array("TITLE" => $proxyType->getEntityTitle(), "URL" => $proxyType->getBaseUrlFolderList(), "ICON" => $proxyType->getEntityImageSrc(64, 64)); } $userId = $this->getUser()->getId(); $storage = Driver::getInstance()->getStorageByUserId($userId); $proxyType = $storage->getProxyType(); $this->arResult["COMMON_DISK"][$storage->getEntityId()] = array("TITLE" => $proxyType->getTitleForCurrentUser(), "URL" => $proxyType->getBaseUrlFolderList(), "ICON" => $proxyType->getEntityImageSrc(64, 64)); $this->arResult["COMMON_DISK"]["GROUP"] = array("TITLE" => Loc::getMessage('DISK_AGGREGATOR_GROUP_TITLE'), "ID" => "bx-disk-aggregator-group-link"); $this->arResult["COMMON_DISK"]["USER"] = array("TITLE" => Loc::getMessage('DISK_AGGREGATOR_USER_TITLE'), "ID" => "bx-disk-aggregator-user-link"); $this->arResult["NETWORK_DRIVE_LINK"] = Driver::getInstance()->getUrlManager()->getHostUrl() . $this->getApplication()->GetCurPage(); $this->includeComponentTemplate(); }
protected function getCommonStorages() { return Storage::getReadableList($this->getSecurityContextByUser($this->getUser()), array('filter' => array('STORAGE.ENTITY_TYPE' => ProxyType\Common::className(), 'STORAGE.SITE_ID' => SITE_ID))); }
/** * Returns common storage by id. * * If you want to find Common storage (default Company docs), you must use $commonId = shared_files_s1. * Else "shared_files_{$siteID}" * * @param string $commonId Id of storage. * @return null|Storage */ public function getStorageByCommonId($commonId) { return Storage::load(array('MODULE_ID' => self::INTERNAL_MODULE_ID, 'ENTITY_TYPE' => ProxyType\Common::className(), 'ENTITY_ID' => $commonId), array('ROOT_OBJECT')); }
$componentPage = "index"; $arParams["RESOURCE_TYPE"] = $arParams["RESOURCE_TYPE"] == "FOLDER" ? "FOLDER" : "IBLOCK"; if ($arParams["RESOURCE_TYPE"] == "IBLOCK") { //$arParams["IBLOCK_TYPE"] $arParams["IBLOCK_ID"] = intVal($arParams["IBLOCK_ID"]); $arParams['CHECK_CREATOR'] = "N"; // only for socnet $arParams['SHOW_TAGS'] = $arParams['SHOW_TAGS'] == "Y" ? "Y" : "N"; if (\Bitrix\Main\Config\Option::get('disk', 'successfully_converted', false) && CModule::includeModule('disk')) { $requestURL = $APPLICATION->GetCurPage(); $arParams["SEF_FOLDER"] = str_replace("\\", "/", $arParams["SEF_FOLDER"]); if ($arParams["SEF_FOLDER"] != "/") { $arParams["SEF_FOLDER"] = "/" . Trim($arParams["SEF_FOLDER"], "/ \t\n\r\v") . "/"; } $currentPageUrl = SubStr($requestURL, StrLen($arParams["SEF_FOLDER"])); $diskStorage = \Bitrix\Disk\Storage::load(array('MODULE_ID' => \Bitrix\Disk\Driver::INTERNAL_MODULE_ID, 'ENTITY_TYPE' => \Bitrix\Disk\ProxyType\Common::className(), 'XML_ID' => (int) $arParams['IBLOCK_ID']), array('ROOT_OBJECT')); if ($diskStorage) { //it means / if (!$currentPageUrl || $currentPageUrl == 'index.php') { if ($arParams["SEF_FOLDER"]) { $arParams["SEF_FOLDER"] = rtrim($arParams["SEF_FOLDER"], '/'); } LocalRedirect($arParams["SEF_FOLDER"] . '/path/'); } $arParams['STORAGE'] = $diskStorage; $componentPage = ''; $arVariablesD = array(); $engine = new CComponentEngine($this); $engine->addGreedyPart("#PATH#"); $engine->addGreedyPart("#FILE_PATH#"); $engine->addGreedyPart("#TRASH_PATH#");
protected function migrateUfHead() { if ($this->isStepFinished(__METHOD__)) { return; } $sqlHelper = $this->connection->getSqlHelper(); $proxyType = $sqlHelper->forSql(ProxyType\Common::className()); $lastId = $this->getStorageId(); $storageQuery = $this->connection->query("\n\t\t\tSELECT\n\t\t\t\tsecta.IBLOCK_ID IBLOCK_ID,\n\t\t\t\ts.ID STORAGE_ID\n\t\t\tFROM b_disk_storage s\n\t\t\t\tINNER JOIN b_disk_object root ON root.ID = s.ROOT_OBJECT_ID\n\t\t\t\tINNER JOIN b_iblock_section secta ON root.WEBDAV_SECTION_ID = secta.ID\n\t\t\tWHERE s.ENTITY_TYPE <> '{$proxyType}' AND s.MODULE_ID = 'disk' AND s.ID > {$lastId} ORDER BY s.ID\n\t\t"); while ($storage = $storageQuery->fetch()) { $this->abortIfNeeded(); $this->migrateCustomUf("IBLOCK_{$storage['IBLOCK_ID']}_SECTION", "DISK_FOLDER_{$storage['STORAGE_ID']}"); $this->migrateCustomUf("IBLOCK_{$storage['IBLOCK_ID']}_FILE", "DISK_FILE_{$storage['STORAGE_ID']}"); // migrate property value to new uf $this->migrateCustomElementProperties($storage['IBLOCK_ID'], "DISK_FILE_{$storage['STORAGE_ID']}"); $this->storeStorageId($storage['STORAGE_ID']); } $this->abortIfNeeded(); //common $storageQuery = $this->connection->query("\n\t\t\tSELECT\n\t\t\t\ts.XML_ID IBLOCK_ID,\n\t\t\t\ts.ID STORAGE_ID\n\t\t\tFROM b_disk_storage s\n\t\t\tWHERE s.ENTITY_TYPE = '{$proxyType}' AND s.MODULE_ID = 'disk'\n\t\t"); while ($storage = $storageQuery->fetch()) { $this->migrateCustomUf("IBLOCK_{$storage['IBLOCK_ID']}_SECTION", "DISK_FOLDER_{$storage['STORAGE_ID']}"); $this->migrateCustomUf("IBLOCK_{$storage['IBLOCK_ID']}_FILE", "DISK_FILE_{$storage['STORAGE_ID']}"); // migrate property value to new uf $this->migrateCustomElementProperties($storage['IBLOCK_ID'], "DISK_FILE_{$storage['STORAGE_ID']}"); } $this->storeStorageId(0); $this->setStepFinished(__METHOD__); }
private static function needProxyToDiskByDocType($documentType) { if (!(\Bitrix\Main\Config\Option::get('disk', 'successfully_converted', false) && CModule::includeModule('disk'))) { return false; } if (empty($documentType)) { return false; } $storage = null; if (substr($documentType, 0, 7) == 'STORAGE') { $storageId = (int) substr($documentType, 8); if ($storageId) { $storage = \Bitrix\Disk\Storage::loadById($storageId); } if ($storage) { return $storage; } } list(, $iblockId) = explode('_', $documentType); if (!$iblockId) { return false; } $storage = \Bitrix\Disk\Storage::load(array('XML_ID' => $iblockId, 'MODULE_ID' => \Bitrix\Disk\Driver::INTERNAL_MODULE_ID, 'ENTITY_TYPE' => \Bitrix\Disk\ProxyType\Common::className())); if (!$storage) { return false; } return $storage; }