public function onCoreInit(GenericEvent $event)
 {
     /** @var Request $request */
     $request = $this->container->get('request');
     // create several booleans to test condition of request regarding install/upgrade
     $installed = $this->container->getParameter('installed');
     if ($installed) {
         VersionUtil::defineCurrentInstalledCoreVersion($this->container);
     }
     $requiresUpgrade = $installed && version_compare(ZIKULACORE_CURRENT_INSTALLED_VERSION, \Zikula_Core::VERSION_NUM, '<');
     // can't use $request->get('_route') to get any of the following
     // all these routes are hard-coded in xml files
     $uriContainsInstall = strpos($request->getRequestUri(), '/install') !== false;
     $uriContainsUpgrade = strpos($request->getRequestUri(), '/upgrade') !== false;
     $uriContainsDoc = strpos($request->getRequestUri(), '/installdoc') !== false;
     $uriContainsWdt = strpos($request->getRequestUri(), '/_wdt') !== false;
     $uriContainsProfiler = strpos($request->getRequestUri(), '/_profiler') !== false;
     $uriContainsRouter = strpos($request->getRequestUri(), '/js/routing?callback=fos.Router.setData') !== false;
     $doNotRedirect = $uriContainsProfiler || $uriContainsWdt || $uriContainsRouter || $request->isXmlHttpRequest();
     // check if Zikula Core is not installed
     if (!$installed && !$uriContainsDoc && !$uriContainsInstall && !$doNotRedirect) {
         $this->container->get('router')->getContext()->setBaseUrl($request->getBasePath());
         // compensate for sub-directory installs
         $url = $this->container->get('router')->generate('install');
         $response = new RedirectResponse($url);
         $response->send();
         \System::shutDown();
     }
     // check if Zikula Core requires upgrade
     if ($requiresUpgrade && !$uriContainsDoc && !$uriContainsUpgrade && !$doNotRedirect) {
         $this->container->get('router')->getContext()->setBaseUrl($request->getBasePath());
         // compensate for sub-directory installs
         $url = $this->container->get('router')->generate('upgrade');
         $response = new RedirectResponse($url);
         $response->send();
         \System::shutDown();
     }
     if (!$installed || $requiresUpgrade || $this->container->hasParameter('upgrading')) {
         \System::setInstalling(true);
     }
 }
Пример #2
0
 protected function registerCommands()
 {
     if ($this->kernel->getContainer()->getParameter('installed') !== true) {
         // composer is called, the system may not be installed yet
         return parent::registerCommands();
     }
     // ensure that we have admin access
     $this->bootstrap();
     if ($this->kernel->getContainer()->getParameter('installed') === true) {
         // don't attempt to login if the Core needs an upgrade
         VersionUtil::defineCurrentInstalledCoreVersion($this->kernel->getContainer());
         if (defined('ZIKULACORE_CURRENT_INSTALLED_VERSION') && version_compare(ZIKULACORE_CURRENT_INSTALLED_VERSION, \Zikula_Core::VERSION_NUM, '==')) {
             try {
                 $this->loginAsAdministrator();
             } catch (\Exception $e) {
                 $output = new \Symfony\Component\Console\Output\ConsoleOutput();
                 $this->renderException($e, $output);
             }
         }
     }
     return parent::registerCommands();
 }