• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/rest.php
  • Класс: CSocNetLogRestService
  • Вызов: CSocNetLogRestService::deleteGroupSubject
static function deleteGroupSubject($arFields): bool
{
	$subjectId = $arFields['SUBJECT_ID'] ?? null;

	if ((int)$subjectId <= 0)
	{
		throw new ArgumentException('Wrong group subject ID');
	}

	$arFilter = [
		'ID' => $subjectId,
	];

	$dbRes = CSocNetGroupSubject::getList(array(), $arFilter);
	$arGroupSubject = $dbRes->fetch();
	if (!is_array($arGroupSubject))
	{
		throw new ObjectNotFoundException('Socialnetwork group subject not found');
	}

	$resSites = CSocNetGroupSubject::getSite($arGroupSubject['ID']);
	while ($siteFields = $resSites->fetch())
	{
		$count = CSocNetGroupSubject::getList(
			[],
			[
				'SITE_ID' => $siteFields['LID']
			],
			[] // count
		);
		if ($count <= 1)
		{
			throw new SystemException('Cannot delete the sole group subject for site ('.$siteFields['LID'].')');
		}
	}

	if (!self::isCurrentUserAdmin())
	{
		throw new AccessDeniedException('User has no permissions to delete group subject');
	}

	if (!CSocNetGroupSubject::delete($arGroupSubject["ID"]))
	{
		throw new SystemException('Cannot delete group subject');
	}

	return true;
}