示例#1
0
 public static function checkFields(Result $result, $primary, array $data)
 {
     if ($result instanceof Entity\AddResult) {
         if (isset($data['REAL_OBJECT_ID']) && isset($data['FILE_ID']) && !empty($data['REAL_OBJECT_ID']) && !empty($data['FILE_ID']) && $data['REAL_OBJECT_ID'] != $data['ID']) {
             $field = static::getEntity()->getField('FILE_ID');
             $result->addError(new FieldError($field, Loc::getMessage("DISK_OBJECT_ENTITY_ERROR_LINK_FILE_ID", array("#FIELD#" => $field->getTitle()))));
         }
         if (isset($data['FILE_ID']) && empty($data['REAL_OBJECT_ID']) && empty($data['FILE_ID'])) {
             $field = static::getEntity()->getField('FILE_ID');
             $result->addError(new FieldError($field, Loc::getMessage("DISK_OBJECT_ENTITY_ERROR_REQUIRED_FILE_ID", array("#FIELD#" => $field->getTitle()))));
         }
     }
     parent::checkFields($result, $primary, $data);
 }
示例#2
0
 protected function processActionShowObjectInGrid()
 {
     if (!$this->checkRequiredGetParams(array('objectId'))) {
         $this->sendJsonErrorResponse();
     }
     /** @var Folder|File $object */
     $object = BaseObject::loadById((int) $this->request->getQuery('objectId'), array('STORAGE'));
     if (!$object) {
         $this->errorCollection->addOne(new Error('Could not find file or folder', self::ERROR_COULD_NOT_FIND_FILE));
         $this->sendJsonErrorResponse();
     }
     $storage = $object->getStorage();
     $securityContext = $storage->getCurrentUserSecurityContext();
     if (!$object->canRead($securityContext)) {
         $this->errorCollection->addOne(new Error('Could not find file or folder', self::ERROR_COULD_NOT_READ_FILE));
         $this->sendJsonErrorResponse();
     }
     $gridOptions = new Internals\Grid\FolderListOptions($storage);
     $pageSize = $gridOptions->getPageSize();
     $parameters = array('select' => array('ID'), 'filter' => array('PARENT_ID' => $object->getParentId(), 'DELETED_TYPE' => ObjectTable::DELETED_TYPE_NONE), 'order' => $gridOptions->getOrderForOrm(), 'limit' => $pageSize);
     $countQuery = new Query(ObjectTable::getEntity());
     $countQuery->addSelect(new ExpressionField('CNT', 'COUNT(1)'));
     $countQuery->setFilter($parameters['filter']);
     $totalCount = $countQuery->setLimit(null)->setOffset(null)->exec()->fetch();
     $totalCount = $totalCount['CNT'];
     $pageCount = ceil($totalCount / $pageSize);
     $driver = Driver::getInstance();
     $finalPage = null;
     for ($pageNumber = 1; $pageNumber <= $pageCount; $pageNumber++) {
         $fullParameters = $driver->getRightsManager()->addRightsCheck($securityContext, $parameters, array('ID', 'CREATED_BY'));
         $fullParameters['offset'] = $pageSize * ($pageNumber - 1);
         $query = ObjectTable::getList($fullParameters);
         while ($row = $query->fetch()) {
             if ($row['ID'] == $object->getId()) {
                 $finalPage = $pageNumber;
                 break;
             }
         }
         if ($finalPage !== null) {
             break;
         }
     }
     $finalPage = $finalPage ?: 1;
     $command = $this->request->getQuery('cmd') ?: '';
     if ($command) {
         $command = '!' . $command;
     }
     LocalRedirect($driver->getUrlManager()->getPathInListing($object) . "?&pageNumber={$finalPage}#hl-" . $object->getId() . $command);
 }
示例#3
0
 public static function getMap()
 {
     return array('ID' => array('data_type' => 'integer', 'primary' => true, 'autocomplete' => true), 'USER_ID' => array('data_type' => 'integer', 'required' => true), 'STORAGE_ID' => array('data_type' => 'integer', 'required' => true), 'OBJECT_ID' => array('data_type' => 'integer', 'required' => true), 'TYPE' => array('data_type' => 'enum', 'values' => ObjectTable::getListOfTypeValues(), 'required' => true), 'CREATE_TIME' => array('data_type' => 'datetime', 'required' => true, 'default_value' => new DateTime()));
 }
示例#4
0
 public static function add(array $data)
 {
     $data['TYPE'] = static::TYPE_FOLDER;
     return parent::add($data);
 }
