Ejemplo n.º 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;
 }
$queryType = "M";
$arRequestedModules = array();
if (array_key_exists("reqm", $_REQUEST)) {
    $arRequestedModulesTmp = explode(",", $_REQUEST["reqm"]);
    for ($i = 0, $cnt = count($arRequestedModulesTmp); $i < $cnt; $i++) {
        if (!in_array($arRequestedModulesTmp[$i], $arRequestedModules)) {
            $arRequestedModules[] = $arRequestedModulesTmp[$i];
        }
    }
} else {
    $arRequestedModules = CUpdateClientPartner::GetRequestedModules($_REQUEST["addmodule"]);
}
COption::SetOptionString("main", "update_system_update", Date($GLOBALS["DB"]->DateFormatToPHP(CSite::GetDateFormat("FULL")), time()));
/************************************/
$arUpdatedModulesList = array();
$loadResult = CUpdateClientPartner::LoadModulesUpdates($errorMessage, $arUpdateDescription, LANG, $stableVersionsOnly, $arRequestedModules, array_key_exists("reqm", $_REQUEST));
if ($loadResult == "S") {
    CUpdateClientPartner::AddMessage2Log("LoadModulesUpdates-Step", "LMU01");
    $message = "";
    if (isset($arUpdateDescription["DATA"]["#"]["ITEM"])) {
        for ($i = 0, $cnt = count($arUpdateDescription["DATA"]["#"]["ITEM"]); $i < $cnt; $i++) {
            if (strlen($message) > 0) {
                $message .= ", ";
            }
            $message .= $arUpdateDescription["DATA"]["#"]["ITEM"][$i]["@"]["NAME"];
            if (strlen($arUpdateDescription["DATA"]["#"]["ITEM"][$i]["@"]["VALUE"]) > 0) {
                $message .= " (" . $arUpdateDescription["DATA"]["#"]["ITEM"][$i]["@"]["VALUE"] . ")";
            }
        }
    }
    die("STP0|" . $message);