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
|
|
|
|
11
|
|
|
class ScriptController extends Controller |
12
|
|
|
{ |
13
|
|
|
public function redisAction() |
14
|
|
|
{ |
15
|
|
|
$data['success'] = 1; |
|
|
|
|
16
|
|
|
|
17
|
|
|
$clients = []; |
18
|
|
|
foreach ($this->container->getServiceIds() as $id) { |
|
|
|
|
19
|
|
|
if (substr($id, 0, 9) === 'snc_redis' && $this->container->get($id) instanceof Client) { |
20
|
|
|
$clients[] = $id; |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
foreach ($clients as $snc) { |
25
|
|
|
$this->container->get($snc)->flushdb(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
return new JsonResponse($data, 200, [ |
29
|
|
|
'Cache-Control' => 'no-cache', |
30
|
|
|
]); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function cacheAction() |
34
|
|
|
{ |
35
|
|
|
global $kernel; |
36
|
|
|
|
37
|
|
|
if ('AppCache' === get_class($kernel)) { |
38
|
|
|
$kernel = $kernel->getKernel(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$commands = [ |
42
|
|
|
'clear', |
43
|
|
|
'warmup', |
44
|
|
|
]; |
45
|
|
|
foreach ($commands as $command) { |
46
|
|
|
$application = new Application($kernel); |
47
|
|
|
$application->setAutoExit(false); |
48
|
|
|
$input = new ArrayInput([ |
49
|
|
|
'command' => 'cache:'.$command, |
50
|
|
|
'--env' => $kernel->getEnvironment(), |
51
|
|
|
]); |
52
|
|
|
$application->run($input); |
53
|
|
|
$data['success'] = 1; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return new JsonResponse($data, 200, [ |
|
|
|
|
57
|
|
|
'Cache-Control' => 'no-cache', |
58
|
|
|
]); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function lexikAction() |
62
|
|
|
{ |
63
|
|
|
global $kernel; |
64
|
|
|
|
65
|
|
|
if ('AppCache' === get_class($kernel)) { |
66
|
|
|
$kernel = $kernel->getKernel(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$application = new Application($kernel); |
70
|
|
|
$application->setAutoExit(false); |
71
|
|
|
|
72
|
|
|
$input = new ArrayInput([ |
73
|
|
|
'command' => 'sludio:lexik:clear', |
74
|
|
|
]); |
75
|
|
|
$application->run($input); |
76
|
|
|
$data['success'] = 1; |
|
|
|
|
77
|
|
|
|
78
|
|
|
return new JsonResponse($data, 200, [ |
79
|
|
|
'Cache-Control' => 'no-cache', |
80
|
|
|
]); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|