示例#5
0
 public static function GetMaxFileId($chatId)
 {
     $maxId = 0;
     if (!self::Enabled()) {
         return $maxId;
     }
     if (intval($chatId) <= 0) {
         return $maxId;
     }
     $folderModel = self::GetFolderModel($chatId);
     if (!$folderModel) {
         return $maxId;
     }
     $result = \Bitrix\Disk\Internals\ObjectTable::getList(array('select' => array('MAX_ID'), 'filter' => array('PARENT_ID' => $folderModel->getId(), 'TYPE' => \Bitrix\Disk\Internals\ObjectTable::TYPE_FILE), 'runtime' => array('MAX_ID' => array('data_type' => 'integer', 'expression' => array('MAX(ID)')))));
     if ($data = $result->fetch()) {
         $maxId = $data['MAX_ID'];
     }
     return intval($maxId);
 }
示例#6
0
 private function getBreadcrumbs(BaseObject $object)
 {
     $parentId = $object->isLink() ? $object->getParentId() : $object->getRealObject()->getParentId();
     $realId = $object->isLink() ? $object->getId() : $object->getRealObject()->getId();
     if (isset($this->cacheBreadcrumbs[$parentId])) {
         if ($object instanceof File) {
             return $this->cacheBreadcrumbs[$parentId] . '/' . $object->getName();
         }
         $this->cacheBreadcrumbs[$realId] = $this->cacheBreadcrumbs[$parentId] . '/' . $object->getName();
         if ($object->isLink()) {
             $this->cacheBreadcrumbs[$object->getRealObject()->getId()] = $this->cacheBreadcrumbs[$realId];
         }
     } else {
         if ($parentId == $this->storage->getRootObjectId()) {
             $this->cacheBreadcrumbs[$realId] = '/' . $object->getName();
             if ($object->isLink()) {
                 if (!$object->getRealObject()) {
                     return null;
                 }
                 $this->cacheBreadcrumbs[$object->getRealObject()->getId()] = $this->cacheBreadcrumbs[$realId];
             }
             return $this->cacheBreadcrumbs[$realId];
         }
         $path = '';
         $parents = ObjectTable::getAncestors($realId, array('select' => array('ID', 'NAME', 'TYPE', 'CODE')));
         while ($parent = $parents->fetch()) {
             if ($parent['CODE'] == Folder::CODE_FOR_UPLOADED_FILES) {
                 //todo hack. CODE_FOR_UPLOADED_FILES
                 return null;
             }
             if ($this->storage->getRootObjectId() == $parent['ID']) {
                 continue;
             }
             $path .= '/' . $parent['NAME'];
             if (!isset($this->cacheBreadcrumbs[$parent['ID']])) {
                 $this->cacheBreadcrumbs[$parent['ID']] = $path;
             }
         }
         if (isset($this->cacheBreadcrumbs[$parentId])) {
             $this->cacheBreadcrumbs[$realId] = $this->cacheBreadcrumbs[$parentId];
             if ($object->isLink()) {
                 $this->cacheBreadcrumbs[$object->getRealObject()->getId()] = $this->cacheBreadcrumbs[$realId];
             }
         } else {
             $this->cacheBreadcrumbs[$realId] = null;
         }
     }
     return $this->cacheBreadcrumbs[$realId];
 }
示例#7
0
 private function resolvePath(Storage $storage, $path, $lookUpFromFolderId, $lastPart = FolderTable::TYPE_FOLDER)
 {
     Diag::getInstance()->collectDebugInfo('urlmanager');
     $path = trim($path, '/');
     $relativeItems = array();
     if ($path == 'index.php' || !$path) {
         if ($lastPart == FolderTable::TYPE_FILE) {
             return null;
         }
         //by default we show root folder.
         return array('STORAGE' => $storage, 'OBJECT_ID' => $storage->getRootObjectId(), 'RELATIVE_PATH' => '/', 'RELATIVE_ITEMS' => array());
     }
     $filter = array('TYPE' => FolderTable::TYPE_FOLDER, 'STORAGE_ID' => $storage->getId());
     if ($lookUpFromFolderId !== null) {
         $filter['PARENT_ID'] = $lookUpFromFolderId;
     }
     $partsOfPath = explode('/', $path);
     if (end($partsOfPath) == 'index.php') {
         array_pop($partsOfPath);
     }
     foreach ($partsOfPath as $i => $pieceOfPath) {
         if ($i === count($partsOfPath) - 1) {
             if ($lastPart !== null) {
                 $filter['TYPE'] = $lastPart;
             } else {
                 unset($filter['TYPE']);
             }
         }
         $filter['=NAME'] = $pieceOfPath;
         $folder = ObjectTable::getList(array('filter' => $filter, 'select' => array('ID', 'NAME', 'REAL_OBJECT_ID', 'STORAGE_ID', 'PARENT_ID')))->fetch();
         if (!$folder) {
             return null;
         }
         if ($folder['REAL_OBJECT_ID']) {
             $filter['PARENT_ID'] = $folder['REAL_OBJECT_ID'];
             unset($filter['STORAGE_ID']);
         } else {
             $filter['PARENT_ID'] = $folder['ID'];
             $filter['STORAGE_ID'] = $folder['STORAGE_ID'];
         }
         $lookUpFromFolderId = $folder['ID'];
         $relativeItems[] = array('ID' => $folder['ID'], 'NAME' => $pieceOfPath);
     }
     unset($pieceOfPath);
     Diag::getInstance()->logDebugInfo('urlmanager');
     return array('STORAGE' => $storage, 'OBJECT_ID' => $lookUpFromFolderId, 'RELATIVE_PATH' => implode('/', $partsOfPath), 'RELATIVE_ITEMS' => $relativeItems);
 }
