Completed
Pull Request — 4.0 (#4022)
by
unknown
06:16
created

MaintenanceController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B index() 0 34 7
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Controller\Admin\Content;
15
16
use Eccube\Controller\AbstractController;
17
use Knp\Component\Pager\Paginator;
18
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
19
use Symfony\Component\HttpFoundation\Request;
20
use Symfony\Component\Routing\Annotation\Route;
21
use Symfony\Component\Form\Extension\Core\Type\FormType;
22
use Eccube\Service\SystemService;
23
24
class MaintenanceController extends AbstractController
25
{
26
    /**
27
     * @var SystemService
28
     */
29
    protected $systemService;
30
31
    public function __construct(SystemService $systemService) {
32
        $this->systemService = $systemService;
33
    }
34
35
    /**
36
     * メンテナンス管理ページを表示
37
     *
38
     * @Route("/%eccube_admin_route%/content/maintenance", name="admin_content_maintenance")
39
     * @Template("@admin/Content/maintenance.twig")
40
     */
41
    public function index(Request $request)
42
    {
43
        $isMaintenance = $this->systemService->isMaintenanceMode();
44
45
        $builder = $this->formFactory->createBuilder(FormType::class);
46
        $form = $builder->getForm();
47
        $form->handleRequest($request);
48
49
        if ($form->isSubmitted() && $form->isValid()) {
50
            $changeTo = $request->request->get('maintenance');
51
            $path = $this->container->getParameter('eccube_content_maintenance_file_path');
52
53
            if ($isMaintenance === false && $changeTo == 'on') {
54
                // 現在メンテナンスモードではない かつ メンテナンスモードを有効 にした場合
55
                // メンテナンスモードを有効にする
56
                file_put_contents($path, null);
57
58
                $this->addSuccess('admin.content.maintenance_switch__on_message', 'admin');
59
            } elseif ($isMaintenance && $changeTo == 'off') {
60
                // 現在メンテナンスモード かつ メンテナンスモードを無効 にした場合
61
                // メンテナンスモードを無効にする
62
                unlink($path);
63
64
                $this->addSuccess('admin.content.maintenance_switch__off_message', 'admin');
65
            }
66
67
            return $this->redirectToRoute('admin_content_maintenance');
68
        }
69
70
        return [
71
            'form' => $form->createView(),
72
            'isMaintenance' => $isMaintenance,
73
        ];
74
    }
75
}
76