1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Starkerxp\StructureBundle\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
8
|
|
|
use Symfony\Component\Filesystem\LockHandler; |
9
|
|
|
|
10
|
|
|
abstract class LockCommand extends ContainerAwareCommand |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var OutputInterface |
14
|
|
|
*/ |
15
|
|
|
protected $output; |
16
|
|
|
/** |
17
|
|
|
* @var InputInterface |
18
|
|
|
*/ |
19
|
|
|
protected $input; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param InputInterface $input |
23
|
|
|
* @param OutputInterface $output |
24
|
|
|
* |
25
|
|
|
* @return bool |
26
|
|
|
*/ |
27
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
28
|
|
|
{ |
29
|
|
|
$this->input = $input; |
30
|
|
|
$this->output = $output; |
31
|
|
|
$lockHandler = new LockHandler($this->getEnvironment().'_'.$this->lockerName()); |
32
|
|
|
if (!$lockHandler->lock()) { |
33
|
|
|
$this->output->writeln('<error>Command already starting !</error>'); |
34
|
|
|
|
35
|
|
|
return false; |
36
|
|
|
} |
37
|
|
|
$this->treatment(); |
38
|
|
|
|
39
|
|
|
return true; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
|
|
public function lockerName() |
46
|
|
|
{ |
47
|
|
|
return $this->getName(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
abstract public function treatment(); |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param $entityFqdn |
54
|
|
|
* @return \Doctrine\ORM\EntityRepository |
55
|
|
|
*/ |
56
|
|
|
protected function getRepository($entityFqdn) |
57
|
|
|
{ |
58
|
|
|
return $this->getEntityManager()->getRepository($entityFqdn); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Récupère l'entity manager. |
63
|
|
|
* |
64
|
|
|
* @return \Doctrine\ORM\EntityManager |
65
|
|
|
*/ |
66
|
|
|
protected function getEntityManager() |
67
|
|
|
{ |
68
|
|
|
return $this->getContainer()->get("doctrine")->getManager(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return \Doctrine\DBAL\Connection |
73
|
|
|
*/ |
74
|
|
|
protected function getConnection() |
75
|
|
|
{ |
76
|
|
|
return $this->getEntityManager()->getConnection(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
protected function getEnvironment(){ |
83
|
|
|
return $this->getContainer()->get("kernel")->getEnvironment(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
} |
|
|
|
|
87
|
|
|
|
This check marks files that end in a newline character, i.e. an empy line.