Ejemplo n.º 1
0
 /**
  * Retrieves update information for all plugins and themes.
  *
  * @return bool
  */
 public function checkUpdates()
 {
     $requestArray = array("platform" => array(self::URI_VAR_BUILD => OW::getConfig()->getValue("base", "soft_build")), "items" => array());
     $plugins = $this->pluginService->findRegularPlugins();
     /* @var $plugin BOL_Plugin */
     foreach ($plugins as $plugin) {
         $requestArray["items"][] = array(self::URI_VAR_KEY => $plugin->getKey(), self::URI_VAR_DEV_KEY => $plugin->getDeveloperKey(), self::URI_VAR_BUILD => $plugin->getBuild(), self::URI_VAR_LICENSE_KEY => $plugin->getLicenseKey(), self::URI_VAR_ITEM_TYPE => self::URI_VAR_ITEM_TYPE_VAL_PLUGIN);
     }
     //check all manual updates before reading builds in DB
     $this->themeService->checkManualUpdates();
     $themes = $this->themeService->findAllThemes();
     /* @var $dto BOL_Theme */
     foreach ($themes as $dto) {
         $requestArray["items"][] = array(self::URI_VAR_KEY => $dto->getKey(), self::URI_VAR_DEV_KEY => $dto->getDeveloperKey(), self::URI_VAR_BUILD => $dto->getBuild(), self::URI_VAR_LICENSE_KEY => $dto->getLicenseKey(), self::URI_VAR_ITEM_TYPE => self::URI_VAR_ITEM_TYPE_VAL_THEME);
     }
     $data = $this->triggerEventBeforeRequest();
     $data["info"] = json_encode($requestArray);
     $params = new UTIL_HttpClientParams();
     $params->addParams($data);
     $response = UTIL_HttpClient::post($this->getStorageUrl(self::URI_CHECK_ITEMS_FOR_UPDATE), $params);
     if (!$response || $response->getStatusCode() != UTIL_HttpClient::HTTP_STATUS_OK) {
         OW::getLogger()->addEntry(__CLASS__ . "::" . __METHOD__ . "#" . __LINE__ . " storage request status is not OK", "core.update");
         return false;
     }
     $resultArray = array();
     if ($response->getBody()) {
         $resultArray = json_decode($response->getBody(), true);
     }
     if (empty($resultArray) || !is_array($resultArray)) {
         OW::getLogger()->addEntry(__CLASS__ . "::" . __METHOD__ . "#" . __LINE__ . " remote request returned empty result", "core.update");
         return false;
     }
     if (!empty($resultArray["update"])) {
         if (!empty($resultArray["update"]["platform"]) && (bool) $resultArray["update"]["platform"]) {
             OW::getConfig()->saveConfig("base", "update_soft", 1);
         }
         if (!empty($resultArray["update"]["items"])) {
             $this->updateItemsUpdateStatus($resultArray["update"]["items"]);
         }
     }
     $items = !empty($resultArray["invalidLicense"]) ? $resultArray["invalidLicense"] : array();
     $this->updateItemsLicenseStatus($items);
     return true;
 }