src/AppBundle/Controller/SetupController.php line 706

Open in your IDE?
  1. <?php
  2. namespace AppBundle\Controller;
  3. use AppBundle\Component\Plugin\PluginManager;
  4. use Monolog\Logger;
  5. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\Filesystem\Filesystem;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\Console\Input\ArrayInput;
  11. use Symfony\Bundle\FrameworkBundle\Console\Application;
  12. use Symfony\Component\Console\Output\BufferedOutput;
  13. use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
  14. use Symfony\Component\HttpKernel\Event\PostResponseEvent;
  15. use Symfony\Component\HttpKernel\Exception\HttpException;
  16. use Symfony\Component\HttpKernel\KernelEvents;
  17. class SetupController extends Controller implements EventSubscriberInterface
  18. {
  19.     private $commandAfterResponse false;
  20.     public function before(FilterControllerEvent $event)
  21.     {
  22.         set_time_limit(60 30);
  23.         $controller $event->getController();
  24.         $action $controller[1];
  25.         // ロックを掛けないアクション(BASIC認証をかけること)
  26.         $allowedActions = array(
  27.             'utilAction''cacheClearAction''schemaUpdateAction'
  28.         );
  29.         // ロックファイルがあればロックをかける
  30.         $currentEnv CMS__ENVIRONMENT;
  31.         $lockFile str_replace('/', \DIRECTORY_SEPARATORCMS__ADMIN_DIR 'setup/install_' $currentEnv '.lock');
  32.         if(file_exists($lockFile) && !in_array($action$allowedActions)){
  33.             throw new HttpException(500'Remove "' $lockFile '" before install.');
  34.         }
  35.     }
  36.     public function indexAction(Request $request)
  37.     {
  38.         return $this->render('setup/index.html.php', [
  39.         ]);
  40.     }
  41.     public function dbSettingAction(Request $request)
  42.     {
  43.         $env CMS__ENVIRONMENT;
  44.         $xml str_replace('/\\', \DIRECTORY_SEPARATORCMS__ADMIN_DIR 'config/env_database_setting_' $env '.xml');
  45.         $db_settings $this->loadDatabaseSettings($xml);
  46.         return $this->render('setup/db-setting.html.php', [
  47.             'db_settings' => isset($db_settings[CMS__ENVIRONMENT]) ? $db_settings[CMS__ENVIRONMENT] : [],
  48.             'env' => $env
  49.         ]);
  50.     }
  51.     public function mailSettingAction(Request $request)
  52.     {
  53.         $env CMS__ENVIRONMENT;
  54.         $xml str_replace('/\\', \DIRECTORY_SEPARATORCMS__ADMIN_DIR 'config/env_mail_setting_' $env '.xml');
  55.         $mail_settings $this->loadMailSettings($xml);
  56.         return $this->render('setup/mail-setting.html.php', [
  57.             'mail_settings' => isset($mail_settings[CMS__ENVIRONMENT]) ? $mail_settings[CMS__ENVIRONMENT] : [],
  58.             'env' => $env
  59.         ]);
  60.     }
  61.     public function migrateAction(Request $request)
  62.     {
  63.         $result '';
  64.         $result .= $this->runCommand(new ArrayInput([
  65.             'command' => 'doctrine:migration:diff',
  66.             '--no-interaction' => true
  67.         ]));
  68.         $result .= $this->runCommand(new ArrayInput([
  69.             'command' => 'doctrine:migration:migrate',
  70.             '--no-interaction' => true
  71.         ]));
  72.         return $this->render('setup/migrate.html.php', [
  73.             'result' => $result
  74.         ]);
  75.     }
  76.     public function databaseAction(Request $request)
  77.     {
  78.         $data $request->request->get('db');
  79.         $env $request->request->get('env');
  80.         $this->saveDatabaseSettings($env, [$env => $data]);
  81.         return $this->redirectToRoute('setup_mail_setting');
  82.     }
  83.     protected function loadDatabaseSettings($file)
  84.     {
  85.         $settings = [
  86.             'prod' => [
  87.                 'database_host' => '127.0.0.1',
  88.                 'database_port' => 3306,
  89.                 'database_name' => null,
  90.                 'database_user' => null,
  91.                 'database_password' => null
  92.             ],
  93.             'staging' => [
  94.                 'database_host' => '127.0.0.1',
  95.                 'database_port' => 3306,
  96.                 'database_name' => null,
  97.                 'database_user' => null,
  98.                 'database_password' => null
  99.             ],
  100.             'dev' => [
  101.                 'database_host' => '203.138.100.49',
  102.                 'database_port' => 3306,
  103.                 'database_name' => null,
  104.                 'database_user' => 'ability',
  105.                 'database_password' => 'ability'
  106.             ]
  107.         ];
  108.         if(file_exists($file)){
  109.             $dom = new \DOMDocument();
  110.             $dom->load($file);
  111.             $root $dom->documentElement;
  112.             $settingNodes $root->getElementsByTagName('setting');
  113.             foreach($settingNodes as $settingNode){
  114.                 $mode $settingNode->getAttribute('mode');
  115.                 $host $settingNode->getElementsByTagName('host')->item(0)->nodeValue;
  116.                 $port $settingNode->getElementsByTagName('port')->item(0)->nodeValue;
  117.                 $name $settingNode->getElementsByTagName('name')->item(0)->nodeValue;
  118.                 $user $settingNode->getElementsByTagName('user')->item(0)->nodeValue;
  119.                 $password $settingNode->getElementsByTagName('password')->item(0)->nodeValue;
  120.                 $settings[$mode] = [
  121.                     'database_host' => $host,
  122.                     'database_port' => $port,
  123.                     'database_name' => $name,
  124.                     'database_user' => $user,
  125.                     'database_password' => $password
  126.                 ];
  127.             }
  128.         }
  129.         return $settings;
  130.     }
  131.     protected function saveDatabaseSettings($env$data){
  132.         $dom = new \DOMDocument();
  133.         $dom->preserveWhiteSpace false;
  134.         $dom->formatOutput true;
  135.         $root $dom->createElement('settings');
  136.         $dom->appendChild($root);
  137.         $file str_replace('/\\', \DIRECTORY_SEPARATORCMS__ADMIN_DIR 'config/env_database_setting_' $env '.xml');
  138.         foreach ($data as $mode => $values) {
  139.             $setting $this->createDatabaseSetting($dom$mode$values);
  140.             if($setting){
  141.                 $root->appendChild($setting);
  142.             }
  143.         }
  144.         $dom->save($file);
  145.     }
  146.     protected function createDatabaseSetting($dom$mode$values)
  147.     {
  148.         $name = !empty($values['name']) ? $values['name'] : null;
  149.         $user = !empty($values['user']) ? $values['user'] : null;
  150.         $host = !empty($values['host']) ? $values['host'] : '127.0.0.1';
  151.         $port = !empty($values['port']) ? $values['port'] : 3306;
  152.         $password = !empty($values['password']) ? $values['password'] : null;
  153.         $setting $dom->createElement('setting');
  154.         $setting->setAttribute('mode'$mode);
  155.         $hostElem $dom->createElement('host');
  156.         $portElem $dom->createElement('port');
  157.         $nameElem $dom->createElement('name');
  158.         $userElem $dom->createElement('user');
  159.         $passwordElem $dom->createElement('password');
  160.         $hostText $dom->createTextNode($host);
  161.         $portText $dom->createTextNode($port);
  162.         $nameText $dom->createTextNode($name);
  163.         $userText $dom->createTextNode($user);
  164.         $passwordText $dom->createTextNode($password);
  165.         $hostElem->appendChild($hostText);
  166.         $portElem->appendChild($portText);
  167.         $nameElem->appendChild($nameText);
  168.         $userElem->appendChild($userText);
  169.         $passwordElem->appendChild($passwordText);
  170.         $setting->appendChild($hostElem);
  171.         $setting->appendChild($portElem);
  172.         $setting->appendChild($nameElem);
  173.         $setting->appendChild($userElem);
  174.         $setting->appendChild($passwordElem);
  175.         return $setting;
  176.     }
  177.     public function checkDatabaseConnectionAction(Request $request)
  178.     {
  179.         $name $request->query->get('name'null);
  180.         $user $request->query->get('user'null);
  181.         $host $request->query->get('host''127.0.0.1');
  182.         $port $request->query->get('port'3306);
  183.         $password $request->query->get('password'null);
  184.         $dsn sprintf('mysql:dbname=%s;host=%s;port=%s',
  185.             $name$host$port);
  186.         try {
  187.             $db = new \PDO($dsn$user$password);
  188.             return new JsonResponse([
  189.                 'status' => 'success'
  190.             ]);
  191.         } catch(\PDOException $e){
  192.             return new JsonResponse([
  193.                 'status' => 'failed'
  194.             ]);
  195.         }
  196.     }
  197.     public function mailAction(Request $request)
  198.     {
  199.         $data $request->request->get('mailer');
  200.         $env $request->request->get('env');
  201.         $this->saveMailSettings($env, [$env => $data]);
  202.         $this->commandAfterResponse true;
  203.         return $this->redirectToRoute('setup_install');
  204.     }
  205.     public function mailTestAction(Request $request)
  206.     {
  207.         $container $this->container;
  208.         $user $container->getParameter('mailer_user');
  209.         $password $container->getParameter('mailer_password');
  210.         $transport $container->getParameter('mailer_transport');
  211.         $host $container->getParameter('mailer_host');
  212.         $message '';
  213.         if('POST' === $request->getMethod()){
  214.             $to $request->request->get('to');
  215.             if(!empty($to)){
  216.                 $log $this->runCommand(new ArrayInput([
  217.                     'command' => 'mail:test',
  218.                     'to' => $to
  219.                 ]));
  220.                 $message '送信しました';
  221.             }
  222.         }
  223.         return $this->render('setup/mail-test.html.php', [
  224.             'message' => $message,
  225.             'user' => $user,
  226.             'password' => $password,
  227.             'transport' => $transport,
  228.             'host' => $host
  229.         ]);
  230.     }
  231.     public function checkMailServerConnectionAction(Request $request)
  232.     {
  233.         $host $request->query->get('host''127.0.0.1');
  234.         $transport $request->query->get('transport''smtp');
  235.         $user $request->query->get('user''');
  236.         $password $request->query->get('password''');
  237.         $port 25;
  238.         try {
  239.             $swiftTransport = new \Swift_SmtpTransport($host$port);
  240.             $swiftTransport->setUsername($user);
  241.             $swiftTransport->setPassword($password);
  242.             $mailer = new \Swift_Mailer($swiftTransport);
  243.             $mailer->getTransport()->start();
  244.         } catch(\Swift_TransportException $ex){
  245.             return new JsonResponse([
  246.                 'status' => 'failed',
  247.                 'error' => $ex->getMessage()
  248.             ]);
  249.         }
  250.         return new JsonResponse([
  251.             'status' => 'success'
  252.         ]);
  253.     }
  254.     protected function loadMailSettings($file)
  255.     {
  256.         $settings = [
  257.             'prod' => [
  258.                 'mailer_transport' => 'smtp',
  259.                 'mailer_host' => '127.0.0.1',
  260.                 'mailer_user' => null,
  261.                 'mailer_password' => null,
  262.                 'mailer_port' => 25,
  263.             ],
  264.             'staging' => [
  265.                 'mailer_transport' => 'smtp',
  266.                 'mailer_host' => '127.0.0.1',
  267.                 'mailer_user' => null,
  268.                 'mailer_password' => null,
  269.                 'mailer_port' => 25,
  270.             ],
  271.             'dev' => [
  272.                 'mailer_transport' => 'smtp',
  273.                 'mailer_host' => 'smtp.mailtrap.io',
  274.                 'mailer_user' => 'b45544fee7a1a6',
  275.                 'mailer_password' => 'dc41fd4e41494d',
  276.                 'mailer_port' => 25
  277.             ]
  278.         ];
  279.         if(file_exists($file)){
  280.             $dom = new \DOMDocument();
  281.             $dom->load($file);
  282.             $root $dom->documentElement;
  283.             $settingNodes $root->getElementsByTagName('setting');
  284.             foreach($settingNodes as $settingNode){
  285.                 $mode $settingNode->getAttribute('mode');
  286.                 $transport $settingNode->getElementsByTagName('transport')->item(0)->nodeValue;
  287.                 $host $settingNode->getElementsByTagName('host')->item(0)->nodeValue;
  288.                 $user $settingNode->getElementsByTagName('user')->item(0)->nodeValue;
  289.                 $password $settingNode->getElementsByTagName('password')->item(0)->nodeValue;
  290.                 $portNode $settingNode->getElementsByTagName('port')->item(0);
  291.                 if($portNode){
  292.                     $port $portNode->nodeValue;
  293.                 } else {
  294.                     $port 25;
  295.                 }
  296.                 $settings[$mode] = [
  297.                     'mailer_host' => $host,
  298.                     'mailer_transport' => $transport,
  299.                     'mailer_user' => $user,
  300.                     'mailer_password' => $password,
  301.                     'mailer_port' => $port,
  302.                 ];
  303.             }
  304.         }
  305.         return $settings;
  306.     }
  307.     protected function saveMailSettings($env$data){
  308.         $dom = new \DOMDocument();
  309.         $dom->preserveWhiteSpace false;
  310.         $dom->formatOutput true;
  311.         $root $dom->createElement('settings');
  312.         $dom->appendChild($root);
  313.         $file str_replace('/\\', \DIRECTORY_SEPARATORCMS__ADMIN_DIR 'config/env_mail_setting_' $env '.xml');
  314.         foreach ($data as $mode => $values) {
  315.             $setting $this->createMailSetting($dom$mode$values);
  316.             if($setting){
  317.                 $root->appendChild($setting);
  318.             }
  319.         }
  320.         $dom->save($file);
  321.     }
  322.     protected function createMailSetting($dom$mode$values)
  323.     {
  324.         $host = !empty($values['host']) ? $values['host'] : '127.0.0.1';
  325.         $transport = !empty($values['transport']) ? $values['transport'] : 'smtp';
  326.         $user = !empty($values['user']) ? $values['user'] : null;
  327.         $password = !empty($values['password']) ? $values['password'] : null;
  328.         $port = !empty($values['port']) ? $values['port'] : 25;
  329.         $setting $dom->createElement('setting');
  330.         $setting->setAttribute('mode'$mode);
  331.         $hostElem $dom->createElement('host');
  332.         $hostElem->appendChild($dom->createTextNode($host));
  333.         $setting->appendChild($hostElem);
  334.         $portElem $dom->createElement('port');
  335.         $portElem->appendChild($dom->createTextNode($port));
  336.         $setting->appendChild($portElem);
  337.         $transportElem $dom->createElement('transport');
  338.         $transportElem->appendChild($dom->createTextNode($transport));
  339.         $setting->appendChild($transportElem);
  340.         $userElem $dom->createElement('user');
  341.         $userElem->appendChild($dom->createTextNode($user));
  342.         $setting->appendChild($userElem);
  343.         $passwordElem $dom->createElement('password');
  344.         $passwordElem->appendChild($dom->createTextNode($password));
  345.         $setting->appendChild($passwordElem);
  346.         return $setting;
  347.     }
  348.     public function installAction(Request $request)
  349.     {
  350.         $dbHost $this->getParameter('database_host');
  351.         $dbName $this->getParameter('database_name');
  352.         return $this->render('setup/install.html.php', [
  353.             'dbHost' => $dbHost,
  354.             'dbName' => $dbName
  355.         ]);
  356.     }
  357.     public function ajaxInstallAction(Request $request)
  358.     {
  359.         set_time_limit(60 30);
  360.         if(!$request->isXmlHttpRequest()){
  361.             return new JsonResponse([
  362.                 'status' => 'failed',
  363.                 'log' => null
  364.             ]);
  365.         }
  366.         $rootDir $this->container->get('kernel')->getRootDir();
  367.         $modDir str_replace('/', \DIRECTORY_SEPARATOR$rootDir '/../src/Mod');
  368.         if(!file_exists($modDir)){
  369.             mkdir($modDir0755true);
  370.         }
  371.         $migrationDir str_replace('/', \DIRECTORY_SEPARATORCMS__ADMIN_DIR 'cms/app/DoctrineMigrations/');
  372.         if(file_exists($migrationDir)){
  373.             $files glob($migrationDir '*.php');
  374.             foreach($files as $file){
  375.                 @unlink($file);
  376.             }
  377.         }
  378.         $log '';
  379.         $this->runCommand(new ArrayInput([
  380.             'command' => 'cache:clear',
  381.             '--no-warmup' => true,
  382.             '--no-interaction' => true,
  383.             '-v' => true
  384.         ]));
  385.         // 注意:データベースの内容が削除されます
  386.         $log .= $this->runCommand(new ArrayInput([
  387.             'command' => 'doctrine:schema:drop',
  388.             '--full-database' => true,
  389.             '--force' => true,
  390.             '--no-interaction' => true,
  391.             '-v' => true
  392.         ]));
  393.         $log .= $this->runCommand(new ArrayInput([
  394.             'command' => 'doctrine:migration:diff',
  395.             '--no-interaction' => true,
  396.             '-v' => true
  397.         ]));
  398.         $log .= $this->runCommand(new ArrayInput([
  399.             'command' => 'doctrine:migration:migrate',
  400.             '--no-interaction' => true,
  401.             '-v' => true
  402.         ]));
  403.         $log .= $this->runCommand(new ArrayInput([
  404.             'command' => 'doctrine:fixtures:load',
  405.             '--no-interaction' => true,
  406.             '-v' => true
  407.         ]));
  408.         $log .= 'Installing modules...' "\n";
  409.         $this->installModAll();
  410.         $log .= 'Modules installed.' "\n";
  411.         $this->runCommand(new ArrayInput([
  412.             'command' => 'log:clear',
  413.             '--no-interaction' => true,
  414.             '-v' => true
  415.         ]));
  416.         $data = [
  417.             'status' => 'success',
  418.             'log' => $log
  419.         ];
  420.         $setupDir str_replace('/', \DIRECTORY_SEPARATORCMS__ADMIN_DIR 'setup/');
  421.         $currentEnv CMS__ENVIRONMENT;
  422.         $lockFile str_replace('/', \DIRECTORY_SEPARATOR$setupDir 'install_' $currentEnv '.lock');
  423.         $logFile str_replace('/', \DIRECTORY_SEPARATOR$setupDir 'install_' $currentEnv '.log');
  424.         if(!file_exists($setupDir)){
  425.             mkdir($setupDir0777true);
  426.         }
  427.         // ロックファイルの作成
  428.         file_put_contents($lockFile'インストールの際はこのファイルを削除してください');
  429.         file_put_contents($logFile$log);
  430.         return new JsonResponse($data);
  431.     }
  432.     public function completeAction(Request $request)
  433.     {
  434.         return $this->render('setup/complete.html.php', []);
  435.     }
  436.     public function schemaUpdateAction(Request $request)
  437.     {
  438.         $result '';
  439.         $result .= $this->runCommand(new ArrayInput([
  440.             'command' => 'doctrine:schema:update',
  441.             '--force' => true
  442.         ]));
  443.         return $this->render('setup/schema-update.html.php', [
  444.             'result' => $result
  445.         ]);
  446.     }
  447.     public function cacheClearAction(Request $request)
  448.     {
  449.         $result '';
  450.         $this->commandAfterResponse true;
  451.         $this->addFlash('success''コマンド実行しました。');
  452.         return $this->render('setup/cache-clear.html.php', [
  453.             'result' => $result
  454.         ]);
  455.     }
  456.     /**
  457.      * アプリケーションコマンドの実行
  458.      *
  459.      * @param ArrayInput $input
  460.      * @return string
  461.      * @throws \Exception
  462.      */
  463.     protected function runCommand(ArrayInput $input)
  464.     {
  465.         $app = new Application($this->get('kernel'));
  466.         $app->setAutoExit(false);
  467.         $output = new BufferedOutput();
  468.         $exitCode $app->run($input$output);
  469.         return $output->fetch();
  470.     }
  471.     public function ajaxClearModAction()
  472.     {
  473.         $fs = new Filesystem();
  474.         $log '';
  475.         $rootDir $this->container->get('kernel')->getRootDir();
  476.         $configDir str_replace('/', \DIRECTORY_SEPARATOR$rootDir '/config');
  477.         $modDir str_replace('/', \DIRECTORY_SEPARATOR$rootDir '/cms/src/Mod');
  478.         $routingFile str_replace('/', \DIRECTORY_SEPARATOR$configDir '/_mod_routing.yml');
  479.         $bundleRegisterFile str_replace('/', \DIRECTORY_SEPARATOR$configDir'/_bundles.xml');
  480.         file_put_contents($routingFile'');
  481.         file_put_contents($bundleRegisterFile'<?xml version="1.0" encoding="UTF-8"?><bundles />');
  482.         if(file_exists($modDir)){
  483.             $fs->remove($modDir);
  484.         }
  485.         mkdir($modDir0755true);
  486.         return new JsonResponse([
  487.             'status' => 'success'
  488.         ]);
  489.     }
  490.     public function ajaxRegisterModAction(Request $request)
  491.     {
  492.         $log '';
  493.         $log .= $this->runCommand(new ArrayInput([
  494.             'command' => 'bundle:register:exists',
  495.             '-v' => true
  496.         ]));
  497.         $data = [
  498.             'status' => 'success',
  499.             'log' => $log
  500.         ];
  501.         return new JsonResponse($data);
  502.     }
  503.     public function ajaxInstallModAction(Request $request)
  504.     {
  505.         $log '';
  506.         $log .= $this->runCommand(new ArrayInput([
  507.             'command' => 'bundle:install',
  508.             '-v' => true
  509.         ]));
  510.         $data = [
  511.             'status' => 'success',
  512.             'log' => $log
  513.         ];
  514.         return new JsonResponse($data);
  515.     }
  516.     /**
  517.      * Mod フォルダを空にする
  518.      */
  519.     protected function clearMods()
  520.     {
  521.         $fs = new Filesystem();
  522.         $configDir $this->container->get('kernel')->getRootDir() . '/config';
  523.         $routingFile str_replace('/', \DIRECTORY_SEPARATOR$configDir '/mod_routing.yml');
  524.         $bundleRegisterFile str_replace('/', \DIRECTORY_SEPARATOR$configDir'/bundles.xml');
  525.         if(file_exists($routingFile)){
  526.             file_put_contents($routingFile'');
  527.         }
  528.         if(file_exists($bundleRegisterFile)){
  529.             unlink($bundleRegisterFile);
  530.         }
  531.         $dir str_replace('/', \DIRECTORY_SEPARATORCMS__ADMIN_DIR 'cms/src/Mod/');
  532.         if(!file_exists($dir)){
  533.             mkdir($dir0755true);
  534.         }
  535.         $copy str_replace('/', \DIRECTORY_SEPARATORCMS__ADMIN_DIR 'cms/src/Mod_' microtime(true) . '/');
  536.         if(file_exists($dir) && is_dir($dir)){
  537.             rename($dir$copy);
  538.             $fs->remove($copy);
  539.             mkdir($dir);
  540.         }
  541.     }
  542.     public function utilAction()
  543.     {
  544.         return $this->render('::setup/util.html.php', []);
  545.     }
  546.     /**
  547.      * bundles.xml をもとにプラグインを再インストール
  548.      */
  549.     public function installModAll()
  550.     {
  551.         $projectDir $this->get('kernel')->getProjectDir();
  552.         $modDir str_replace('/', \DIRECTORY_SEPARATOR$projectDir '/src/Mod');
  553.         $bundleConfig str_replace('', \DIRECTORY_SEPARATOR$projectDir '/app/config/bundles.xml');
  554.         $manager = new PluginManager($this->container);
  555.         if(file_exists($bundleConfig)){
  556.             $dom = new \DOMDocument('1.0''UTF-8');
  557.             $dom->preserveWhiteSpace false;
  558.             $dom->formatOutput true;
  559.             $dom->load($bundleConfig);
  560.             $bundles $dom->documentElement->getElementsByTagName('bundle');
  561.             foreach($bundles as $bundleNode){
  562.                 $alias $bundleNode->getAttribute('alias');
  563.                 $directory $bundleNode->getAttribute('directory');
  564.                 $configFile str_replace('/', \DIRECTORY_SEPARATOR$modDir '/' trim($directory'/') . '/Resources/config/bundle.xml');
  565.                 // バンドルが読み込まれている場合はインストーラーを実行
  566.                 if(file_exists($configFile) && $this->container->has($alias '.bundle_setup')){
  567.                     $manager->installWithConfig($configFile);
  568.                     $setup $this->container->get($alias '.bundle_setup');
  569.                     $setup->install();
  570.                 }
  571.             }
  572.         }
  573.     }
  574.     public function forceCacheClear(PostResponseEvent $event)
  575.     {
  576.         set_time_limit(60 3);
  577.         if ($this->commandAfterResponse === false) {
  578.             return '';
  579.         }
  580.         $commands = [];
  581.         $log '';
  582.         /** @var Logger $logger */
  583.         $logger $this->container->get('monolog.logger.custom');
  584.         $logger->info('command cache clear start');
  585.         $commands[] = new ArrayInput([
  586.             'command' => 'cache:clear',
  587.             '--no-interaction' => true,
  588.             '-v' => true
  589.         ]);
  590.         foreach($commands as $command){
  591.             /** ArrayInput $command */
  592.             $log .= (string)$command . \PHP_EOL;
  593.             $log .= $this->runCommand($command);
  594.         }
  595.         $this->commandAfterResponse false;
  596.         $logger->info($log);
  597.         $logger->info('command cache clear finish');
  598.         return $log;
  599.     }
  600.     /**
  601.      * {@inheritdoc}
  602.      */
  603.     public static function getSubscribedEvents()
  604.     {
  605.         return [KernelEvents::TERMINATE => 'forceCacheClear'];
  606.     }
  607. }