|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Rik van der Kemp <[email protected]> |
|
4
|
|
|
* @copyright Zicht Online <http://www.zicht.nl> |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace Zicht\Bundle\FrameworkExtraBundle\Command; |
|
8
|
|
|
|
|
9
|
|
|
use Gedmo\Tree\Entity\Repository\NestedTreeRepository; |
|
|
|
|
|
|
10
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
14
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Checks if a NestedTree set is verified (correct), if not repairs the tree |
|
18
|
|
|
* using the NestedSet methods. |
|
19
|
|
|
* |
|
20
|
|
|
* @package Zicht\Bundle\FrameworkExtraBundle\Command |
|
21
|
|
|
*/ |
|
22
|
|
|
class RepairNestedTreeCommand extends ContainerAwareCommand |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* This is const because it's referred by the exception thrown when a validation error occurs |
|
26
|
|
|
*/ |
|
27
|
|
|
const COMMAND_NAME = 'zicht:repair:nested-tree'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @{inheritDoc} |
|
31
|
|
|
*/ |
|
32
|
|
|
protected function configure() |
|
33
|
|
|
{ |
|
34
|
|
|
$this |
|
35
|
|
|
->setName(self::COMMAND_NAME) |
|
36
|
|
|
->setDescription('Repair a NestedTreeSet') |
|
37
|
|
|
->addOption('dry-run', 'd', InputOption::VALUE_NONE, 'Do a dry run, i.e. only report the problems without doing any changes') |
|
38
|
|
|
->addArgument('entity', InputArgument::REQUIRED, 'The entity to be repaired, must be of nested tree set. E.g. ZichtMenuBundle:MenuItem') |
|
39
|
|
|
->setHelp( |
|
40
|
|
|
'This command will try to repair broken nested set.' . PHP_EOL . |
|
41
|
|
|
'Pass --dry-run to see if the nested set is broken (use --verbose to see which items are broken)' . PHP_EOL |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @{inheritDoc} |
|
47
|
|
|
*/ |
|
48
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
49
|
|
|
{ |
|
50
|
|
|
$doctrine = $this->getContainer()->get('doctrine'); |
|
51
|
|
|
$entity = $input->getArgument('entity'); |
|
52
|
|
|
$formatter = $this->getHelperSet()->get('formatter'); |
|
53
|
|
|
$repository = $doctrine->getRepository($entity); |
|
54
|
|
|
|
|
55
|
|
|
if ($repository instanceof NestedTreeRepository) { |
|
56
|
|
|
if (true !== ($issues = $repository->verify())) { |
|
57
|
|
|
if ($output->getVerbosity() > 0) { |
|
58
|
|
|
$output->writeln("Errors found in tree:"); |
|
59
|
|
|
$output->writeln($formatter->formatBlock($issues, 'comment', true)); |
|
|
|
|
|
|
60
|
|
|
} else { |
|
61
|
|
|
$output->writeln("Errors found in tree"); |
|
62
|
|
|
} |
|
63
|
|
|
if ($input->getOption('dry-run')) { |
|
64
|
|
|
$output->writeln("Dry run, so no changes are made"); |
|
65
|
|
|
} else { |
|
66
|
|
|
$output->writeln("Recovering"); |
|
67
|
|
|
$repository->recover(); |
|
68
|
|
|
$doctrine->getManager()->flush(); |
|
69
|
|
|
} |
|
70
|
|
|
} else { |
|
71
|
|
|
$output->writeln("No issues found"); |
|
72
|
|
|
} |
|
73
|
|
|
} else { |
|
74
|
|
|
$output->writeln("Given entity is not of instance NestedTreeRepository"); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths