1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the SexyField package. |
5
|
|
|
* |
6
|
|
|
* (c) Dion Snoeijen <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare (strict_types = 1); |
13
|
|
|
|
14
|
|
|
namespace Tardigrades\Command; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper; |
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
19
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
20
|
|
|
use Symfony\Component\Console\Question\Question; |
21
|
|
|
use Tardigrades\Entity\FieldType; |
22
|
|
|
use Tardigrades\SectionField\SectionFieldInterface\FieldTypeManager; |
|
|
|
|
23
|
|
|
use Tardigrades\SectionField\Service\FieldTypeManagerInterface; |
24
|
|
|
use Tardigrades\SectionField\Service\FieldTypeNotFoundException; |
25
|
|
|
use Tardigrades\SectionField\ValueObject\Id; |
26
|
|
|
|
27
|
|
|
class DeleteFieldTypeCommand extends FieldTypeCommand |
28
|
|
|
{ |
29
|
|
|
/** @var QuestionHelper */ |
30
|
|
|
private $questionHelper; |
31
|
|
|
|
32
|
|
|
/** @var FieldTypeManagerInterface */ |
33
|
|
|
private $fieldTypeManager; |
34
|
|
|
|
35
|
|
|
public function __construct( |
36
|
|
|
FieldTypeManagerInterface $fieldTypeManager |
37
|
|
|
) { |
38
|
|
|
$this->fieldTypeManager = $fieldTypeManager; |
39
|
|
|
|
40
|
|
|
parent::__construct('sf:delete-field-type'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function configure(): void |
44
|
|
|
{ |
45
|
|
|
$this |
46
|
|
|
->setDescription('Delete field type.') |
47
|
|
|
->setHelp('Delete field type.') |
48
|
|
|
; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): void |
52
|
|
|
{ |
53
|
|
|
try { |
54
|
|
|
$this->questionHelper = $this->getHelper('question'); |
55
|
|
|
|
56
|
|
|
$this->showInstalledFieldTypes($input, $output); |
57
|
|
|
} catch (FieldTypeNotFoundException $exception) { |
58
|
|
|
$output->writeln("Field type not found"); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
private function showInstalledFieldTypes(InputInterface $input, OutputInterface $output): void |
63
|
|
|
{ |
64
|
|
|
$fieldTypes = $this->fieldTypeManager->readAll(); |
65
|
|
|
|
66
|
|
|
$this->renderTable($output, $fieldTypes, 'Installed field types'); |
67
|
|
|
$this->deleteWhatRecord($input, $output); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
private function deleteWhatRecord(InputInterface $input, OutputInterface $output): void |
71
|
|
|
{ |
72
|
|
|
$fieldType = $this->getFieldType($input, $output); |
73
|
|
|
|
74
|
|
|
if ($fieldType->hasFields()) { |
75
|
|
|
$fields = PHP_EOL; |
76
|
|
|
foreach ($fieldType->getFields() as $field) { |
77
|
|
|
$fields .= ' - ' . $field->getHandle() . ':' . PHP_EOL; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$output->writeln( |
81
|
|
|
'<info>This FieldType has fields that use this type, delete them first. ' . |
82
|
|
|
$fields . |
83
|
|
|
'</info>' |
84
|
|
|
); |
85
|
|
|
return; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$output->writeln('<info>Record with id #' . $fieldType->getId() . ' will be deleted</info>'); |
89
|
|
|
|
90
|
|
|
$sure = new ConfirmationQuestion('<comment>Are you sure?</comment> (y/n) ', false); |
91
|
|
|
|
92
|
|
|
if (!$this->questionHelper->ask($input, $output, $sure)) { |
93
|
|
|
$output->writeln('<comment>Cancelled, nothing deleted.</comment>'); |
94
|
|
|
return; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$this->fieldTypeManager->delete($fieldType); |
98
|
|
|
|
99
|
|
|
$output->writeln('<info>Removed!</info>'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
private function getFieldType(InputInterface $input, OutputInterface $output): FieldType |
103
|
|
|
{ |
104
|
|
|
$question = new Question('<question>What record do you want to delete?</question> (#id): '); |
105
|
|
|
$question->setValidator(function ($id) { |
106
|
|
|
try { |
107
|
|
|
return $this->fieldTypeManager->read(Id::fromInt((int) $id)); |
108
|
|
|
} catch (FieldTypeNotFoundException $exception) { |
109
|
|
|
return null; |
110
|
|
|
} |
111
|
|
|
}); |
112
|
|
|
|
113
|
|
|
$fieldType = $this->questionHelper->ask($input, $output, $question); |
114
|
|
|
if (!$fieldType) { |
115
|
|
|
throw new FieldTypeNotFoundException(); |
116
|
|
|
} |
117
|
|
|
return $fieldType; |
|
|
|
|
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
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