Completed
Push — master ( 06c1ce...67d37c )
by Jeroen
06:20
created

Controller/TranslatorCommandController.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\TranslatorBundle\Controller;
4
5
use Kunstmaan\AdminBundle\FlashMessages\FlashTypes;
6
use Kunstmaan\TranslatorBundle\Model\Export\ExportCommand;
7
use Kunstmaan\TranslatorBundle\Model\Import\ImportCommand;
8
use Symfony\Component\Routing\Annotation\Route;
9
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
10
use Symfony\Component\HttpFoundation\RedirectResponse;
11
12
class TranslatorCommandController extends Controller
13
{
14
    /**
15
     * @Route("/clear-cache", name="KunstmaanTranslatorBundle_command_clear_cache")
16
     */
17
    public function clearCacheAction()
18
    {
19
        $this->get('kunstmaan_translator.service.translator.resource_cacher')->flushCache();
20
        $this->addFlash(
21
            FlashTypes::SUCCESS,
22
            $this->get('translator')->trans('kuma_translator.command.clear.flash.success')
23
        );
24
25
        return new RedirectResponse($this->generateUrl('KunstmaanTranslatorBundle_settings_translations'));
26
    }
27
28
    /**
29
     * @Route("/import", name="KunstmaanTranslatorBundle_command_import")
30
     */
31 View Code Duplication
    public function importAction()
32
    {
33
        $importCommand = new ImportCommand();
34
        $importCommand
35
            ->setForce(false)
36
            ->setDefaultBundle($this->getParameter('kuma_translator.default_bundle'))
37
            ->setBundles($this->getParameter('kuma_translator.bundles'))
38
            ->setGlobals(true);
39
40
        $this->get('kunstmaan_translator.service.importer.command_handler')->executeImportCommand($importCommand);
41
42
        $this->addFlash(
43
            FlashTypes::SUCCESS,
44
            $this->get('translator')->trans('kuma_translator.command.import.flash.success')
45
        );
46
47
        return new RedirectResponse($this->generateUrl('KunstmaanTranslatorBundle_settings_translations'));
48
    }
49
50
    /**
51
     * @Route("/import-forced", name="KunstmaanTranslatorBundle_command_import_forced")
52
     */
53 View Code Duplication
    public function importForcedAction()
54
    {
55
        $importCommand = new ImportCommand();
56
        $importCommand
57
            ->setForce(true)
58
            ->setDefaultBundle($this->getParameter('kuma_translator.default_bundle'))
59
            ->setBundles($this->getParameter('kuma_translator.bundles'))
60
            ->setGlobals(false);
61
62
        $this->get('kunstmaan_translator.service.importer.command_handler')->executeImportCommand($importCommand);
63
64
        $this->addFlash(
65
            FlashTypes::SUCCESS,
66
            $this->get('translator')->trans('kuma_translator.command.import.flash.force_success')
67
        );
68
69
        return new RedirectResponse($this->generateUrl('KunstmaanTranslatorBundle_settings_translations'));
70
    }
71
72
    /**
73
     * @Route("/export", name="KunstmaanTranslatorBundle_command_export")
74
     *
75
     * @deprecated Using the "KunstmaanTranslatorBundle_command_export" route is deprecated since KunstmaanTranslatorBundle 5.4 and will be removed in KunstmaanTranslatorBundle 6.0. Use the default adminlist bundle export functionality instead.
76
     */
77
    public function exportAction()
78
    {
79
        // NEXT_MAJOR this route will be removed because we are now using the common export logic
80
        @trigger_error('Using the "KunstmaanTranslatorBundle_command_export" route is deprecated since KunstmaanTranslatorBundle 5.4 and will be removed in KunstmaanTranslatorBundle 6.0. Use the default adminlist bundle export functionality instead.', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
81
        $locales = $this->getParameter('kuma_translator.managed_locales');
82
        $exportCommand = new ExportCommand();
83
        $exportCommand
84
            ->setLocales($locales)
85
            ->setFormat('csv');
86
87
        $response = $this->get('kunstmaan_translator.service.exporter.command_handler')->executeExportCSVCommand($exportCommand);
88
89
        return $response;
90
    }
91
}
92