|
34 | 34 | use Symfony\Component\Console\Input\InputOption;
|
35 | 35 | use Symfony\Component\Console\Output\OutputInterface;
|
36 | 36 |
|
37 |
| -class PluginFieldsFixDroppedFieldsCommand extends AbstractCommand |
| 37 | +class PluginFieldsCheckDatabaseCommand extends AbstractCommand |
38 | 38 | {
|
39 | 39 | protected function configure()
|
40 | 40 | {
|
41 |
| - $this->setName('plugin:fields:fixdroppedfields'); |
42 |
| - $this->setAliases(['fields:fixdroppedfields']); |
43 |
| - $this->setDescription( |
44 |
| - 'Remove fields that were wrongly kept in the database following an ' |
45 |
| - . 'issue introduced in 1.15.0 and fixed in 1.15.3.' |
| 41 | + $this->setName('plugin:fields:check_database'); |
| 42 | + $this->setDescription(__('Check database to detect inconsistencies.', 'fields')); |
| 43 | + $this->setHelp( |
| 44 | + __('This command will chec database to detect following inconsistencies:', 'fields') |
| 45 | + . "\n" |
| 46 | + . sprintf( |
| 47 | + __('- some deleted fields may still be present in database (bug introduced in %s and fixed in version %s)', 'fields'), |
| 48 | + '1.15.0', |
| 49 | + '1.15.3' |
| 50 | + ) |
46 | 51 | );
|
47 | 52 |
|
48 | 53 | $this->addOption(
|
49 |
| - "delete", |
| 54 | + 'fix', |
50 | 55 | null,
|
51 | 56 | InputOption::VALUE_NONE,
|
52 |
| - "Use this option to actually delete data" |
| 57 | + __('Use this option to actually fix database', 'fields') |
53 | 58 | );
|
54 | 59 | }
|
55 | 60 |
|
56 | 61 | protected function execute(InputInterface $input, OutputInterface $output)
|
57 | 62 | {
|
58 | 63 | // Read option
|
59 |
| - $delete = $input->getOption("delete"); |
| 64 | + $fix = $input->getOption('fix'); |
60 | 65 |
|
61 |
| - $fields = PluginFieldsMigration::fixDroppedFields(!$delete); |
| 66 | + $dead_fields = PluginFieldsMigration::checkDeadFields($fix); |
| 67 | + $dead_fields_count = count($dead_fields, COUNT_RECURSIVE) - count($dead_fields); |
62 | 68 |
|
63 | 69 | // No invalid fields found
|
64 |
| - if (!count($fields)) { |
| 70 | + if ($dead_fields_count === 0) { |
65 | 71 | $output->writeln(
|
66 |
| - __("Everything is in order - no action needed.", 'fields'), |
| 72 | + '<info>' . __('Everything is in order - no action needed.', 'fields') . '</info>', |
67 | 73 | );
|
68 | 74 | return Command::SUCCESS;
|
69 | 75 | }
|
70 | 76 |
|
71 | 77 | // Indicate which fields will have been or must be deleted
|
72 |
| - foreach ($fields as $field) { |
73 |
| - if ($delete) { |
74 |
| - $info = sprintf(__("-> %s was deleted.", 'fields'), $field); |
75 |
| - } else { |
76 |
| - $info = sprintf(__("-> %s must be deleted.", 'fields'), $field); |
77 |
| - } |
| 78 | + $error = $fix |
| 79 | + ? sprintf(__('Database was containing %s gone field(s).', 'fields'), $dead_fields_count) |
| 80 | + : sprintf(__('Database contains %s gone field(s).', 'fields'), $dead_fields_count); |
| 81 | + $output->writeln('<error>' . $error . '</error>', OutputInterface::VERBOSITY_QUIET); |
78 | 82 |
|
79 |
| - $output->writeln($info); |
| 83 | + foreach ($dead_fields as $table => $fields) { |
| 84 | + foreach ($fields as $field) { |
| 85 | + $info = $fix |
| 86 | + ? sprintf(__('-> "%s.%s" has been deleted.', 'fields'), $table, $field) |
| 87 | + : sprintf(__('-> "%s.%s" should be deleted.', 'fields'), $table, $field); |
| 88 | + $output->writeln($info); |
| 89 | + } |
80 | 90 | }
|
81 | 91 |
|
82 | 92 | // Show extra info in dry-run mode
|
83 |
| - if (!$delete) { |
84 |
| - $fields_found = sprintf( |
85 |
| - __("%s field(s) need to be deleted.", 'fields'), |
86 |
| - count($fields) |
87 |
| - ); |
88 |
| - $output->writeln($fields_found); |
89 |
| - |
| 93 | + if (!$fix) { |
90 | 94 | // Print command to do the actual deletion
|
91 | 95 | $next_command = sprintf(
|
92 |
| - __("Run \"%s\" to delete the found field(s).", 'fields'), |
93 |
| - "php bin/console plugin:fields:fixdroppedfields --delete" |
| 96 | + __('Run "%s" to delete the found field(s).', 'fields'), |
| 97 | + sprintf("php bin/console %s --fix", $this->getName()) |
| 98 | + ); |
| 99 | + $output->writeln( |
| 100 | + '<comment>' . $next_command . '</comment>', |
| 101 | + OutputInterface::VERBOSITY_QUIET |
94 | 102 | );
|
95 |
| - $output->writeln($next_command); |
96 | 103 | }
|
97 | 104 |
|
98 | 105 | return Command::SUCCESS;
|
|
0 commit comments