1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sludio\HelperBundle\Script\Controller; |
4
|
|
|
|
5
|
|
|
use Predis\Client; |
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
8
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
9
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
10
|
|
|
use Sludio\HelperBundle\Translatable\Repository\TranslatableRepository as Sludio; |
11
|
|
|
|
12
|
|
|
class ScriptController extends Controller |
13
|
|
|
{ |
14
|
|
|
public function redisAction() |
15
|
|
|
{ |
16
|
|
|
$clients = []; |
17
|
|
|
foreach ($this->container->getServiceIds() as $id) { |
|
|
|
|
18
|
|
View Code Duplication |
if (substr($id, 0, 9) === 'snc_redis' && $this->container->get($id) instanceof Client) { |
|
|
|
|
19
|
|
|
$clients[] = $id; |
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
foreach ($clients as $snc) { |
24
|
|
|
$this->container->get($snc)->flushdb(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
return new JsonResponse(['success' => 1], 200, [ |
28
|
|
|
'Cache-Control' => 'no-cache', |
29
|
|
|
]); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function cacheAction() |
33
|
|
|
{ |
34
|
|
|
global $kernel; |
35
|
|
|
|
36
|
|
|
if ('AppCache' === get_class($kernel)) { |
37
|
|
|
$kernel = $kernel->getKernel(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$commands = [ |
41
|
|
|
'clear', |
42
|
|
|
'warmup', |
43
|
|
|
]; |
44
|
|
|
foreach ($commands as $command) { |
45
|
|
|
$application = new Application($kernel); |
46
|
|
|
$application->setAutoExit(false); |
47
|
|
|
$input = new ArrayInput([ |
48
|
|
|
'command' => 'cache:'.$command, |
49
|
|
|
'--env' => $kernel->getEnvironment(), |
50
|
|
|
]); |
51
|
|
|
$application->run($input); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return new JsonResponse(['success' => 1], 200, [ |
55
|
|
|
'Cache-Control' => 'no-cache', |
56
|
|
|
]); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function lexikAction() |
60
|
|
|
{ |
61
|
|
|
global $kernel; |
62
|
|
|
|
63
|
|
|
if ('AppCache' === get_class($kernel)) { |
64
|
|
|
$kernel = $kernel->getKernel(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$application = new Application($kernel); |
68
|
|
|
$application->setAutoExit(false); |
69
|
|
|
|
70
|
|
|
$input = new ArrayInput([ |
71
|
|
|
'command' => 'sludio:lexik:clear', |
72
|
|
|
]); |
73
|
|
|
$application->run($input); |
74
|
|
|
|
75
|
|
|
return new JsonResponse(['success' => 1], 200, [ |
76
|
|
|
'Cache-Control' => 'no-cache', |
77
|
|
|
]); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function generateAction() |
81
|
|
|
{ |
82
|
|
|
Sludio::getAllTranslations(); |
83
|
|
|
|
84
|
|
|
return new JsonResponse(['success' => 1], 200, [ |
85
|
|
|
'Cache-Control' => 'no-cache', |
86
|
|
|
]); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|