static function UpdateStepModules($updatesDir, &$strError, $bSaveUpdaters = false)
{
global $DB;
$strError_tmp = "";
if (!defined("US_SAVE_UPDATERS_DIR") || US_SAVE_UPDATERS_DIR == '')
$bSaveUpdaters = false;
$stime = microtime(true);
$updatesDirFull = $_SERVER["DOCUMENT_ROOT"]."/bitrix/updates/".$updatesDir;
if (!file_exists($updatesDirFull) || !is_dir($updatesDirFull))
$strError_tmp .= "[UUK01] ".str_replace("#FILE#", $updatesDirFull, GetMessage("SUPP_CU_NO_TMP_CAT")).". ";
if ($strError_tmp == '')
if (!is_readable($updatesDirFull))
$strError_tmp .= "[UUK03] ".str_replace("#FILE#", $updatesDirFull, GetMessage("SUPP_CU_RD_TMP_CAT")).". ";
$arModules = array();
if ($strError_tmp == '')
{
$handle = @opendir($updatesDirFull);
if ($handle)
{
while (false !== ($dir = readdir($handle)))
{
if ($dir == "." || $dir == "..")
continue;
if (is_dir($updatesDirFull."/".$dir))
$arModules[] = $dir;
}
closedir($handle);
}
}
if (!is_array($arModules) || empty($arModules))
$strError_tmp .= "[UUK02] ".GetMessage("SUPP_UK_NO_MODS").". ";
if ($strError_tmp == '')
{
for ($i = 0, $cnt = count($arModules); $i < $cnt; $i++)
{
$strError_tmp1 = "";
$updateDirFrom = $updatesDirFull."/".$arModules[$i];
$updateDirTo = $_SERVER["DOCUMENT_ROOT"].US_SHARED_KERNEL_PATH."/modules/".$arModules[$i];
CUpdateClientPartner::__CheckDirPath($updateDirTo."/", true);
if (!file_exists($updateDirTo) || !is_dir($updateDirTo))
$strError_tmp1 .= "[UUK04] ".str_replace("#MODULE_DIR#", $updateDirTo, GetMessage("SUPP_UK_NO_MODIR")).". ";
if ($strError_tmp1 == '')
if (!is_writable($updateDirTo))
$strError_tmp1 .= "[UUK05] ".str_replace("#MODULE_DIR#", $updateDirTo, GetMessage("SUPP_UK_WR_MODIR")).". ";
if ($strError_tmp1 == '')
if (!file_exists($updateDirFrom) || !is_dir($updateDirFrom))
$strError_tmp1 .= "[UUK06] ".str_replace("#DIR#", $updateDirFrom, GetMessage("SUPP_UK_NO_FDIR")).". ";
if ($strError_tmp1 == '')
if (!is_readable($updateDirFrom))
$strError_tmp1 .= "[UUK07] ".str_replace("#DIR#", $updateDirFrom, GetMessage("SUPP_UK_READ_FDIR")).". ";
if ($strError_tmp1 == '')
{
$handle = @opendir($updateDirFrom);
$arUpdaters = array();
if ($handle)
{
while (false !== ($dir = readdir($handle)))
{
if (mb_substr($dir, 0, 7) == "updater")
{
$bPostUpdater = "N";
if (is_file($updateDirFrom."/".$dir))
{
$num = mb_substr($dir, 7, mb_strlen($dir) - 11);
if (mb_substr($dir, mb_strlen($dir) - 9) == "_post.php")
{
$bPostUpdater = "Y";
$num = mb_substr($dir, 7, mb_strlen($dir) - 16);
}
$arUpdaters[] = array("/".$dir, trim($num), $bPostUpdater);
}
elseif (file_exists($updateDirFrom."/".$dir."/index.php"))
{
$num = mb_substr($dir, 7);
if (mb_substr($dir, mb_strlen($dir) - 5) == "_post")
{
$bPostUpdater = "Y";
$num = mb_substr($dir, 7, mb_strlen($dir) - 12);
}
$arUpdaters[] = array("/".$dir."/index.php", trim($num), $bPostUpdater);
}
if ($bSaveUpdaters)
CUpdateClientPartner::__CopyDirFiles($updateDirFrom."/".$dir, $_SERVER["DOCUMENT_ROOT"].US_SAVE_UPDATERS_DIR."/".$arModules[$i]."/".$dir, $strError_tmp1, false);
}
}
closedir($handle);
}
$n = count($arUpdaters);
for ($i1 = 0; $i1 < $n - 1; $i1++)
{
for ($j1 = $i1 + 1; $j1 < $n; $j1++)
{
if (CUpdateClientPartner::__CompareVersions($arUpdaters[$i1][1], $arUpdaters[$j1][1]) > 0)
{
$tmp1 = $arUpdaters[$i1];
$arUpdaters[$i1] = $arUpdaters[$j1];
$arUpdaters[$j1] = $tmp1;
}
}
}
}
if ($strError_tmp1 == '')
{
if ($DB->type == "MYSQL" && defined("MYSQL_TABLE_TYPE") && MYSQL_TABLE_TYPE <> '')
{
$DB->Query("SET storage_engine = '".MYSQL_TABLE_TYPE."'", true);
}
}
if ($strError_tmp1 == '')
{
for ($i1 = 0, $n = count($arUpdaters); $i1 < $n; $i1++)
{
if ($arUpdaters[$i1][2] == "N")
{
$strError_tmp2 = "";
CUpdateClientPartner::__RunUpdaterScript($updateDirFrom.$arUpdaters[$i1][0], $strError_tmp2, "/bitrix/updates/".$updatesDir."/".$arModules[$i], $arModules[$i]);
if ($strError_tmp2 <> '')
{
$strError_tmp1 .=
str_replace("#MODULE#", $arModules[$i], str_replace("#VER#", $arUpdaters[$i1][1], GetMessage("SUPP_UK_UPDN_ERR"))).": ".
$strError_tmp2.". ";
$strError_tmp1 .= str_replace("#MODULE#", $arModules[$i], GetMessage("SUPP_UK_UPDN_ERR_BREAK"))." ";
break;
}
}
}
}
if ($strError_tmp1 == '')
CUpdateClientPartner::__CopyDirFiles($updateDirFrom, $updateDirTo, $strError_tmp1, true);
if ($strError_tmp1 == '')
{
for ($i1 = 0, $n = count($arUpdaters); $i1 < $n; $i1++)
{
if ($arUpdaters[$i1][2]=="Y")
{
$strError_tmp2 = "";
CUpdateClientPartner::__RunUpdaterScript($updateDirFrom.$arUpdaters[$i1][0], $strError_tmp2, "/bitrix/updates/".$updatesDir."/".$arModules[$i], $arModules[$i]);
if ($strError_tmp2 <> '')
{
$strError_tmp1 .=
str_replace("#MODULE#", $arModules[$i], str_replace("#VER#", $arUpdaters[$i1][1], GetMessage("SUPP_UK_UPDY_ERR"))).": ".
$strError_tmp2.". ";
$strError_tmp1 .= str_replace("#MODULE#", $arModules[$i], GetMessage("SUPP_UK_UPDN_ERR_BREAK"))." ";
break;
}
}
}
}
if ($strError_tmp1 <> '')
$strError_tmp .= $strError_tmp1;
}
CUpdateClientPartner::ClearUpdateFolder($updatesDirFull);
}
CUpdateClientPartner::AddMessage2Log("TIME UpdateStepModules ".Round(microtime(true) - $stime, 3)." sec");
if ($strError_tmp <> '')
{
CUpdateClientPartner::AddMessage2Log($strError_tmp, "USM");
$strError .= $strError_tmp;
return false;
}
else
{
foreach(GetModuleEvents("main", "OnModuleUpdate", true) as $arEvent)
ExecuteModuleEventEx($arEvent, array($arModules));
return true;
}
}