src/Eccube/Controller/Admin/Content/MaintenanceController.php line 42

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Eccube\Controller\Admin\Content;
  13. use Eccube\Controller\AbstractController;
  14. use Eccube\Service\SystemService;
  15. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  16. use Symfony\Component\Form\Extension\Core\Type\FormType;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. class MaintenanceController extends AbstractController
  21. {
  22.     /**
  23.      * @var SystemService
  24.      */
  25.     protected $systemService;
  26.     public function __construct(SystemService $systemService)
  27.     {
  28.         $this->systemService $systemService;
  29.     }
  30.     /**
  31.      * メンテナンス管理ページを表示
  32.      *
  33.      * @Route("/%eccube_admin_route%/content/maintenance", name="admin_content_maintenance", methods={"GET", "POST"})
  34.      * @Template("@admin/Content/maintenance.twig")
  35.      */
  36.     public function index(Request $request)
  37.     {
  38.         $isMaintenance $this->systemService->isMaintenanceMode();
  39.         $builder $this->formFactory->createBuilder(FormType::class);
  40.         $form $builder->getForm();
  41.         $form->handleRequest($request);
  42.         if ($form->isSubmitted() && $form->isValid()) {
  43.             $changeTo $request->request->get('maintenance');
  44.             if ($isMaintenance === false && $changeTo == 'on') {
  45.                 // 現在メンテナンスモードではない かつ メンテナンスモードを有効 にした場合
  46.                 // メンテナンスモードを有効にする
  47.                 $this->systemService->enableMaintenance(''true);
  48.                 $this->addSuccess('admin.content.maintenance_switch__on_message''admin');
  49.             } elseif ($isMaintenance && $changeTo == 'off') {
  50.                 // 現在メンテナンスモード かつ メンテナンスモードを無効 にした場合
  51.                 // メンテナンスモードを無効にする
  52.                 $this->systemService->disableMaintenanceNow(''true);
  53.                 $this->addSuccess('admin.content.maintenance_switch__off_message''admin');
  54.             }
  55.             return $this->redirectToRoute('admin_content_maintenance');
  56.         }
  57.         return [
  58.             'form' => $form->createView(),
  59.             'isMaintenance' => $isMaintenance,
  60.         ];
  61.     }
  62.     /**
  63.      * メンテナンス解除
  64.      *
  65.      * キャッシュ管理やプラグインのインストール等の操作時にajax経由で解除する
  66.      * 権限管理設定でアクセス不可になるのを避けるため、ルーティングは/admin/disable_maintenanceで設定しています
  67.      *
  68.      * @Route("/%eccube_admin_route%/disable_maintenance/{mode}", requirements={"mode": "manual|auto_maintenance|auto_maintenance_update"}, name="admin_disable_maintenance", methods={"POST"})
  69.      */
  70.     public function disableMaintenance(Request $request$modeSystemService $systemService)
  71.     {
  72.         $this->isTokenValid();
  73.         if (!$request->isXmlHttpRequest()) {
  74.             throw new BadRequestHttpException();
  75.         }
  76.         if ($mode === 'manual') {
  77.             $path $this->getParameter('eccube_content_maintenance_file_path');
  78.             if (file_exists($path)) {
  79.                 unlink($this->getParameter('eccube_content_maintenance_file_path'));
  80.             }
  81.         } else {
  82.             $maintenanceMode = [
  83.                 'auto_maintenance' => SystemService::AUTO_MAINTENANCE,
  84.                 'auto_maintenance_update' => SystemService::AUTO_MAINTENANCE_UPDATE,
  85.             ];
  86.             $systemService->disableMaintenance($maintenanceMode[$mode]);
  87.         }
  88.         return $this->json(['success' => true]);
  89.     }
  90. }