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); }
/** * Returns list of storages. * @param array $filter Filter. * @param array $order Order. * @return Disk\Storage[]|null */ protected function getList(array $filter = array(), array $order = array()) { $securityContext = $this->getSecurityContextByUser($this->userId); $internalizer = new Disk\Rest\Internalizer(new Entity\Storage(), $this); $parameters = array_merge(array('with' => array('ROOT_OBJECT'), 'filter' => array_merge(array('=ROOT_OBJECT.PARENT_ID' => null, '=MODULE_ID' => Disk\Driver::INTERNAL_MODULE_ID, '=RIGHTS_CHECK' => true), $internalizer->cleanFilter($filter)), 'runtime' => array(new ExpressionField('RIGHTS_CHECK', 'CASE WHEN ' . $securityContext->getSqlExpressionForList('%1$s', '%2$s') . ' THEN 1 ELSE 0 END', array('ROOT_OBJECT.ID', 'ROOT_OBJECT.CREATED_BY'), array('data_type' => 'boolean'))), 'order' => $order), Disk\Rest\RestManager::getNavData($this->start)); $parameters = Disk\Driver::getInstance()->getRightsManager()->addRightsCheck($securityContext, $parameters, array('ROOT_OBJECT.ID', 'ROOT_OBJECT.CREATED_BY')); $storages = Disk\Storage::getModelList($parameters); if ($storages === null) { $this->errorCollection->addOne(new Error('Could not load list of storages.')); return null; } foreach ($storages as $key => $storage) { if (!$storage->getProxyType() instanceof Disk\ProxyType\Common && !$storage->getProxyType() instanceof Disk\ProxyType\Group && !$storage->getProxyType() instanceof Disk\ProxyType\User) { unset($storages[$key]); } } unset($storage); return $storages; }