Completed
Pull Request — 4.0 (#4084)
by
unknown
06:18
created

JsController::index()   B

Complexity

Conditions 6
Paths 10

Size

Total Lines 32

Duplication

Lines 32
Ratio 100 %

Importance

Changes 0
Metric Value
cc 6
nc 10
nop 1
dl 32
loc 32
rs 8.7857
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.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
13
namespace Eccube\Controller\Admin\Content;
14
15
use Eccube\Controller\AbstractController;
16
use Eccube\Form\Type\Admin\MainEditType;
17
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
18
use Symfony\Component\Filesystem\Exception\IOException;
19
use Symfony\Component\Filesystem\Filesystem;
20
use Symfony\Component\Form\Extension\Core\Type\FormType;
21
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
22
use Symfony\Component\HttpFoundation\Request;
23
use Symfony\Component\Routing\Annotation\Route;
24
25 View Code Duplication
class JsController extends AbstractController
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
{
27
    /**
28
     * @Route("/%eccube_admin_route%/content/js", name="admin_content_js")
29
     * @Template("@admin/Content/js.twig")
30
     */
31
    public function index(Request $request)
32
    {
33
        $builder = $this->formFactory
34
            ->createBuilder(FormType::class)
35
            ->add('js', TextareaType::class, [
36
                'required' => false
37
            ]);
38
        $form = $builder->getForm();
39
        $jsPath = $this->getParameter('eccube_html_dir').'/user_data/assets/js/customize.js';
40
        if (file_exists($jsPath) && is_writable($jsPath)) {
41
            $form->get('js')->setData(file_get_contents($jsPath));
42
        }
43
44
        $form->handleRequest($request);
45
        if ($form->isSubmitted() && $form->isValid()) {
46
47
            $fs = new Filesystem();
48
            try {
49
                $fs->dumpFile($jsPath, $form->get('js')->getData());
50
                $this->addSuccess('admin.common.save_complete', 'admin');
51
                return $this->redirectToRoute('admin_content_js');
52
            } catch (IOException $e) {
53
                $message = trans('admin.common.save_error');
54
                $this->addError($message, 'admin');
55
                log_error($message, [$jsPath, $e]);
56
            }
57
58
        }
59
        return [
60
            'form' => $form->createView()
61
        ];
62
    }
63
}