Example #1
0
 public function update(array $params)
 {
     $this->checkXP();
     if (!empty($_GET['mode'])) {
         switch (trim($_GET['mode'])) {
             case 'theme_up_to_date':
                 OW::getFeedback()->warning(OW::getLanguage()->text('admin', 'manage_themes_up_to_date_message'));
                 break;
             case 'theme_update_success':
                 OW::getFeedback()->info(OW::getLanguage()->text('admin', 'manage_themes_update_success_message'));
                 break;
             default:
                 OW::getFeedback()->error(OW::getLanguage()->text('admin', 'manage_themes_update_process_error'));
                 break;
         }
         $this->redirectToAction('chooseTheme');
     }
     $themeDto = $this->getThemeDtoByName($params);
     $ftp = $this->getFtpConnection();
     try {
         $archivePath = $this->themeService->downloadTheme($themeDto->getName(), $themeDto->getDeveloperKey(), !empty($params['licenseKey']) ? $params['licenseKey'] : null);
     } catch (Exception $e) {
         OW::getFeedback()->error($e->getMessage());
         $this->redirectToAction('chooseTheme');
     }
     if (!file_exists($archivePath)) {
         OW::getFeedback()->error(OW::getLanguage()->text('admin', 'theme_update_download_error'));
         $this->redirectToAction('chooseTheme');
     }
     $zip = new ZipArchive();
     $tempDir = OW_DIR_PLUGINFILES . 'ow' . DS . uniqid('theme_update') . DS;
     if ($zip->open($archivePath) === true) {
         $zip->extractTo($tempDir);
         $zip->close();
     } else {
         OW::getFeedback()->error(OW::getLanguage()->text('admin', 'theme_update_download_error'));
         $this->redirectToAction('chooseTheme');
     }
     if (file_exists($tempDir . 'theme.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 . 'theme.xml')) {
             $localDir = $tempDir . $innerDir;
         } else {
             OW::getFeedback()->error(OW::getLanguage()->text('admin', 'theme_update_download_error'));
             $this->redirectToAction('chooseTheme');
         }
     }
     if (substr($name, -1) === DS) {
         $name = substr($name, 0, strlen($name) - 1);
     }
     $remoteDir = OW_DIR_THEME . $themeDto->getName();
     if (!file_exists($remoteDir)) {
         $ftp->mkDir($remoteDir);
     }
     $ftp->uploadDir($localDir, $remoteDir);
     UTIL_File::removeDir($localDir);
     $this->redirect(OW::getRequest()->buildUrlQueryString(OW_URL_HOME . 'ow_updates/', array('theme' => $themeDto->getName(), 'back-uri' => urlencode(OW::getRequest()->getRequestUri()))));
 }