コード例 #1
0
ファイル: plugin_service.php プロジェクト: hardikamutech/loov
 /**
  * Cron function.
  */
 public function checkUpdates()
 {
     if (defined('OW_PLUGIN_XP')) {
         return;
     }
     $pluginsRequestArray = array(array('key' => 'core', 'developerKey' => 'ow', 'build' => OW::getConfig()->getValue('base', 'soft_build')));
     $plugins = $this->pluginDao->findRegularPlugins();
     /* @var $plugin BOL_Plugin */
     foreach ($plugins as $plugin) {
         $pluginsRequestArray[] = array('key' => $plugin->getKey(), 'developerKey' => $plugin->getDeveloperKey(), 'build' => $plugin->getBuild());
     }
     $themeService = BOL_ThemeService::getInstance();
     //check all manual updates before reading builds in DB
     $themeService->checkManualUpdates();
     $themesRequestArray = array();
     $themes = $themeService->findAllThemes();
     /* @var $theme BOL_Theme */
     foreach ($themes as $theme) {
         $themesRequestArray[] = array('key' => $theme->getName(), 'developerKey' => $theme->getDeveloperKey(), 'build' => $theme->getBuild());
     }
     $event = new OW_Event('base.on_plugin_info_update');
     OW::getEventManager()->trigger($event);
     $data = $event->getData();
     if (empty($data)) {
         $data = array();
     }
     $requestUrl = OW::getRequest()->buildUrlQueryString(self::UPDATE_SERVER . 'get-items-update-info/');
     $data['plugins'] = urlencode(json_encode($pluginsRequestArray));
     $data['themes'] = urlencode(json_encode($themesRequestArray));
     $postdata = http_build_query($data);
     $options = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));
     $context = stream_context_create($options);
     $resultArray = json_decode(file_get_contents($requestUrl, false, $context), true);
     if (empty($resultArray) || !is_array($resultArray)) {
         return;
     }
     if (!empty($resultArray['plugins']) && is_array($resultArray['plugins'])) {
         foreach ($plugins as $plugin) {
             if (in_array($plugin->getKey(), $resultArray['plugins']) && (int) $plugin->getUpdate() === 0) {
                 $plugin->setUpdate(1);
                 $this->pluginDao->save($plugin);
             }
         }
         if (in_array('core', $resultArray['plugins'])) {
             OW::getConfig()->saveConfig('base', 'update_soft', 1);
         }
     }
     if (!empty($resultArray['themes']) && is_array($resultArray['themes'])) {
         foreach ($themes as $theme) {
             if (in_array($theme->getName(), $resultArray['themes']) && (int) $theme->getUpdate() === 0) {
                 $theme->setUpdate(1);
                 $themeService->saveTheme($theme);
             }
         }
     }
 }