Esempio n. 1
0
 public function update(array $params)
 {
     $this->checkXP();
     $pluginDto = $this->getPluginDtoByKey($params);
     if (!empty($_GET['mode'])) {
         switch (trim($_GET['mode'])) {
             case 'plugin_up_to_date':
                 OW::getFeedback()->warning(OW::getLanguage()->text('admin', 'manage_plugins_up_to_date_message'));
                 break;
             case 'plugin_update_success':
                 if ($pluginDto !== null) {
                     $event = new OW_Event(OW_EventManager::ON_AFTER_PLUGIN_UPDATE, array('pluginKey' => $pluginDto->getKey()));
                     OW::getEventManager()->trigger($event);
                 }
                 OW::getFeedback()->info(OW::getLanguage()->text('admin', 'manage_plugins_update_success_message'));
                 break;
             default:
                 OW::getFeedback()->error(OW::getLanguage()->text('admin', 'manage_plugins_update_process_error'));
                 break;
         }
         $this->redirectToAction('index');
     }
     $ftp = $this->getFtpConnection();
     try {
         $archivePath = $this->pluginService->downloadItem($pluginDto->getKey(), $pluginDto->getDeveloperKey(), !empty($params['licenseKey']) ? $params['licenseKey'] : null);
     } catch (Exception $e) {
         OW::getFeedback()->error($e->getMessage());
         $this->redirectToAction('index');
     }
     if (!file_exists($archivePath)) {
         OW::getFeedback()->error(OW::getLanguage()->text('admin', 'plugin_update_download_error'));
         $this->redirectToAction('index');
     }
     $zip = new ZipArchive();
     $tempDir = OW_DIR_PLUGINFILES . 'ow' . DS . uniqid('plugin_update') . DS;
     if ($zip->open($archivePath) === true) {
         $zip->extractTo($tempDir);
         $zip->close();
     } else {
         OW::getFeedback()->error(OW::getLanguage()->text('admin', 'plugin_update_download_error'));
         $this->redirectToAction('index');
     }
     if (file_exists($tempDir . 'plugin.xml')) {
         $localDir = $tempDir;
     } else {
         $handle = opendir($tempDir);
         while (($item = readdir($handle)) !== false) {
             if ($item === '.' || $item === '..') {
                 continue;
             }
             $innerDir = $item;
         }
         closedir($handle);
         if (!empty($innerDir) && file_exists($tempDir . $innerDir . DS . 'plugin.xml')) {
             $localDir = $tempDir . $innerDir;
         } else {
             OW::getFeedback()->error(OW::getLanguage()->text('admin', 'plugin_update_download_error'));
             $this->redirectToAction('index');
         }
     }
     if (substr($name, -1) === DS) {
         $name = substr($name, 0, strlen($name) - 1);
     }
     $remoteDir = OW_DIR_PLUGIN . $pluginDto->getModule();
     if (!file_exists($remoteDir)) {
         $ftp->mkDir($remoteDir);
     }
     $ftp->uploadDir($localDir, $remoteDir);
     UTIL_File::removeDir($localDir);
     // copy static dir
     $pluginStaticDir = OW_DIR_PLUGIN . $pluginDto->getModule() . DS . 'static' . DS;
     if (!defined('OW_PLUGIN_XP') && file_exists($pluginStaticDir)) {
         $staticDir = OW_DIR_STATIC_PLUGIN . $pluginDto->getModule() . DS;
         if (!file_exists($staticDir)) {
             mkdir($staticDir);
             chmod($staticDir, 0777);
         }
         UTIL_File::copyDir($pluginStaticDir, $staticDir);
     }
     $this->redirect(OW::getRequest()->buildUrlQueryString(OW_URL_HOME . 'ow_updates/index.php', array('plugin' => $pluginDto->getKey(), 'back-uri' => urlencode(OW::getRequest()->getRequestUri()))));
 }