1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Victoire\Bundle\WidgetMapBundle\Command; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManager; |
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
7
|
|
|
use Symfony\Component\Console\Helper\Table; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
use Victoire\Bundle\CoreBundle\Entity\View; |
11
|
|
|
use Victoire\Bundle\WidgetMapBundle\Entity\WidgetMap; |
12
|
|
|
|
13
|
|
|
class WidgetMapOverwriteValidationCommand extends ContainerAwareCommand |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* {@inheritdoc} |
17
|
|
|
*/ |
18
|
|
|
public function configure() |
19
|
|
|
{ |
20
|
|
|
parent::configure(); |
21
|
|
|
|
22
|
|
|
$this |
23
|
|
|
->setName('victoire:widget-map:validate-overwrite') |
24
|
|
|
->setDescription('Check for each View if there is conflicts between WidgetMaps.'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param InputInterface $input |
29
|
|
|
* @param OutputInterface $output |
30
|
|
|
* |
31
|
|
|
* @throws \Exception |
32
|
|
|
* |
33
|
|
|
* @return bool |
34
|
|
|
*/ |
35
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
36
|
|
|
{ |
37
|
|
|
$table = new Table($output); |
38
|
|
|
$table->setHeaders([ |
39
|
|
|
'Contextual View', |
40
|
|
|
'WidgetMaps in conflict', |
41
|
|
|
'Parent WidgetMap', |
42
|
|
|
'Slot', |
43
|
|
|
'Position', |
44
|
|
|
]); |
45
|
|
|
|
46
|
|
|
/** @var EntityManager $entityManager */ |
47
|
|
|
$entityManager = $this->getContainer()->get('doctrine.orm.entity_manager'); |
48
|
|
|
$contextualViewWarmer = $this->getContainer()->get('victoire_widget_map.contextual_view_warmer'); |
49
|
|
|
|
50
|
|
|
$conflictNb = 0; |
51
|
|
|
|
52
|
|
|
$views = $entityManager->getRepository('Victoire\Bundle\CoreBundle\Entity\View')->findAll(); |
53
|
|
|
foreach ($views as $view) { |
54
|
|
|
$widgetMaps = $contextualViewWarmer->warm($view); |
55
|
|
|
|
56
|
|
|
foreach ($widgetMaps as $widgetMap) { |
57
|
|
|
$positions = [WidgetMap::POSITION_BEFORE, WidgetMap::POSITION_AFTER]; |
58
|
|
|
$children = []; |
59
|
|
|
foreach ($positions as $position) { |
60
|
|
|
$children[$position] = null; |
61
|
|
|
$matchingChildren = []; |
62
|
|
|
|
63
|
|
|
foreach ($widgetMap->getContextualChildren($position) as $_child) { |
64
|
|
|
if (null === $_child->getSubstituteForView($view)) { |
65
|
|
|
$children[$position] = $_child; |
66
|
|
|
$matchingChildren[] = $_child->getId(); |
67
|
|
|
$parent = $_child->getParent()->getId(); |
68
|
|
|
$slot = $_child->getSlot(); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if (!$children[$position] && $widgetMap->getReplaced()) { |
73
|
|
|
foreach ($widgetMap->getReplaced()->getContextualChildren($position) as $_child) { |
74
|
|
|
if (null === $_child->getSubstituteForView($view)) { |
75
|
|
|
$matchingChildren[] = $_child->getId(); |
76
|
|
|
$parent = $_child->getParent()->getId(); |
77
|
|
|
$slot = $_child->getSlot(); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
if (count($matchingChildren) > 1) { |
83
|
|
|
$conflictNb++; |
84
|
|
|
$table->addRow([ |
85
|
|
|
$view->getId(), |
86
|
|
|
implode(', ', $matchingChildren), |
87
|
|
|
$parent, |
|
|
|
|
88
|
|
|
$slot, |
|
|
|
|
89
|
|
|
$position, |
90
|
|
|
]); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
if ($conflictNb > 0) { |
97
|
|
|
$output->writeln(sprintf('<error>%s WidgetMaps conflicts found.</error>', $conflictNb)); |
98
|
|
|
$output->writeln('<error>At least one of those WidgetMaps must have a replace_id with action "overwrite".</error>'); |
99
|
|
|
$table->render(); |
100
|
|
|
} else { |
101
|
|
|
$output->writeln('<info>No conflict found.</info>'); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|