|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Fi\PannelloAmministrazioneBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
|
6
|
|
|
use Symfony\Component\Console\Output\BufferedOutput; |
|
7
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
|
8
|
|
|
use Symfony\Component\Process\Process; |
|
9
|
|
|
use Fi\PannelloAmministrazioneBundle\DependencyInjection\ProjectPath; |
|
10
|
|
|
use Fi\OsBundle\DependencyInjection\OsFunctions; |
|
11
|
|
|
|
|
12
|
|
|
class PannelloAmministrazioneUtils |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
private $container; |
|
16
|
|
|
private $apppaths; |
|
17
|
|
|
|
|
18
|
1 |
|
public function __construct($container) |
|
19
|
|
|
{ |
|
20
|
1 |
|
$this->container = $container; |
|
21
|
1 |
|
$this->apppaths = new ProjectPath($container); |
|
22
|
1 |
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function clearcache($env = "") |
|
25
|
|
|
{ |
|
26
|
|
|
if (!$env) { |
|
27
|
|
|
$env = $this->container->get('kernel')->getEnvironment(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
$phpPath = OsFunctions::getPHPExecutableFromPath(); |
|
31
|
|
|
|
|
32
|
|
|
if (in_array($env, array('dev', 'test', 'localhost'))) { |
|
33
|
|
|
$command = $phpPath . ' ' . $this->apppaths->getConsole() . ' cache:clear ' |
|
34
|
|
|
. '--no-warmup --env=' . $env; |
|
35
|
|
|
} else { |
|
36
|
|
|
$command = $phpPath . ' ' . $this->apppaths->getConsole() . ' cache:clear ' |
|
37
|
|
|
. '--no-debug --no-warmup --env=' . $env; |
|
38
|
|
|
|
|
39
|
|
|
$command = $command . " && " . $phpPath . ' ' . $this->apppaths->getConsole() . ' cache:warmup ' |
|
40
|
|
|
. '--no-debug --env=' . $env; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
return PannelloAmministrazioneUtils::runCommand($command); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public static function runCommand($command) |
|
47
|
|
|
{ |
|
48
|
|
|
/* @var $process \Symfony\Component\Process\Process */ |
|
49
|
|
|
$return = array(); |
|
|
|
|
|
|
50
|
|
|
$process = new Process($command); |
|
51
|
|
|
$process->setTimeout(60 * 100); |
|
52
|
|
|
$process->run(); |
|
53
|
|
|
|
|
54
|
|
|
if (!$process->isSuccessful()) { |
|
55
|
|
|
$return = array("errcode" => -1, |
|
56
|
|
|
"command" => $command, |
|
57
|
|
|
"errmsg" => 'Errore nel comando ' . $command . $process->getErrorOutput() . $process->getOutput()); |
|
58
|
|
|
} else { |
|
59
|
|
|
$return = array("errcode" => 0, |
|
60
|
|
|
"command" => $command, |
|
61
|
|
|
"errmsg" => $process->getOutput() |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return $return; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function runSymfonyCommand($command, array $options = array()) |
|
69
|
|
|
{ |
|
70
|
|
|
$application = new Application($this->container->get('kernel')); |
|
71
|
|
|
$application->setAutoExit(false); |
|
72
|
|
|
|
|
73
|
|
|
$cmdoptions = array_merge(array('command' => $command), $options); |
|
74
|
|
|
|
|
75
|
|
|
$outputbuf = new BufferedOutput(); |
|
76
|
|
|
// return the output, don't use if you used NullOutput() |
|
77
|
|
|
$returncode = $application->run(new ArrayInput($cmdoptions), $outputbuf); |
|
78
|
|
|
$output = $outputbuf->fetch(); |
|
79
|
|
|
|
|
80
|
|
|
return array('errcode' => ($returncode == 0 ? false : true), 'command' => $cmdoptions['command'], 'message' => $output); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.