1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cdf\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\OsBundle\DependencyInjection\OsFunctions; |
10
|
|
|
|
11
|
|
|
class PannelloAmministrazioneUtils |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
private $container; |
15
|
|
|
private $apppaths; |
16
|
|
|
|
17
|
1 |
|
public function __construct($container) |
18
|
|
|
{ |
19
|
1 |
|
$this->container = $container; |
20
|
1 |
|
$this->apppaths = $container->get("pannelloamministrazione.projectpath"); |
|
|
|
|
21
|
1 |
|
} |
22
|
1 |
|
public function clearcache($env = "") |
|
|
|
|
23
|
|
|
{ |
24
|
1 |
|
if (!$env) { |
25
|
|
|
$env = $this->container->get('kernel')->getEnvironment(); |
26
|
|
|
} |
27
|
|
|
|
28
|
1 |
|
$phpPath = OsFunctions::getPHPExecutableFromPath(); |
29
|
|
|
|
30
|
1 |
|
$command = $phpPath . ' ' . $this->apppaths->getConsole() . ' cache:clear ' |
31
|
1 |
|
. '--env=' . $env; |
32
|
|
|
|
33
|
1 |
|
return self::runCommand($command); |
34
|
|
|
} |
35
|
1 |
|
public static function runCommand($command) |
36
|
|
|
{ |
37
|
|
|
/* @var $process \Symfony\Component\Process\Process */ |
38
|
1 |
|
$process = new Process($command); |
39
|
1 |
|
$process->setTimeout(60 * 60 * 24); |
40
|
1 |
|
$process->run(); |
41
|
|
|
|
42
|
1 |
|
if (!$process->isSuccessful()) { |
43
|
1 |
|
$return = array("errcode" => -1, |
|
|
|
|
44
|
1 |
|
"command" => $command, |
|
|
|
|
45
|
1 |
|
"message" => 'Errore nel comando ' . $command . "\n" . $process->getErrorOutput() . "\n" . $process->getOutput()); |
|
|
|
|
46
|
|
|
} else { |
47
|
1 |
|
$return = array("errcode" => 0, |
|
|
|
|
48
|
1 |
|
"command" => $command, |
|
|
|
|
49
|
1 |
|
"message" => $process->getOutput() |
|
|
|
|
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
1 |
|
return $return; |
54
|
|
|
} |
55
|
1 |
|
public function runSymfonyCommand($command, array $options = array()) |
56
|
|
|
{ |
57
|
1 |
|
$application = new Application($this->container->get('kernel')); |
58
|
1 |
|
$application->setAutoExit(false); |
59
|
|
|
|
60
|
1 |
|
$cmdoptions = array_merge(array('command' => $command), $options); |
61
|
|
|
|
62
|
1 |
|
$outputbuf = new BufferedOutput(); |
63
|
|
|
// return the output, don't use if you used NullOutput() |
64
|
1 |
|
$returncode = $application->run(new ArrayInput($cmdoptions), $outputbuf); |
65
|
1 |
|
$output = $outputbuf->fetch(); |
|
|
|
|
66
|
|
|
|
67
|
1 |
|
return array('errcode' => ($returncode == 0 ? 0 : 1), 'command' => $cmdoptions['command'], 'message' => $output); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.