- Модуль: wiki
- Путь к файлу: ~/bitrix/modules/wiki/classes/general/wiki.php
- Класс: CWiki
- Вызов: CWiki::RenameLinkOnPages
function RenameLinkOnPages($iBlockId, $oldName, $newName, $iBlockSectId = false)
{
if(!$iBlockId || !$oldName || !$newName)
return false;
$arFilter["IBLOCK_ID"] = $iBlockId;
$arFilter["CHECK_PERMISSIONS"]="N";
if($iBlockSectId)
{
$arFilter["SECTION_ID"] = $iBlockSectId;
$arFilter["INCLUDE_SUBSECTIONS"] = "Y";
}
$count = 0;
$sCatName = '';
$isCategory = CWikiUtils::IsCategoryPage($oldName , $sCatName);
$catSearch = "[[".GetMessage('CATEGORY_NAME').":".$sCatName."]]";
$arPatterns = array(
//link and link_name are equal
array(
"search" => "[[".$oldName."|".$oldName."]]",
"pattern" => "/[[(".preg_quote($oldName).")|(".preg_quote($oldName).")]]/isU".BX_UTF_PCRE_MODIFIER,
"replacement" => "[[".$newName."|".$newName."]]"
),
//link and link_name are different
array(
"search" => "[[".$oldName."|",
"pattern" => "/[[(".preg_quote($oldName).")|(.*)]]/isU".BX_UTF_PCRE_MODIFIER,
"replacement" => "[[".$newName."|$2]]"
),
//exist only link
array(
"search" => "[[".$oldName."]]",
"pattern" => "/[[".preg_quote($oldName)."]]/isU".BX_UTF_PCRE_MODIFIER,
"replacement" => "[[".$newName."]]"
)
);
$dbRes = CIBlockElement::GetList(array(), $arFilter, false, false, array("ID", "NAME", "DETAIL_TEXT"));
while($arElement = $dbRes->GetNext())
{
$bChanged = false;
$newText = $arElement["~DETAIL_TEXT"];
foreach ($arPatterns as $arPattern)
{
if(mb_strpos($newText, $arPattern["search"]) !== false)
{
$newText = preg_replace($arPattern["pattern"], $arPattern["replacement"], $newText);
$bChanged = true;
}
}
if ($isCategory)
if(mb_strpos($newText, $catSearch) !== false)
{
$newText = $this->RenameCategoryOnPage($newText, $sCatName, $newName);
$bChanged = true;
}
if($bChanged)
{
$this->CleanCache($arElement["ID"], $arElement["NAME"], $iBlockId);
$this->cIB_E->Update($arElement["ID"], array("DETAIL_TEXT" => $newText), false, true);
self::MarkPageAsUpdated($iBlockId, $iBlockSectId, $arElement["NAME"]);
$count++;
}
}
return $count;
}