Completed
Push — master ( cd3b2e...50c111 )
by Craig
07:10
created

UpdateController::dumpJsRoutesAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 3
Ratio 27.27 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 2
dl 3
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Routes.
4
 *
5
 * @copyright Zikula contributors (Zikula)
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 * @author Zikula contributors <[email protected]>.
8
 * @link http://www.zikula.org
9
 * @link http://zikula.org
10
 * @version Generated by ModuleStudio 0.7.1 (http://modulestudio.de).
11
 */
12
13
namespace Zikula\RoutesModule\Controller;
14
15
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
16
use Symfony\Component\HttpFoundation\Request;
17
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
18
use Zikula\Core\Controller\AbstractController;
19
use Zikula\ThemeModule\Engine\Annotation\Theme;
20
21
/**
22
 * Update controller for renewing route information on demand.
23
 */
24
class UpdateController extends AbstractController
25
{
26
    /**
27
     * Reloads the routes and dumps exposed JS routes.
28
     *
29
     * @Route("/update/reload",
30
     *        methods = {"GET", "POST"}
31
     * )
32
     * @Theme("admin")
33
     *
34
     * @param Request $request Current request instance
35
     *
36
     * @return Response Output
37
     *
38
     * @throws AccessDeniedException Thrown if the user doesn't have required permissions
39
     */
40
    public function reloadAction(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
41
    {
42
        $objectType = 'route';
43 View Code Duplication
        if (!$this->hasPermission('ZikulaRoutesModule:' . ucfirst($objectType) . ':', '::', ACCESS_ADMIN)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
44
            throw new AccessDeniedException();
45
        }
46
47
        $cacheClearer = $this->get('zikula.cache_clearer');
48
        $cacheClearer->clear('symfony.routing');
49
50
        $this->addFlash('status', $this->__('Done! Routes reloaded.'));
51
52
        // reload **all** JS routes
53
        $this->dumpJsRoutes($lang);
0 ignored issues
show
Bug introduced by
The variable $lang does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
54
55
        return $this->redirectToRoute('zikularoutesmodule_route_adminview');
56
    }
57
58
    /**
59
     * Renews multilingual routing settings.
60
     *
61
     * @Route("/update/renew",
62
     *        methods = {"GET", "POST"}
63
     * )
64
     * @Theme("admin")
65
     *
66
     * @param Request $request Current request instance
67
     *
68
     * @return Response Output
69
     *
70
     * @throws AccessDeniedException Thrown if the user doesn't have required permissions
71
     */
72
    public function renewAction(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
73
    {
74
        $objectType = 'route';
75 View Code Duplication
        if (!$this->hasPermission('ZikulaRoutesModule:' . ucfirst($objectType) . ':', '::', ACCESS_ADMIN)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
76
            throw new AccessDeniedException();
77
        }
78
79
        // Renew the routing settings.
80
        $this->get('zikula_routes_module.multilingual_routing_helper')->reloadMultilingualRoutingSettings();
81
82
        $this->addFlash('status', $this->__('Done! Routing settings renewed.'));
83
84
        return $this->redirectToRoute('zikularoutesmodule_route_adminview');
85
    }
86
87
    /**
88
     * Dumps the routes exposed to javascript.
89
     *
90
     * @Route("/update/dump/{lang}",
91
     *        name = "zikularoutesmodule_update_dumpjsroutes",
92
     *        methods = {"GET"}
93
     * )
94
     * @Theme("admin")
95
     *
96
     * @param Request $request Current request instance
97
     *
98
     * @return Response Output
99
     *
100
     * @throws AccessDeniedException Thrown if the user doesn't have required permissions
101
     */
102
    public function dumpJsRoutesAction(Request $request, $lang = null)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
103
    {
104
        $objectType = 'route';
105 View Code Duplication
        if (!$this->hasPermission('ZikulaRoutesModule:' . ucfirst($objectType) . ':', '::', ACCESS_ADMIN)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
106
            throw new AccessDeniedException();
107
        }
108
109
        $this->dumpJsRoutes($lang);
110
111
        return $this->redirectToRoute('zikularoutesmodule_route_adminview');
112
    }
113
114
    /**
115
     * Dumps exposed JS routes to '/web/js/fos_js_routes.js'.
116
     */
117
    private function dumpJsRoutes($lang = null)
118
    {
119
        $routeDumperHelper = $this->get('zikula_routes_module.route_dumper_helper');
120
        $result = $routeDumperHelper->dumpJsRoutes($lang);
121
122
        if ($result == '') {
123
            $this->addFlash('status', $this->__f('Done! Exposed JS Routes dumped to %s.', ['%s' => 'web/js/fos_js_routes.js']));
124
        } else {
125
            $this->addFlash('error', $this->__f('Error! There was an error dumping exposed JS Routes: %s', ['%s' => $result]));
126
        }
127
    }
128
}
129