• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/wizard_site.php
  • Класс: CWizard
  • Вызов: CWizard::__InstallTemplate
function __InstallTemplate($templateID)
{
	if (!array_key_exists($templateID, $this->arTemplates))
		return;

	//Copy template
	$canCopyTemplate = !(
		file_exists($_SERVER["DOCUMENT_ROOT"].BX_PERSONAL_ROOT."/templates/".$templateID) &&
		isset($this->arTemplates[$templateID]["REWRITE"]) && $this->arTemplates[$templateID]["REWRITE"] == "N"
	);

	//If the main module was not included
	require_once($_SERVER['DOCUMENT_ROOT']."/bitrix/modules/main/include.php");

	if ($canCopyTemplate)
	{
		CopyDirFiles(
			$_SERVER["DOCUMENT_ROOT"].$this->__GetTemplatesPath()."/".$templateID,
			$_SERVER["DOCUMENT_ROOT"].BX_PERSONAL_ROOT."/templates/".$templateID,
			$rewrite = true,
			$recursive = true
		);
	}

	//Attach template to default site
	$obSite = CSite::GetList("def", "desc", Array("ACTIVE" => "Y"));
	if ($arSite = $obSite->Fetch())
	{
		$arTemplates = Array();
		$found = false;
		$obTemplate = CSite::GetTemplateList($arSite["LID"]);
		while($arTemplate = $obTemplate->Fetch())
		{
			if(!$found && trim($arTemplate["CONDITION"]) == '')
			{
				$arTemplate["TEMPLATE"] = $templateID;
				$found = true;
			}
			$arTemplates[]= $arTemplate;
		}

		if (!$found)
			$arTemplates[]= Array("CONDITION" => "", "SORT" => 150, "TEMPLATE" => $templateID);

		$arFields = Array(
			"TEMPLATE" => $arTemplates,
			"NAME" => $arSite["NAME"],
		);

		$obSite = new CSite();
		$obSite->Update($arSite["LID"], $arFields);
	}

	//Copy files
	$this->__MoveDirFiles($this->arTemplates[$templateID]);
}