Completed
Pull Request — master (#4264)
by Craig
06:18
created

ExtensionController::uninstallAction()   B

Complexity

Conditions 10
Paths 14

Size

Total Lines 61
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 31
nc 14
nop 9
dl 0
loc 61
rs 7.6666
c 0
b 0
f 0

How to fix   Long Method    Complexity    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula - https://ziku.la/
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 Zikula\ExtensionsModule\Controller;
15
16
use Psr\Log\LoggerInterface;
17
use RuntimeException;
18
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
19
use Symfony\Component\HttpFoundation\RedirectResponse;
20
use Symfony\Component\HttpFoundation\Request;
21
use Symfony\Component\HttpFoundation\Response;
22
use Symfony\Component\Routing\Annotation\Route;
23
use Symfony\Component\Routing\RouterInterface;
24
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
25
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
26
use Zikula\BlocksModule\Entity\RepositoryInterface\BlockRepositoryInterface;
27
use Zikula\Bundle\CoreBundle\CacheClearer;
28
use Zikula\Bundle\CoreBundle\Composer\MetaData;
29
use Zikula\Bundle\CoreBundle\Controller\AbstractController;
30
use Zikula\Bundle\CoreBundle\HttpKernel\ZikulaHttpKernelInterface;
31
use Zikula\Bundle\CoreBundle\HttpKernel\ZikulaKernel;
32
use Zikula\Bundle\FormExtensionBundle\Form\Type\DeletionType;
33
use Zikula\Component\SortableColumns\Column;
34
use Zikula\Component\SortableColumns\SortableColumns;
35
use Zikula\ExtensionsModule\AbstractExtension;
36
use Zikula\ExtensionsModule\Api\VariableApi;
37
use Zikula\ExtensionsModule\Constant;
38
use Zikula\ExtensionsModule\Entity\ExtensionEntity;
39
use Zikula\ExtensionsModule\Entity\RepositoryInterface\ExtensionRepositoryInterface;
40
use Zikula\ExtensionsModule\Event\ExtensionListPreReSyncEvent;
41
use Zikula\ExtensionsModule\Event\ExtensionPostCacheRebuildEvent;
42
use Zikula\ExtensionsModule\Form\Type\ExtensionInstallType;
43
use Zikula\ExtensionsModule\Form\Type\ExtensionModifyType;
44
use Zikula\ExtensionsModule\Helper\BundleSyncHelper;
45
use Zikula\ExtensionsModule\Helper\ExtensionDependencyHelper;
46
use Zikula\ExtensionsModule\Helper\ExtensionHelper;
47
use Zikula\ExtensionsModule\Helper\ExtensionStateHelper;
48
use Zikula\PermissionsModule\Annotation\PermissionCheck;
49
use Zikula\RoutesModule\Event\RoutesNewlyAvailableEvent;
50
use Zikula\ThemeModule\Engine\Annotation\Theme;
51
use Zikula\ThemeModule\Engine\Engine;
52
53
/**
54
 * @Route("")
55
 */
56
class ExtensionController extends AbstractController
57
{
58
    /**
59
     * @Route("/list/{page}", methods = {"GET"}, requirements={"page" = "\d+"})
60
     * @PermissionCheck("admin")
61
     * @Theme("admin")
62
     * @Template("@ZikulaExtensionsModule/Extension/list.html.twig")
63
     */
64
    public function listAction(
65
        Request $request,
66
        EventDispatcherInterface $eventDispatcher,
67
        ExtensionRepositoryInterface $extensionRepository,
68
        BundleSyncHelper $bundleSyncHelper,
69
        RouterInterface $router,
70
        int $page = 1
71
    ): array {
72
        $modulesJustInstalled = $request->query->get('justinstalled');
73
        if (!empty($modulesJustInstalled)) {
74
            // notify the event dispatcher that new routes are available (ids of modules just installed avail as args)
75
            $eventDispatcher->dispatch(new RoutesNewlyAvailableEvent(json_decode($modulesJustInstalled)));
76
        }
77
78
        $sortableColumns = new SortableColumns($router, 'zikulaextensionsmodule_extension_list');
79
        $sortableColumns->addColumns([new Column('displayname'), new Column('state')]);
80
        $sortableColumns->setOrderByFromRequest($request);
81
82
        $upgradedExtensions = [];
83
        $extensionListPreReSyncEvent = new ExtensionListPreReSyncEvent();
84
        $eventDispatcher->dispatch($extensionListPreReSyncEvent);
85
        if (1 === $page && !$extensionListPreReSyncEvent->isPropagationStopped()) {
86
            // regenerate the extension list only when viewing the first page
87
            $extensionsInFileSystem = $bundleSyncHelper->scanForBundles();
88
            $upgradedExtensions = $bundleSyncHelper->syncExtensions($extensionsInFileSystem);
89
        }
90
91
        $pageSize = $this->getVar('itemsperpage');
92
93
        $paginator = $extensionRepository->getPagedCollectionBy([], [
94
            $sortableColumns->getSortColumn()->getName() => $sortableColumns->getSortDirection()
95
        ], $page, $pageSize);
0 ignored issues
show
Bug introduced by
It seems like $pageSize can also be of type false; however, parameter $pageSize of Zikula\ExtensionsModule\...:getPagedCollectionBy() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

95
        ], $page, /** @scrutinizer ignore-type */ $pageSize);
Loading history...
96
        $paginator->setRoute('zikulaextensionsmodule_extension_list');
97
98
        return [
99
            'sort' => $sortableColumns->generateSortableColumns(),
100
            'paginator' => $paginator,
101
            'upgradedExtensions' => $upgradedExtensions
102
        ];
103
    }
