• Модуль: seo
  • Путь к файлу: ~/bitrix/modules/seo/lib/Sitemap/Generator.php
  • Класс: BitrixSeoSitemapGenerator
  • Вызов: Generator::runForum
protected function runForum(): bool
{
	$result = true;

	$timeFinish = self::getTimeFinish();
	$isFinished = false;
	$runtimeForum = false;
	$currentForum = null;
	$forumId = 0;
	$sitemapFile = null;
	$dbTopicResult = null;
	$arTopic = null;

	while (!$isFinished && microtime(true) <= $timeFinish && CModule::IncludeModule("forum"))
	{
		if (!$runtimeForum)
		{
			$dbRes = RuntimeTable::getList([
				'order' => ['ID' => 'ASC'],
				'filter' => [
					'PID' => $this->sitemapId,
					'ITEM_TYPE' => RuntimeTable::ITEM_TYPE_FORUM,
					'PROCESSED' => RuntimeTable::UNPROCESSED,
				],
				'limit' => 1,
			]);
			$runtimeForum = $dbRes->fetch();

			if ($runtimeForum)
			{
				$forumId = intval($runtimeForum['ITEM_ID']);

				$db_res = CForumNew::GetListEx(
					[],
					[
						'ID' => $forumId,
						"ACTIVE" => "Y",
						"SITE_ID" => $this->sitemapData['SITE_ID'],
						"!TOPICS" => 0,
					]
				);
				$currentForum = $db_res->Fetch();
				if (!$currentForum)
				{
					RuntimeTable::update($runtimeForum['ID'], [
						'PROCESSED' => RuntimeTable::PROCESSED,
					]);
					$this->statusMessage = Loc::getMessage(
						'SITEMAP_RUN_FORUM_NAME',
						['#FORUM_NAME#' => $currentForum['NAME']]
					);
				}
				else
				{
					$fileName = str_replace('#FORUM_ID#', $forumId, $this->sitemapData['SETTINGS']['FILENAME_FORUM']);
					$sitemapFile = new FileRuntime($this->sitemapId, $fileName, $this->getSitemapSettings());
				}
			}
		}

		if (!$runtimeForum || !$sitemapFile)
		{
			$isFinished = true;
		}
		elseif (is_array($currentForum))
		{
			$isActive =
				array_key_exists($forumId, $this->sitemapData['SETTINGS']['FORUM_TOPIC'])
				&& $this->sitemapData['SETTINGS']['FORUM_TOPIC'][$forumId] == "Y"
			;
			if ($isActive)
			{
				if ($dbTopicResult == null)
				{
					$dbTopicResult = CForumTopic::GetList(
						["LAST_POST_DATE" => "DESC"],
						array_merge(
							[
								"FORUM_ID" => $forumId,
								"APPROVED" => "Y",
							],
							(
							$this->state['FORUM_CURRENT_TOPIC'] > 0
								? [">ID" => $this->state["FORUM_CURRENT_TOPIC"]]
								: []
							)
						),
						false,
						0,
						['nTopCount' => 100]
					);
				}
				if (($arTopic = $dbTopicResult->fetch()) && $arTopic)
				{
					$this->state["FORUM_CURRENT_TOPIC"] = $arTopic["ID"];
					$url = CForumNew::PreparePath2Message(
						$currentForum["PATH2FORUM_MESSAGE"],
						[
							"FORUM_ID" => $currentForum["ID"],
							"TOPIC_ID" => $arTopic["ID"],
							"TITLE_SEO" => $arTopic["TITLE_SEO"],
							"MESSAGE_ID" => "s",
							"SOCNET_GROUP_ID" => $arTopic["SOCNET_GROUP_ID"],
							"OWNER_ID" => $arTopic["OWNER_ID"],
							"PARAM1" => $arTopic["PARAM1"],
							"PARAM2" => $arTopic["PARAM2"],
						]
					);
					$sitemapFile->addIBlockEntry($url, MakeTimeStamp($arTopic['LAST_POST_DATE']));
				}
			}
			else
			{
				$url = CForumNew::PreparePath2Message(
					$currentForum["PATH2FORUM_MESSAGE"],
					[
						"FORUM_ID" => $currentForum["ID"],
						"TOPIC_ID" => $currentForum["TID"],
						"TITLE_SEO" => $currentForum["TITLE_SEO"],
						"MESSAGE_ID" => "s",
						"SOCNET_GROUP_ID" => $currentForum["SOCNET_GROUP_ID"],
						"OWNER_ID" => $currentForum["OWNER_ID"],
						"PARAM1" => $currentForum["PARAM1"],
						"PARAM2" => $currentForum["PARAM2"],
					]
				);
				$sitemapFile->addIBlockEntry($url, MakeTimeStamp($currentForum['LAST_POST_DATE']));
			}
			if (empty($arTopic))
			{
				RuntimeTable::update($runtimeForum['ID'], [
					'PROCESSED' => RuntimeTable::PROCESSED,
				]);

				if ($sitemapFile->isNotEmpty())
				{
					if ($sitemapFile->isCurrentPartNotEmpty())
					{
						$sitemapFile->finish();
					}
					else
					{
						$sitemapFile->delete();
					}

					if (!is_array($this->state['XML_FILES']))
					{
						$this->state['XML_FILES'] = [];
					}

					$xmlFiles = $sitemapFile->getNameList();
					$directory = $sitemapFile->getPathDirectory();
					foreach ($xmlFiles as &$xmlFile)
					{
						$xmlFile = $directory . $xmlFile;
					}
					$this->state['XML_FILES'] = array_unique(array_merge($this->state['XML_FILES'], $xmlFiles));
				}
				else
				{
					$sitemapFile->delete();
				}

				$runtimeForum = false;
				$dbTopicResult = null;
				$this->state['FORUM_CURRENT_TOPIC'] = 0;
			}
		}
	}
	if ($this->step < Step::STEPS[Step::STEP_FORUM] - 1)
	{
		$this->step++;
	}

	if ($isFinished)
	{
		$this->step = Step::STEPS[Step::STEP_FORUM];
		$this->statusMessage = Loc::getMessage('SITEMAP_RUN_FINALIZE');
	}

	return $result;
}