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

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

	if(
		$withDeletingObject &&
		($this->isToUser() || $this->isToGroup() || $this->isToDepartmentChild())
	)
	{
		$linkModel = $this->getLinkObject();
		if($linkModel instanceof FolderLink)
		{
			$linkModel->deleteTree($declinedBy);
		}
		elseif($linkModel instanceof FileLink)
		{
			$linkModel->deleteWithoutSharing($declinedBy);
		}
	}

	$success = $this->update(array(
		'LINK_OBJECT_ID' => null,
		'LINK_STORAGE_ID' => null,
		'STATUS' => SharingTable::STATUS_IS_DECLINED,
	));
	if(!$success)
	{
		return false;
	}

	foreach($this->getChildren() as $childSharing)
	{
		$childSharing->decline($declinedBy, $withDeletingObject);
	}
	unset($childSharing);

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

	if($this->isToUser() || $this->isToGroup() || $this->isToDepartmentParent())
	{
		$rightsManager = Driver::getInstance()->getRightsManager();
		$rightsManager->deleteByDomain($this->getRealObject(), $rightsManager->getSharingDomain($this->id));

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

	if(
		$this->isToUser() &&
		!$this->isToDepartmentChild() &&
		self::CODE_USER . $declinedBy === $this->toEntity &&
		$this->fromEntity !== $this->toEntity
	)
	{
		$isFolder = $this->getRealObject() instanceof Folder;
		$message = Loc::getMessage(
			$isFolder? 'DISK_SHARING_MODEL_TEXT_SELF_DISCONNECT' : 'DISK_SHARING_MODEL_TEXT_SELF_DISCONNECT_FILE',
			array(
				'#NAME#' => $this->getRealObject()->getName(),
				'#USERNAME#' => User::loadById($declinedBy)->getFormattedName(),
			)
		);
		[$subTag, $tag] = $this->getNotifyTags();
		Driver::getInstance()->sendNotify($this->createdBy, array(
			'FROM_USER_ID' => $declinedBy,
			'NOTIFY_EVENT' => 'sharing',
			'NOTIFY_TAG' => $tag,
//			'NOTIFY_SUB_TAG' => $subTag,
			'NOTIFY_MESSAGE' => $message,
			'NOTIFY_MESSAGE_OUT' => strip_tags($message),
		));
	}

	return true;
}