104
105
    /**
106
     * @Route("/activate/{id}/{token}", methods = {"GET"}, requirements={"id" = "^[1-9]\d*$"})
107
     * @PermissionCheck("admin")
108
     *
109
     * Activate an extension.
110
     *
111
     * @throws AccessDeniedException Thrown if the CSRF token is invalid
112
     */
113
    public function activateAction(
114
        int $id,
115
        string $token,
116
        ExtensionRepositoryInterface $extensionRepository,
117
        ExtensionStateHelper $extensionStateHelper,
118
        LoggerInterface $zikulaLogger,
119
        CacheClearer $cacheClearer
120
    ): RedirectResponse {
121
        if (!$this->isCsrfTokenValid('activate-extension', $token)) {
122
            throw new AccessDeniedException();
123
        }
124
125
        /** @var ExtensionEntity $extension */
126
        $extension = $extensionRepository->find($id);
127
        $zikulaLogger->notice(sprintf('Extension activating'), ['name' => $extension->getName()]);
128
        if (Constant::STATE_NOTALLOWED === $extension->getState()) {
129
            $this->addFlash('error', $this->trans('Error! Activation of %name% not allowed.', ['%name%' => $extension->getName()]));
130
        } else {
131
            // Update state
132
            $extensionStateHelper->updateState($id, Constant::STATE_ACTIVE);
133
//            $cacheClearer->clear('symfony');
134
            $this->addFlash('status', $this->trans('Done! Activated %name%.', ['%name%' => $extension->getName()]));
135
        }
136
137
        return $this->redirectToRoute('zikulaextensionsmodule_extension_list');
138
    }
139
140
    /**
141
     * @Route("/deactivate/{id}/{token}", methods = {"GET"}, requirements={"id" = "^[1-9]\d*$"})
142
     * @PermissionCheck("admin")
143
     *
144
     * Deactivate an extension
145
     *
146
     * @throws AccessDeniedException Thrown if the CSRF token is invalid
147
     */
148
    public function deactivateAction(
149
        int $id,
150
        string $token,
151
        ExtensionRepositoryInterface $extensionRepository,
152
        ExtensionStateHelper $extensionStateHelper,
153
        LoggerInterface $zikulaLogger,
154
        CacheClearer $cacheClearer
155
    ): RedirectResponse {
156
        if (!$this->isCsrfTokenValid('deactivate-extension', $token)) {
157
            throw new AccessDeniedException();
158
        }
159
160
        /** @var ExtensionEntity $extension */
161
        $extension = $extensionRepository->find($id);
162
        $zikulaLogger->notice(sprintf('Extension deactivating'), ['name' => $extension->getName()]);
163
        $defaultTheme = $this->getVariableApi()->get(VariableApi::CONFIG, 'defaulttheme');
164
        $adminTheme = $this->getVariableApi()->get('ZikulaAdminModule', 'admintheme');
165
166
        if (null !== $extension) {
167
            if (ZikulaKernel::isCoreExtension($extension->getName())) {
168
                $this->addFlash('error', $this->trans('Error! You cannot deactivate the %name%. It is required by the system.', ['%name%' => $extension->getName()]));
169
            } elseif (in_array($extension->getName(), [$defaultTheme, $adminTheme])) {
170
                $this->addFlash('error', $this->trans('Error! You cannot deactivate the %name%. The theme is in use.', ['%name%' => $extension->getName()]));
171
            } else {
172
                // Update state
173
                $extensionStateHelper->updateState($id, Constant::STATE_INACTIVE);
174
//                $cacheClearer->clear('symfony');
175
                $this->addFlash('status', $this->trans('Done! Deactivated %name%.', ['%name%' => $extension->getName()]));
176
            }
177
        }
178
179
        return $this->redirectToRoute('zikulaextensionsmodule_extension_list');
180
    }
