• Модуль: landing
  • Путь к файлу: ~/bitrix/modules/landing/lib/agent.php
  • Класс: BitrixLandingAgent
  • Вызов: Agent::removeBadDomain
static function removeBadDomain(): string
{
	$maxFailCount = 7;

	Rights::setGlobalOff();

	// only custom domain
	$filterDomains = array_map(function($domain)
	{
		return '%.' . $domain;
	}, Domain::B24_DOMAINS);
	$filterDomains[] = '%' . Manager::getHttpHost();

	$customDomainExist = false;
	$resDomain = Domain::getList([
		'select' => [
			'ID', 'DOMAIN', 'FAIL_COUNT'
		],
		'filter' => [
			'!DOMAIN' => $filterDomains
		],
		'limit' => 5,
		'order' => [
			'DATE_MODIFY' => 'asc'
		]
	]);
	while ($domain = $resDomain->fetch())
	{
		$customDomainExist = true;
		if (DomainRegister::isDomainActive($domain['DOMAIN']))
		{
			Domain::update($domain['ID'], [
				'FAIL_COUNT' => null
			])->isSuccess();
		}
		else
		{
			// remove domain
			if ($domain['FAIL_COUNT'] >= $maxFailCount - 1)
			{
				// wee need site for randomize domain
				$resSite = Site::getList([
					'select' => [
						'ID', 'DOMAIN_ID', 'DOMAIN_NAME' => 'DOMAIN.DOMAIN'
					],
					'filter' => [
						'DOMAIN_ID' => $domain['ID']
					]
				]);
				if ($rowSite = $resSite->fetch())
				{
					Debug::log('removeBadDomain-randomizeDomain', var_export($rowSite, true));
					Site::randomizeDomain($rowSite['ID']);
				}
				// site not exist, delete domain
				/*else
				{
					Debug::log('removeBadDomain-Domain::delete', var_export($rowSite, true));
					Domain::delete($domain['ID'])->isSuccess();
				}*/
			}
			else
			{
				Domain::update($domain['ID'], [
					'FAIL_COUNT' => intval($domain['FAIL_COUNT']) + 1
				])->isSuccess();
			}
		}
	}

	Rights::setGlobalOn();

	return $customDomainExist ? __CLASS__ . '::' . __FUNCTION__ . '();' : '';
}