/** * Creates storage in module Disk. * This is core method. If you need to create user storage use Driver::addUserStorage, * if group storage use Driver::addGroupStorage, if common storage use Driver::addCommonStorage. * * @param array $data Array with fields. Necessary: NAME, MODULE_ID, ENTITY_ID, ENTITY_TYPE. * @param array $rights Array of rights. * @throws \Bitrix\Main\SystemException * @throws \Bitrix\Main\ArgumentException * @return null|Storage */ public function addStorage(array $data, array $rights = array()) { $this->errorCollection->clear(); $this->checkRequiredInputParams($data, array('NAME', 'MODULE_ID', 'ENTITY_TYPE', 'ENTITY_ID')); if (isset($data['USE_INTERNAL_RIGHTS']) && !$data['USE_INTERNAL_RIGHTS'] && !empty($rights)) { throw new ArgumentException('Attempt to set the rights, but not to use the internal rights.'); } /** @var Storage $storageModel */ $storageModel = Storage::add($data, $this->errorCollection); if (!$storageModel) { return null; } if ($storageModel->isUseInternalRights()) { Driver::getInstance()->getRightsManager()->setAsNewLeaf($storageModel->getRootObject(), $rights); } return $storageModel; }
/** * @return bool * @throws \Bitrix\Main\NotImplementedException */ protected function deleteInternal() { $this->errorCollection->clear(); /** @var DataManager $tableClassName */ $tableClassName = static::getTableClassName(); $deleteResult = $tableClassName::delete($this->id); if (!$deleteResult->isSuccess()) { $this->errorCollection->add(array(new Error('', self::ERROR_INTERNAL_DELETE))); return false; } return true; }
/** * Recalculate rights after move * @param \Bitrix\Disk\BaseObject|BaseObject $object * @return bool */ public function setAfterMove(BaseObject $object) { $this->errorCollection->clear(); $existsRights = $this->getSpecificRights($object); $rights = $this->cleanWrongNegativeRights($object, $this->uniqualizeRightsOnObject($existsRights)); $this->deleteInternal($object); if (!$this->insertRightsInternal($object, $rights)) { return false; } $simpleBuilder = new SimpleReBuilder($object, $rights); $simpleBuilder->run(); Driver::getInstance()->getIndexManager()->recalculateRights($object); return true; }
/** * Clones uf values from entity and creates new files (copies from attach) to save in new entity. * @param array $attachedIds List of attached objects id. * @param int $userId Id of user. * @internal * @return array */ public function cloneUfValuesFromAttachedObject(array $attachedIds, $userId) { $this->errorCollection->clear(); $userId = (int) $userId; if ($userId <= 0) { $this->errorCollection->addOne(new Error('Invalid $userId')); return null; } $userStorage = Driver::getInstance()->getStorageByUserId($userId); if (!$userStorage) { $this->errorCollection->addOne(new Error("Could not find storage for user {$userId}")); $this->errorCollection->add(Driver::getInstance()->getErrors()); return null; } $folder = $userStorage->getFolderForUploadedFiles(); if (!$folder) { $this->errorCollection->addOne(new Error("Could not create/find folder for upload")); $this->errorCollection->add($userStorage->getErrors()); return null; } $newValues = array(); foreach ($attachedIds as $id) { list($type, $realValue) = FileUserType::detectType($id); if (FileUserType::TYPE_ALREADY_ATTACHED != $type) { continue; } $attachedObject = AttachedObject::loadById($realValue, array('OBJECT')); if (!$attachedObject) { continue; } if (!$attachedObject->canRead($userId)) { continue; } $file = $attachedObject->getFile(); if (!$file) { continue; } $newFile = $file->copyTo($folder, $userId, true); if (!$newFile) { $this->errorCollection->add($file->getErrors()); continue; } $newValues[] = FileUserType::NEW_FILE_PREFIX . $newFile->getId(); } return $newValues; }