181
182
    /**
183
     * @Route("/modify/{id}/{forceDefaults}", requirements={"id" = "^[1-9]\d*$", "forceDefaults" = "0|1"})
184
     * @Theme("admin")
185
     * @Template("@ZikulaExtensionsModule/Extension/modify.html.twig")
186
     *
187
     * Modify a module.
188
     *
189
     * @return array|RedirectResponse
190
     * @throws AccessDeniedException Thrown if the user doesn't have admin permissions for modifying the extension
191
     */
192
    public function modifyAction(
193
        Request $request,
194
        ZikulaHttpKernelInterface $kernel,
195
        ExtensionEntity $extension,
196
        CacheClearer $cacheClearer,
197
        bool $forceDefaults = false
198
    ) {
199
        if (!$this->hasPermission('ZikulaExtensionsModule::modify', $extension->getName() . '::' . $extension->getId(), ACCESS_ADMIN)) {
200
            throw new AccessDeniedException();
201
        }
202
203
        /** @var AbstractExtension $extensionBundle */
204
        $extensionBundle = $kernel->getBundle($extension->getName());
205
        $metaData = $extensionBundle->getMetaData()->getFilteredVersionInfoArray();
206
207
        if ($forceDefaults) {
208
            $extension->setName($metaData['name']);
209
            $extension->setUrl($metaData['url']);
210
            $extension->setDescription($metaData['description']);
211
        }
212
213
        $form = $this->createForm(ExtensionModifyType::class, $extension);
214
        $form->handleRequest($request);
215
        if ($form->isSubmitted() && $form->isValid()) {
216
            if ($form->get('defaults')->isClicked()) {
0 ignored issues
show
Bug introduced by
The method isClicked() does not exist on Symfony\Component\Form\FormInterface. It seems like you code against a sub-type of Symfony\Component\Form\FormInterface such as Symfony\Component\Form\SubmitButton. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

216
            if ($form->get('defaults')->/** @scrutinizer ignore-call */ isClicked()) {
Loading history...
217
                $this->addFlash('info', 'Default values reloaded. Save to confirm.');
218
219
                return $this->redirectToRoute('zikulaextensionsmodule_extension_modify', ['id' => $extension->getId(), 'forceDefaults' => 1]);
220
            }
221
            if ($form->get('save')->isClicked()) {
222
                $em = $this->getDoctrine()->getManager();
223
                $em->persist($extension);
224
                $em->flush();
225
226
                $cacheClearer->clear('symfony.routing');
227
                $this->addFlash('status', 'Done! Extension updated.');
228
            } elseif ($form->get('cancel')->isClicked()) {
229
                $this->addFlash('status', 'Operation cancelled.');
230
            }
231
232
            return $this->redirectToRoute('zikulaextensionsmodule_extension_list');
233
        }
234
235
        return [
236
            'form' => $form->createView()
237
        ];
238
    }
239
240
    /**
241
     * @Route("/compatibility/{id}", methods = {"GET"}, requirements={"id" = "^[1-9]\d*$"})
242
     * @Theme("admin")
243
     * @Template("@ZikulaExtensionsModule/Extension/compatibility.html.twig")
244
     *
245
     * Display information of a module compatibility with the version of the core
246
     *
247
     * @throws AccessDeniedException Thrown if the user doesn't have admin permission to the requested module
248
     */
249
    public function compatibilityAction(ExtensionEntity $extension): array
250
    {
251
        if (!$this->hasPermission('ZikulaExtensionsModule::', $extension->getName() . '::' . $extension->getId(), ACCESS_ADMIN)) {
252
            throw new AccessDeniedException();
253
        }
254
255
        return [
256
            'extension' => $extension
257
        ];
258
    }
259
260
    /**
261
     * @Route("/install/{id}/{token}", requirements={"id" = "^[1-9]\d*$"})
262
     * @PermissionCheck("admin")
263
     * @Theme("admin")
264
     * @Template("@ZikulaExtensionsModule/Extension/install.html.twig")
265
     *
266
     * Install and initialise an extension.
267
     *
268
     * @return array|RedirectResponse
269
     * @throws AccessDeniedException Thrown if the CSRF token is invalid
270
     */
271
    public function installAction(
272
        Request $request,
273
        ExtensionEntity $extension,
274
        string $token,
275
        ZikulaHttpKernelInterface $kernel,
276
        ExtensionRepositoryInterface $extensionRepository,
277
        ExtensionHelper $extensionHelper,
278
        ExtensionStateHelper $extensionStateHelper,
279
        ExtensionDependencyHelper $dependencyHelper,
280
        LoggerInterface $zikulaLogger,
281
        CacheClearer $cacheClearer
282
    ) {
283
        $id = $extension->getId();
284
        if (!$this->isCsrfTokenValid('install-extension', $token)) {
285
            throw new AccessDeniedException();
286
        }
287
288
        if (!$kernel->isBundle($extension->getName())) {
289
            // set state to transitional which marks the bundle as active for the kernel
290
            if (Constant::STATE_TRANSITIONAL === $extension->getState()) {
291
                $zikulaLogger->info('@1 Wait 3');
292
                sleep(3);
293
            } else {
294
                $extensionStateHelper->updateState($id, Constant::STATE_TRANSITIONAL);
295
//                $cacheClearer->clear('symfony');
296
            }
297
298
            return $this->redirectToRoute('zikulaextensionsmodule_extension_install', ['id' => $id, 'token' => $token]);
299
        }
300
301
        // check if installer class is known in container
302
        $extensionBundle = $kernel->getBundle($extension->getName());
303
        $installerClass = $extensionHelper->getExtensionInstallerInstance($extensionBundle);
304
        if (null === $installerClass) {
305
            // if not, wait and try again
306
            $zikulaLogger->info('@2 Wait 3');
307
            sleep(3);
308
309
            return $this->redirectToRoute('zikulaextensionsmodule_extension_install', ['id' => $id, 'token' => $token]);
310
        }
311
312
        $unsatisfiedDependencies = $dependencyHelper->getUnsatisfiedExtensionDependencies($extension);
313
        $form = $this->createForm(ExtensionInstallType::class, [
314
            'dependencies' => $this->formatDependencyCheckboxArray($extensionRepository, $unsatisfiedDependencies)
315
        ]);
316
        $hasNoUnsatisfiedDependencies = empty($unsatisfiedDependencies);
317
        $form->handleRequest($request);
318
        if ($hasNoUnsatisfiedDependencies || ($form->isSubmitted() && $form->isValid())) {
319
            if ($hasNoUnsatisfiedDependencies || $form->get('install')->isClicked()) {
320
                $extensionsInstalled = [];
321
                $data = $form->getData();
322
                foreach ($data['dependencies'] as $dependencyId => $installSelected) {
323
                    if (!$installSelected && MetaData::DEPENDENCY_REQUIRED !== $unsatisfiedDependencies[$dependencyId]->getStatus()) {
324
                        continue;
325
                    }
326
                    $dependencyExtensionEntity = $extensionRepository->get($unsatisfiedDependencies[$dependencyId]->getModname());
327
                    if (isset($dependencyExtensionEntity)) {
328
                        if (!$extensionHelper->install($dependencyExtensionEntity)) {
329
                            $this->addFlash('error', $this->trans('Failed to install dependency "%name%"!', ['%name%' => $dependencyExtensionEntity->getName()]));
330
331
                            return $this->redirectToRoute('zikulaextensionsmodule_extension_list');
332
                        }
333
                        $extensionsInstalled[] = $dependencyExtensionEntity->getId();
334
                        $this->addFlash('status', $this->trans('Installed dependency "%name%".', ['%name%' => $dependencyExtensionEntity->getName()]));
335
                    } else {
336
                        $this->addFlash('warning', $this->trans('Warning: could not install selected dependency "%name%".', ['%name%' => $unsatisfiedDependencies[$dependencyId]->getModname()]));
337
                    }
338
                }
339
                if ($extensionHelper->install($extension)) {
340
                    $this->addFlash('status', $this->trans('Done! Installed "%name%".', ['%name%' => $extension->getName()]));
341
                    $extensionsInstalled[] = $id;
342
//                    $cacheClearer->clear('symfony');
343
344
                    return $this->redirectToRoute('zikulaextensionsmodule_extension_postinstall', ['extensions' => json_encode($extensionsInstalled)]);
345
                }
346
                $extensionStateHelper->updateState($id, Constant::STATE_UNINITIALISED);
347
                $this->addFlash('error', $this->trans('Initialization of "%name%" failed!', ['%name%' => $extension->getName()]));
348
            }
349
            if ($form->get('cancel')->isClicked()) {
350
                $extensionStateHelper->updateState($id, Constant::STATE_UNINITIALISED);
351
                $this->addFlash('status', 'Operation cancelled.');
352
            }
353
354
            return $this->redirectToRoute('zikulaextensionsmodule_extension_list');
355
        }
356
357
        return [
358
            'dependencies' => $unsatisfiedDependencies,
359
            'extension' => $extension,
360
            'form' => $form->createView()
361
        ];
362
    }
363
364
    /**
365
     * Post-installation action to trigger the MODULE_POSTINSTALL event.
366
     * The additional Action is required because this event must occur AFTER the rebuild of the cache which occurs on Request.
367
     *
368
     * @Route("/postinstall/{extensions}", methods = {"GET"})
369
     */
370
    public function postInstallAction(
371
        ExtensionRepositoryInterface $extensionRepository,
372
        ZikulaHttpKernelInterface $kernel,
373
        EventDispatcherInterface $eventDispatcher,
374
        string $extensions = null
375
    ): RedirectResponse {
376
        if (!empty($extensions)) {
377
            $extensions = json_decode($extensions);
378
            foreach ($extensions as $extensionId) {
379
                /** @var ExtensionEntity $extensionEntity */
380
                $extensionEntity = $extensionRepository->find($extensionId);
381
                if (null === $extensionRepository) {
382
                    continue;
383
                }
384
                /** @var AbstractExtension $extensionBundle */
385
                $extensionBundle = $kernel->getBundle($extensionEntity->getName());
386
                if (null === $extensionBundle) {
387
                    continue;
388
                }
389
                $eventDispatcher->dispatch(new ExtensionPostCacheRebuildEvent($extensionBundle, $extensionEntity));
390
            }
391
        }
392
393
        return $this->redirectToRoute('zikulaextensionsmodule_extension_list', ['justinstalled' => json_encode($extensions)]);
394
    }
395
396
    /**
397
     * Create array suitable for checkbox FormType [[ID => bool][ID => bool]].
398
     */
399
    private function formatDependencyCheckboxArray(
400
        ExtensionRepositoryInterface $extensionRepository,
401
        array $dependencies
402
    ): array {
403
        $return = [];
404
        foreach ($dependencies as $dependency) {
405
            /** @var ExtensionEntity $dependencyExtension */
406
            $dependencyExtension = $extensionRepository->get($dependency->getModname());
407
            $return[$dependency->getId()] = null !== $dependencyExtension;
408
        }
409
410
        return $return;
411
    }
412
413
    /**
414
     * @Route("/upgrade/{id}/{token}", requirements={"id" = "^[1-9]\d*$"})
415
     * @PermissionCheck("admin")
416
     *
417
     * Upgrade an extension.
418
     *
419
     * @throws AccessDeniedException Thrown if the CSRF token is invalid
420
     */
421
    public function upgradeAction(
422
        ExtensionEntity $extension,
423
        $token,
424
        ExtensionHelper $extensionHelper
425
    ): RedirectResponse {
426
        if (!$this->isCsrfTokenValid('upgrade-extension', $token)) {
427
            throw new AccessDeniedException();
428
        }
429
430
        $result = $extensionHelper->upgrade($extension);
431
        if ($result) {
432
            $this->addFlash('status', $this->trans('%name% upgraded to new version and activated.', ['%name%' => $extension->getDisplayname()]));
433
        } else {
434
            $this->addFlash('error', 'Extension upgrade failed!');
435
        }
436
437
        return $this->redirectToRoute('zikulaextensionsmodule_extension_list');
438
    }
439
440
    /**
441
     * @Route("/uninstall/{id}/{token}", requirements={"id" = "^[1-9]\d*$"})
442
     * @PermissionCheck("admin")
443
     * @Theme("admin")
444
     * @Template("@ZikulaExtensionsModule/Extension/uninstall.html.twig")
445
     *
446
     * Uninstall an extension.
447
     *
448
     * @return array|Response|RedirectResponse
449
     * @throws AccessDeniedException Thrown if the CSRF token is invalid
450
     */
451
    public function uninstallAction(
452
        Request $request,
453
        ExtensionEntity $extension,
454
        string $token,
455
        ZikulaHttpKernelInterface $kernel,
456
        BlockRepositoryInterface $blockRepository,
457
        ExtensionHelper $extensionHelper,
458
        ExtensionStateHelper $extensionStateHelper,
459
        ExtensionDependencyHelper $dependencyHelper,
460
        CacheClearer $cacheClearer
461
    ) {
462
        if (!$this->isCsrfTokenValid('uninstall-extension', $token)) {
463
            throw new AccessDeniedException();
464
        }
465
466
        if (Constant::STATE_MISSING === $extension->getState()) {
467
            throw new RuntimeException($this->trans('Error! The requested extension cannot be uninstalled because its files are missing!'));
468
        }
469
        if (!$kernel->isBundle($extension->getName())) {
470
            $extensionStateHelper->updateState($extension->getId(), Constant::STATE_TRANSITIONAL);
471
//            $cacheClearer->clear('symfony');
472
        }
473
        $requiredDependents = $dependencyHelper->getDependentExtensions($extension);
474
        $blocks = $blockRepository->findBy(['module' => $extension]);
475
476
        $form = $this->createForm(DeletionType::class, [], [
477
            'action' => $this->generateUrl('zikulaextensionsmodule_extension_uninstall', [
478
                'id' => $extension->getId(),
479
                'token' => $token
480
            ]),
481
        ]);
482
        $form->handleRequest($request);
483
        if ($form->isSubmitted() && $form->isValid()) {
484
            if ($form->get('delete')->isClicked()) {
485
                // remove dependent extensions
486
                if (!$extensionHelper->uninstallArray($requiredDependents)) {
487
                    $this->addFlash('error', 'Error: Could not uninstall dependent extensions.');
488
489
                    return $this->redirectToRoute('zikulaextensionsmodule_extension_list');
490
                }
491
                // remove blocks
492
                $blockRepository->remove($blocks);
493
494
                // remove the extension
495
                if ($extensionHelper->uninstall($extension)) {
496
                    $this->addFlash('status', 'Done! Uninstalled extension.');
497
                } else {
498
                    $this->addFlash('error', 'Extension removal failed! (note: blocks and dependents may have been removed)');
499
                }
500
            } elseif ($form->get('cancel')->isClicked()) {
501
                $this->addFlash('status', 'Operation cancelled.');
502
            }
503
504
            return $this->redirectToRoute('zikulaextensionsmodule_extension_postuninstall');
505
        }
506
507
        return [
508
            'form' => $form->createView(),
509
            'extension' => $extension,
510
            'blocks' => $blocks,
511
            'requiredDependents' => $requiredDependents
512
        ];
513
    }
514
515
    /**
516
     * @Route("/post-uninstall")
517
     * @PermissionCheck("admin")
518
     *
519
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
520
     */
521
    public function postUninstallAction(CacheClearer $cacheClearer)
522
    {
523
        $cacheClearer->clear('symfony');
524
525
        return $this->redirectToRoute('zikulaextensionsmodule_extension_list');
526
    }
527
528
    /**
529
     * @Route("/theme-preview/{themeName}")
530
     * @PermissionCheck("admin")
531
     */
532
    public function previewAction(Engine $engine, string $themeName): Response
533
    {
534
        $engine->setActiveTheme($themeName);
535
        $this->addFlash('warning', 'Please note that blocks may appear out of place or even missing in a theme preview because position names are not consistent from theme to theme.');
536
537
        return $this->forward('Zikula\Bundle\CoreBundle\Controller\MainController::homeAction');
538
    }
539
}
540