Skip to content

Commit

Permalink
Merge pull request #1552 from mnico/1542-drupalstyle-update
Browse files Browse the repository at this point in the history
[update] Implement DrupalStyle
  • Loading branch information
jmolivas committed Dec 22, 2015
2 parents 7801da1 + 79451c0 commit 666068d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 85 deletions.
86 changes: 34 additions & 52 deletions src/Command/Update/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Helper\Table;
use Drupal\Console\Command\ContainerAwareCommand;
use Drupal\Console\Style\DrupalStyle;

class DebugCommand extends ContainerAwareCommand
{
Expand All @@ -23,8 +23,7 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
$table = new Table($output);
$table->setStyle('compact');
$io = new DrupalStyle($input, $output);

$this->getDrupalHelper()->loadLegacyFile('/core/includes/update.inc');
$this->getDrupalHelper()->loadLegacyFile('/core/includes/install.inc');
Expand All @@ -37,75 +36,58 @@ protected function execute(InputInterface $input, OutputInterface $output)
$severity = drupal_requirements_severity($requirements);

if ($severity == REQUIREMENT_ERROR || ($severity == REQUIREMENT_WARNING)) {
$output->writeln(
'[-] <info>' .
$this->trans('commands.update.debug.messages.requirements-error')
. '</info>'
);

$table->setHeaders(
[
$this->trans('commands.update.debug.messages.severity'),
$this->trans('commands.update.debug.messages.title'),
$this->trans('commands.update.debug.messages.value'),
$this->trans('commands.update.debug.messages.description')
]
);
$io->info($this->trans('commands.update.debug.messages.requirements-error'));

$tableHeader = [
$this->trans('commands.update.debug.messages.severity'),
$this->trans('commands.update.debug.messages.title'),
$this->trans('commands.update.debug.messages.value'),
$this->trans('commands.update.debug.messages.description'),
];

$tableRows = [];
foreach ($requirements as $requirement) {
if (isset($requirement['minimum schema']) & in_array($requirement['minimum schema'], array(REQUIREMENT_ERROR, REQUIREMENT_WARNING))) {
$table->addRow(
[
$requirement['severity'],
$requirement['title'],
$requirement['value'],
$requirement['description']
]
);
$tableRows[] = [
$requirement['severity'],
$requirement['title'],
$requirement['value'],
$requirement['description'],
];
}
}

$table->render();
$io->table($tableHeader, $tableRows, 'compact');

return;
}

if (empty($updates)) {
$output->writeln(
'[-] <info>' .
$this->trans('commands.update.debug.messages.no-updates')
. '</info>'
);
$io->info($this->trans('commands.update.debug.messages.no-updates'));

return;
}

$table->setHeaders(
[
$this->trans('commands.update.debug.messages.module'),
$this->trans('commands.update.debug.messages.update-n'),
$this->trans('commands.update.debug.messages.description')
]
);

$output->writeln(
'<info>'.
$this->trans('commands.update.debug.messages.module-list')
.'</info>'
);
$tableHeader = [
$this->trans('commands.update.debug.messages.module'),
$this->trans('commands.update.debug.messages.update-n'),
$this->trans('commands.update.debug.messages.description')
];

$io->info($this->trans('commands.update.debug.messages.module-list'));

$tableRows = [];
foreach ($updates as $module => $module_updates) {
foreach ($module_updates['pending'] as $update_n => $update) {
list(, $description) = explode($update_n . " - ", $update);
$table->addRow(
[
$module,
$update_n,
trim($description)
]
);
$tableRows[] = [
$module,
$update_n,
trim($description),
];
}
}

$table->render();
$io->table($tableHeader, $tableRows, 'compact');
}
}
43 changes: 10 additions & 33 deletions src/Command/Update/ExecuteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Console\Command\ContainerAwareCommand;
use Drupal\Console\Style\DrupalStyle;

class ExecuteCommand extends ContainerAwareCommand
{
Expand All @@ -25,6 +26,8 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);

$this->getDrupalHelper()->loadLegacyFile('/core/includes/install.inc');
$this->getDrupalHelper()->loadLegacyFile('/core/includes/update.inc');

Expand All @@ -39,39 +42,28 @@ protected function execute(InputInterface $input, OutputInterface $output)
$updates = update_get_update_list();
if ($module != 'all') {
if (!isset($updates[$module])) {
$output->writeln(
'[-] <error>' .
sprintf(
$io->error(sprintf(
$this->trans('commands.update.execute.messages.no-module-updates'),
$module
)
. '</error>'
);
return;
} else {
// filter to execute only a specific module updates
$updates = [$module => $updates[$module]];

if ($update_n && !isset($updates[$module]['pending'][$update_n])) {
$output->writeln(
'[-] <info>' .
sprintf(
$io->info(sprintf(
$this->trans('commands.update.execute.messages.module-update-function-not-found'),
$module,
$update_n
)
. '</info>'
);
}
}
}


$output->writeln(
'[-] <info>' .
$this->trans('commands.site.maintenance.description')
. '</info>'
);
$io->info($this->trans('commands.site.maintenance.description'));
\Drupal::state()->set('system.maintenance_mode', true);

foreach ($updates as $module_name => $module_updates) {
Expand All @@ -82,32 +74,21 @@ protected function execute(InputInterface $input, OutputInterface $output)

//Executing all pending updates
if ($update_n > $module_updates['start']) {
$output->writeln(
'[-] <info>' .
$this->trans('commands.update.execute.messages.executing-required-previous-updates')
. '</info>'
);
$io->info($this->trans('commands.update.execute.messages.executing-required-previous-updates'));
}
for ($update_index=$module_updates['start']; $update_index<=$update_number; $update_index++) {
$output->writeln(
'[-] <info>' .
sprintf(
$io->info(sprintf(
$this->trans('commands.update.execute.messages.executing-update'),
$update_index,
$module_name
)
. '</info>'
);

try {
$module_handler->invoke($module_name, 'update_' . $update_index);
} catch (\Exception $e) {
watchdog_exception('update', $e);
$output->writeln(
'<error>' .
$e->getMessage() .
'</error>'
);
$io->error($e->getMessage());
}

//Update module schema version
Expand All @@ -117,11 +98,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

\Drupal::state()->set('system.maintenance_mode', false);
$output->writeln(
'[-] <info>' .
$this->trans('commands.site.maintenance.messages.maintenance-off')
. '</info>'
);
$io->info($this->trans('commands.site.maintenance.messages.maintenance-off'));

$this->getChain()->addCommand('cache:rebuild', ['cache' => 'all']);
}
Expand Down

0 comments on commit 666068d

Please sign in to comment.