• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/sharing.php
  • Класс: BitrixDiskSharing
  • Вызов: Sharing::approve
public function approve(array $data = array())
{
	$this->errorCollection->clear();

	if($this->isApproved())
	{
		return true;
	}

	if($this->isDeclined())
	{
		return false;
	}

	if($this->isToDepartmentParent())
	{
		return true;
	}

	$targetStorage = $this->getTargetStorageByToEntity();
	if(!$targetStorage)
	{
		$this->errorCollection->addOne(
			new Error(
				Loc::getMessage('DISK_SHARING_MODEL_ERROR_COULD_NOT_FIND_STORAGE'),
				self::ERROR_COULD_NOT_FIND_STORAGE
			)
		);
		return false;
	}

	$realObject = $this->getRealObject();
	if (!$realObject || !$realObject->getStorage())
	{
		$this->errorCollection[] = new Error('Could not find real object');

		return false;
	}

	$linkModel = null;
	if($this->isToUser() || $this->isToGroup() || $this->isToDepartmentChild())
	{
		$linkName = empty($data['LINK_NAME'])? null : $data['LINK_NAME'];
		if(
			!$linkName &&
			$realObject->isRoot() &&
			$realObject->getStorage()->getProxyType() instanceof ProxyTypeGroup
		)
		{
			$linkName = UiText::correctFolderName($realObject->getStorage()->getProxyType()->getEntityTitle());
		}

		if($realObject instanceof Folder)
		{
			$linkModel = $targetStorage->addFolderLink($realObject, array(
				'NAME' => $linkName,
				'CREATED_BY' => $this->createdBy
			), array(), true);
		}
		elseif($realObject instanceof File)
		{
			$linkModel = $targetStorage->addFileLink($realObject, array(
				'NAME' => $linkName,
				'CREATED_BY' => $this->createdBy
			), array(), true);
		}
	}

	if(!$linkModel)
	{
		$this->errorCollection->addOne(
			new Error(
				Loc::getMessage('DISK_SHARING_MODEL_ERROR_COULD_NOT_CREATE_LINK'),
				self::ERROR_COULD_NOT_CREATE_LINK
			)
		);
		$this->errorCollection->add($targetStorage->getErrors());
		return false;
	}

	$success = $this->update(array(
		'LINK_OBJECT_ID' => $linkModel->getId(),
		'LINK_STORAGE_ID' => $linkModel->getStorageId(),
		'STATUS' => SharingTable::STATUS_IS_APPROVED,
	));
	if(!$success)
	{
		return false;
	}
	$this->linkObject = $linkModel;

	[, $tag] = $this->getNotifyTags();
	if(Loader::includeModule('im'))
	{
		CIMNotify::deleteByTag($tag);
	}


	return true;
}