Beispiel #1
0
 /**
  * Update module.
  *
  * It must be called repeatedly until the method returns false.
  * After each call php must be restarted (new process created) to update module class and function definitions.
  *
  * @param array $modulesUpdated [optional]
  * @return bool
  */
 public function update(&$modulesUpdated = null)
 {
     require_once $_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/main/classes/general/update_client_partner.php';
     if (!$this->isThirdParty()) {
         throw new Exception\ModuleUpdateException('Kernel module updates are currently not supported.', $this->getName());
     }
     // ensures module existence
     $this->getObject();
     $errorMessage = $updateDescription = null;
     $loadResult = \CUpdateClientPartner::LoadModulesUpdates($errorMessage, $updateDescription, LANGUAGE_ID, $this->isBeta() ? 'N' : 'Y', [$this->getName()], true);
     switch ($loadResult) {
         // archive loaded
         case "S":
             return $this->update($modulesUpdated);
             // error
         // error
         case "E":
             throw new Exception\ModuleUpdateException($errorMessage, $this->getName());
             // finished installing updates
         // finished installing updates
         case "F":
             return false;
             // need to process loaded update
         // need to process loaded update
         case 'U':
             break;
     }
     /** @var string Temp directory with update files */
     $updateDir = null;
     if (!\CUpdateClientPartner::UnGzipArchive($updateDir, $errorMessage, true)) {
         throw new Exception\ModuleUpdateException('[CL02] UnGzipArchive failed. ' . $errorMessage, $this->getName());
     }
     $this->validateUpdate($updateDir);
     if (isset($updateDescription["DATA"]["#"]["NOUPDATES"])) {
         \CUpdateClientPartner::ClearUpdateFolder($_SERVER["DOCUMENT_ROOT"] . "/bitrix/updates/" . $updateDir);
         return false;
     }
     $modulesUpdated = $updateDescr = [];
     if (isset($updateDescription["DATA"]["#"]["ITEM"])) {
         foreach ($updateDescription["DATA"]["#"]["ITEM"] as $moduleInfo) {
             $modulesUpdated[$moduleInfo["@"]["NAME"]] = $moduleInfo["@"]["VALUE"];
             $updateDescr[$moduleInfo["@"]["NAME"]] = $moduleInfo["@"]["DESCR"];
         }
     }
     if (\CUpdateClientPartner::UpdateStepModules($updateDir, $errorMessage)) {
         foreach ($modulesUpdated as $key => $value) {
             if (Option::set('main', 'event_log_marketplace', "Y") === "Y") {
                 \CEventLog::Log("INFO", "MP_MODULE_DOWNLOADED", "main", $key, $value);
             }
         }
     } else {
         throw new Exception\ModuleUpdateException('[CL04] UpdateStepModules failed. ' . $errorMessage, $this->getName());
     }
     return true;
 }
 public static function LoadModuleNoDemand($moduleId, &$strError, $stableVersionsOnly = "Y", $lang = false)
 {
     $strError_tmp = "";
     CUpdateClientPartner::AddMessage2Log("exec CUpdateClientPartner::LoadModuleNoDemand");
     $stableVersionsOnly = $stableVersionsOnly == "N" ? "N" : "Y";
     if ($lang === false) {
         $lang = LANGUAGE_ID;
     }
     $strQuery = CUpdateClientPartner::__CollectRequestData($strError_tmp, $lang, $stableVersionsOnly, array($moduleId), array(), true);
     if ($strQuery === False || StrLen($strQuery) <= 0 || StrLen($strError_tmp) > 0) {
         if (StrLen($strError_tmp) <= 0) {
             $strError_tmp = "[GNSU01] " . GetMessage("SUPZ_NO_QSTRING") . ". ";
         }
     }
     if (StrLen($strError_tmp) <= 0) {
         CUpdateClientPartner::AddMessage2Log(preg_replace("/LICENSE_KEY=[^&]*/i", "LICENSE_KEY=X", $strQuery));
         $stime = CUpdateClientPartner::__GetMicroTime();
         $content = CUpdateClientPartner::__GetHTTPPage("MODULE", $strQuery, $strError_tmp);
         if (strlen($content) <= 0) {
             if (StrLen($strError_tmp) <= 0) {
                 $strError_tmp = "[GNSU02] " . GetMessage("SUPZ_EMPTY_ANSWER") . ". ";
             }
         }
         CUpdateClientPartner::AddMessage2Log("TIME LoadModuleNoDemand(request) " . Round(CUpdateClientPartner::__GetMicroTime() - $stime, 3) . " sec");
     }
     if (StrLen($strError_tmp) <= 0) {
         if (!($fp1 = fopen($_SERVER["DOCUMENT_ROOT"] . "/bitrix/updates/update_archive.gz", "wb"))) {
             $strError_tmp = "[GNSU03] " . str_replace("#FILE#", $_SERVER["DOCUMENT_ROOT"] . "/bitrix/updates", GetMessage("SUPP_RV_ER_TEMP_FILE")) . ". ";
         }
     }
     if (StrLen($strError_tmp) <= 0) {
         fwrite($fp1, $content);
         fclose($fp1);
     }
     if (strlen($strError_tmp) <= 0) {
         $temporaryUpdatesDir = "";
         if (!CUpdateClientPartner::UnGzipArchive($temporaryUpdatesDir, $strError_tmp, true)) {
             $strError_tmp .= "[CL02] " . GetMessage("SUPC_ME_PACK") . ". ";
             CUpdateClientPartner::AddMessage2Log(GetMessage("SUPC_ME_PACK"), "CL02");
         }
     }
     $arStepUpdateInfo = array();
     if (strlen($strError_tmp) <= 0) {
         $arStepUpdateInfo = CUpdateClientPartner::GetStepUpdateInfo($temporaryUpdatesDir, $strError_tmp);
     }
     if (StrLen($strError_tmp) <= 0) {
         if (isset($arStepUpdateInfo["DATA"]["#"]["ERROR"])) {
             for ($i = 0, $cnt = count($arStepUpdateInfo["DATA"]["#"]["ERROR"]); $i < $cnt; $i++) {
                 $strError_tmp .= "[" . $arStepUpdateInfo["DATA"]["#"]["ERROR"][$i]["@"]["TYPE"] . "] " . $arStepUpdateInfo["DATA"]["#"]["ERROR"][$i]["#"];
             }
         }
     }
     if (strlen($strError_tmp) <= 0) {
         if (!CUpdateClientPartner::UpdateStepModules($temporaryUpdatesDir, $strError_tmp)) {
             $strError_tmp .= "[CL04] " . GetMessage("SUPC_ME_UPDATE") . ". ";
             CUpdateClientPartner::AddMessage2Log(GetMessage("SUPC_ME_UPDATE"), "CL04");
         }
     }
     if (strlen($strError_tmp) > 0) {
         CUpdateSystem::AddMessage2Log($strError_tmp, "CURV");
         $strError .= $strError_tmp;
         return False;
     } else {
         return True;
     }
 }
    if (strlen($errorMessage) <= 0) {
        $errorMessage = "[CL02] " . GetMessage("SUPC_ME_PACK");
    }
    CUpdateClientPartner::AddMessage2Log($errorMessage, "CL02");
} elseif ($loadResult == "F") {
    CUpdateClientPartner::AddMessage2Log("Finish - NOUPDATES", "STEP");
    die("FIN");
}
/*if (!CUpdateClientPartner::GetNextStepUpdates($errorMessage, LANG, $stableVersionsOnly, $arRequestedModules, array_key_exists("reqm", $_REQUEST)))
{
	$errorMessage .= "[CL01] ".GetMessage("SUPC_ME_LOAD").". ";
	CUpdateClientPartner::AddMessage2Log(GetMessage("SUPC_ME_LOAD"), "CL01");
}*/
if (StrLen($errorMessage) <= 0) {
    $temporaryUpdatesDir = "";
    if (!CUpdateClientPartner::UnGzipArchive($temporaryUpdatesDir, $errorMessage, true)) {
        $errorMessage .= "[CL02] " . GetMessage("SUPC_ME_PACK") . ". ";
        CUpdateClientPartner::AddMessage2Log(GetMessage("SUPC_ME_PACK"), "CL02");
    }
}
if (strlen($errorMessage) <= 0) {
    if (!CUpdateClientPartner::CheckUpdatability($temporaryUpdatesDir, $errorMessage)) {
        $errorMessage .= "[CL03] " . GetMessage("SUPC_ME_CHECK") . ". ";
        CUpdateClientPartner::AddMessage2Log(GetMessage("SUPC_ME_CHECK"), "CL03");
    }
}
$arStepUpdateInfo = $arUpdateDescription;
/*if (strlen($errorMessage) <= 0)
{
	$arStepUpdateInfo = CUpdateClientPartner::GetStepUpdateInfo($temporaryUpdatesDir, $errorMessage);
	//CUpdateClientPartner::AddMessage2Log(print_r($arStepUpdateInfo, true), "!!!!!");