示例#8
0
 /**
  * Gets all fields (DataManager fields).
  * @return array
  */
 public function getDataManagerFields()
 {
     return ObjectTable::getMap();
 }
示例#9
0
 private function fillChildren()
 {
     if ($this->object instanceof File) {
         return;
     }
     $specificRightsByObjectId = array($this->object->getId() => $this->specificRights);
     //store all rights on object (all inherited rights)
     $inheritedRightsByObjectId = array($this->object->getId() => $this->getParentRights());
     $childrenRights = Driver::getInstance()->getRightsManager()->getDescendantsRights($this->object->getId());
     if (!$childrenRights) {
         SimpleRightTable::fillDescendants($this->object->getId());
         return;
     }
     //store all specific rights on object
     foreach ($childrenRights as $right) {
         if (!isset($specificRightsByObjectId[$right['OBJECT_ID']])) {
             $specificRightsByObjectId[$right['OBJECT_ID']] = array();
         }
         $specificRightsByObjectId[$right['OBJECT_ID']][] = $right;
     }
     unset($right, $childrenRights);
     $simpleRightsByObjectId = array($this->object->getId() => $this->simpleRights);
     $query = ObjectTable::getDescendants($this->object->getId(), array('select' => array('ID', 'PARENT_ID')));
     while ($object = $query->fetch()) {
         //specific rights on object
         if (!isset($specificRightsByObjectId[$object['ID']])) {
             $specificRightsByObjectId[$object['ID']] = array();
         }
         if (!isset($inheritedRightsByObjectId[$object['ID']])) {
             $inheritedRightsByObjectId[$object['ID']] = array();
         }
         if (!isset($simpleRightsByObjectId[$object['PARENT_ID']])) {
             $simpleRightsByObjectId[$object['PARENT_ID']] = array();
         }
         if (isset($inheritedRightsByObjectId[$object['PARENT_ID']])) {
             $inheritedRightsByObjectId[$object['ID']] = array_merge($inheritedRightsByObjectId[$object['PARENT_ID']], $specificRightsByObjectId[$object['PARENT_ID']] ?: array());
         } else {
             $inheritedRightsByObjectId[$object['PARENT_ID']] = array();
         }
         $simpleRightsByObjectId[$object['ID']] = $this->uniqualizeSimpleRights($this->getNewSimpleRight($specificRightsByObjectId[$object['ID']], $inheritedRightsByObjectId[$object['ID']], $simpleRightsByObjectId[$object['PARENT_ID']]));
         $items = array();
         foreach ($simpleRightsByObjectId[$object['ID']] as $right) {
             $items[] = array('OBJECT_ID' => $object['ID'], 'ACCESS_CODE' => $right['ACCESS_CODE']);
         }
         unset($right);
         SimpleRightTable::insertBatch($items);
     }
     unset($object);
 }
示例#10
0
 /**
  * Tells if name is not unique in object.
  * @param string $name Name.
  * @param int $underObjectId Id of parent object.
  * @param null $excludeId Id which will be excluded from query.
  * @param null &$opponentId Opponent object which has same name.
  * @return bool
  * @throws \Bitrix\Main\ArgumentException
  */
 public static function isUniqueName($name, $underObjectId, $excludeId = null, &$opponentId = null)
 {
     $opponent = ObjectTable::getList(array('select' => array('ID'), 'filter' => array('!ID' => $excludeId, 'PARENT_ID' => $underObjectId, '=NAME' => $name), 'limit' => 1))->fetch();
     if (!$opponent) {
         return true;
     }
     $opponentId = $opponent['ID'];
     return false;
 }