Ejemplo n.º 1
0
 private function deleteApp($app_id)
 {
     //remove db tables and etc
     $paths = array();
     /**
      * @var waAppConfig
      */
     $system = wa($app_id);
     $system->setActive($app_id);
     $app = SystemConfig::getAppConfig($app_id);
     $info = $app->getInfo();
     $name = _wd($app_id, $info['name']);
     /**
      * @var waAppConfig $config ;
      */
     $config = $system->getConfig();
     if (!empty($info['plugins'])) {
         $plugins = $config->getPlugins();
         foreach ($plugins as $plugin => $enabled) {
             try {
                 if ($enabled && ($plugin_instance = $system->getPlugin($plugin))) {
                     $plugin_instance->uninstall();
                 }
             } catch (Exception $ex) {
                 waLog::log($ex->getMessage(), 'installer.log');
             }
             $this->apps->updateAppPluginsConfig($app_id, $plugin, null);
             //wa-apps/$app_id/plugins/$slug
             $paths[] = wa()->getAppPath("plugins/" . $plugin, $app_id);
             while ($path = array_shift($paths)) {
                 waFiles::delete($path, true);
             }
             $paths = array();
         }
     }
     $config->uninstall();
     $this->apps->updateAppConfig($app_id, null);
     $paths[] = wa()->getTempPath(null, $app_id);
     //wa-cache/temp/$app_id/
     $paths[] = wa()->getAppCachePath(null, $app_id);
     //wa-cache/apps/$app_id/
     $paths[] = wa()->getDataPath(null, true, $app_id);
     //wa-data/public/$app_id/
     $paths[] = wa()->getDataPath(null, false, $app_id);
     //wa-data/protected/$app_id/
     if ($this->options['log']) {
         $paths[] = wa()->getConfig()->getPath('log') . '/' . $app_id;
         //wa-log/$app_id/
     }
     if ($this->options['config']) {
         $paths[] = wa()->getConfigPath($app_id);
         //wa-config/$app_id/
     }
     $paths[] = wa()->getAppPath(null, $app_id);
     //wa-apps/$app_id/
     $paths[] = wa()->getAppCachePath(null, 'webasyst');
     //wa-cache/apps/webasyst/
     foreach ($paths as $path) {
         try {
             waFiles::delete($path, true);
         } catch (waException $ex) {
         }
     }
     return $name;
 }
Ejemplo n.º 2
0
                        $urls[] = array('source' => $item['download_url'], 'target' => $target, 'slug' => $item['slug']);
                        if (preg_match('@wa-apps/([\\w\\d\\-]+)$@', $target, $matches)) {
                            $apps[] = $matches[1];
                        }
                    }
                }
            }
            $installer_apps = new waInstallerApps();
            waInstallerApps::setLocale($t->getLocale());
            $installer = new waInstaller(waInstaller::LOG_DEBUG);
            if ($urls && $installer->update($urls)) {
                foreach ($apps as $app) {
                    $installer_apps->installWebAsystApp($app);
                    if (!empty($plugins[$app])) {
                        foreach ($plugins[$app] as $plugin) {
                            $installer_apps->updateAppPluginsConfig($app, $plugin);
                        }
                    }
                }
            } else {
                $state = $installer->getState();
                if (isset($state['stage_status']) && $state['stage_status'] == waInstaller::STATE_ERROR) {
                    throw new Exception($state['error']);
                }
            }
            $log = parseLog($installer->getFullState('raw'), $t);
            $next_step = $step + 1;
            $next = $steps[$step]['next'];
            $content = <<<HTML
<h1>{$t->_('Files')}&nbsp;<i class="icon16 yes"></i></h1>
<div class="i-log">{$log}</div>
 function execute()
 {
     $module = 'apps';
     $url = parse_url(waRequest::server('HTTP_REFERER'), PHP_URL_QUERY);
     if (preg_match('/(^|&)module=(update|apps|plugins)($|&)/', $url, $matches)) {
         $module = $matches[2];
     }
     $app_ids = waRequest::get('app_id');
     try {
         if (!$app_ids || !is_array($app_ids)) {
             throw new waException(_w('Application not found'));
         }
         $vendors = array();
         foreach ($app_ids as $app_id => &$info) {
             if (!is_array($info)) {
                 $info = array('vendor' => $info);
             }
             $vendors[] = $info['vendor'];
             unset($info);
         }
         $vendors = array_unique($vendors);
         $apps = new waInstallerApps();
         $app_list = $apps->getApplicationsList(true, $vendors);
         $deleted_apps = array();
         if (installerHelper::isDeveloper()) {
             throw new waException(_w('Unable to delete application (developer version is on)'));
         }
         foreach ($app_list as $info) {
             $app_id = $info['slug'];
             if (isset($app_ids[$app_id]) && $app_ids[$app_id]['vendor'] == $info['vendor']) {
                 if (isset($info['system']) && $info['system']) {
                     throw new waException(sprintf(_w('Can not delete system application "%s"'), $info['name']));
                 }
                 $apps->updateRoutingConfig($app_id, false);
                 $apps->updateAppConfig($app_id, null);
                 //remove db tables and etc
                 $paths = array();
                 $app_instance = waSystem::getInstance($app_id);
                 $plugins = $app_instance->getConfig()->getPlugins();
                 foreach ($plugins as $plugin_id => $plugin) {
                     if ($plugin && ($plugin_instance = $app_instance->getPlugin($plugin_id))) {
                         $plugin_instance->uninstall();
                     }
                     $apps->updateAppPluginsConfig($app_id, $plugin_id, null);
                     //wa-apps/$app_id/plugins/$slug
                     $paths[] = wa()->getAppPath("plugins/{$plugin_id}", $app_id);
                     foreach ($paths as $path) {
                         waFiles::delete($path, true);
                     }
                     $paths = array();
                 }
                 $app_instance->getConfig()->uninstall();
                 //XXX called at uninstall
                 //$paths[] = wa()->getAppCachePath(null, $app_id);//wa-cache/apps/$app_id/
                 $paths[] = wa()->getTempPath(null, $app_id);
                 //wa-cache/temp/$app_id/
                 $paths[] = wa()->getAppCachePath(null, $app_id);
                 //wa-cache/apps/$app_id/
                 $paths[] = wa()->getDataPath(null, true, $app_id);
                 //wa-data/public/$app_id/
                 $paths[] = wa()->getDataPath(null, false, $app_id);
                 //wa-data/protected/$app_id/
                 //XXX uncomplete code
                 //$paths[] = wa()->   null, false, $app_id);//wa-log/$app_id/
                 //XXX uncomplete code
                 //$paths[] = wa()->getAppPath(null, $app_id);//wa-config/$app_id/
                 $paths[] = wa()->getAppPath(null, $app_id);
                 //wa-apps/$app_id/
                 foreach ($paths as $path) {
                     waFiles::delete($path, true);
                 }
                 $deleted_apps[] = $info['name'];
             }
         }
         if (!$deleted_apps) {
             throw new waException(_w('Application not found'));
         }
         $message = _w('Application %s has been deleted', 'Applications %s have been deleted', min(2, count($deleted_apps)), false);
         $message = sprintf($message, implode(', ', $deleted_apps));
         $msg = installerMessage::getInstance()->raiseMessage($message);
         $this->redirect(array('module' => $module, 'msg' => $msg));
     } catch (Exception $ex) {
         $msg = installerMessage::getInstance()->raiseMessage($ex->getMessage(), installerMessage::R_FAIL);
         $this->redirect(array('module' => $module, 'msg' => $msg));
     }
 }