Skip to content
Permalink
Browse files

4020 fix update execute command (#4027)

* [update:execute] Fixed the post update

* [debug:update] Create a trait to show tables

* [update:execute] Ask first to execute an update
  • Loading branch information...
harold20 authored and enzolutions committed May 10, 2019
1 parent 241d793 commit 404a02616aa926f1a8a0da127bb4174bbc4b4728
Showing with 125 additions and 68 deletions.
  1. +7 −53 src/Command/Debug/UpdateCommand.php
  2. +73 −0 src/Command/Shared/UpdateTrait.php
  3. +45 −15 src/Command/Update/ExecuteCommand.php
@@ -7,6 +7,7 @@
namespace Drupal\Console\Command\Debug;
use Drupal\Console\Command\Shared\UpdateTrait;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Console\Core\Command\Command;
@@ -15,6 +16,8 @@
class UpdateCommand extends Command
{
use UpdateTrait;
/**
* @var Site
*/
@@ -65,16 +68,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
$requirements = update_check_requirements();
$severity = drupal_requirements_severity($requirements);
$updates = update_get_update_list();
$postUpdates = $this->postUpdateRegistry->getPendingUpdateInformation();
$this->getIo()->newLine();
if ($severity == REQUIREMENT_ERROR || ($severity == REQUIREMENT_WARNING)) {
$this->populateRequirements($requirements);
} elseif (empty($updates)) {
} elseif (empty($updates) && empty($postUpdates)) {
$this->getIo()->info($this->trans('commands.debug.update.messages.no-updates'));
} else {
$this->populateUpdate($updates);
$this->populatePostUpdate();
$this->showUpdateTable($updates, $this->trans('commands.debug.update.messages.module-list'));
$this->showPostUpdateTable($postUpdates, $this->trans('commands.debug.update.messages.module-list-post-update'));
}
}
@@ -110,54 +114,4 @@ private function populateRequirements($requirements)
$this->getIo()->table($tableHeader, $tableRows);
}
/**
* @param $updates
*/
private function populateUpdate($updates)
{
$this->getIo()->info($this->trans('commands.debug.update.messages.module-list'));
$tableHeader = [
$this->trans('commands.debug.update.messages.module'),
$this->trans('commands.debug.update.messages.update-n'),
$this->trans('commands.debug.update.messages.description')
];
$tableRows = [];
foreach ($updates as $module => $module_updates) {
foreach ($module_updates['pending'] as $update_n => $update) {
list(, $description) = explode($update_n . " - ", $update);
$tableRows[] = [
$module,
$update_n,
trim($description),
];
}
}
$this->getIo()->table($tableHeader, $tableRows);
}
private function populatePostUpdate()
{
$this->getIo()->info(
$this->trans('commands.debug.update.messages.module-list-post-update')
);
$tableHeader = [
$this->trans('commands.debug.update.messages.module'),
$this->trans('commands.debug.update.messages.post-update'),
$this->trans('commands.debug.update.messages.description')
];
$postUpdates = $this->postUpdateRegistry->getPendingUpdateInformation();
$tableRows = [];
foreach ($postUpdates as $module => $module_updates) {
foreach ($module_updates['pending'] as $postUpdateFunction => $message) {
$tableRows[] = [
$module,
$postUpdateFunction,
$message,
];
}
}
$this->getIo()->table($tableHeader, $tableRows);
}
}
@@ -0,0 +1,73 @@
<?php
/**
* @file
* Contains Drupal\Console\Command\Shared\ThemeRegionTrait.
*/
namespace Drupal\Console\Command\Shared;
trait UpdateTrait
{
/**
* @param $updates
* @param $messageKey
* @return mixed
*/
public function showUpdateTable($updates, $messageKey)
{
if(!$updates) {
return 1;
}
$this->getIo()->info($messageKey);
$tableHeader = [
$this->trans('commands.debug.update.messages.module'),
$this->trans('commands.debug.update.messages.update-n'),
$this->trans('commands.debug.update.messages.description')
];
$tableRows = [];
foreach ($updates as $module => $module_updates) {
foreach ($module_updates['pending'] as $update_n => $update) {
list(, $description) = explode($update_n . " - ", $update);
$tableRows[] = [
$module,
$update_n,
trim($description),
];
}
}
$this->getIo()->table($tableHeader, $tableRows);
}
/**
* @param $postUpdates
* @param $messageKey
* @return mixed
*/
public function showPostUpdateTable($postUpdates, $messageKey)
{
if(!$postUpdates) {
return 1;
}
$this->getIo()->info($messageKey);
$tableHeader = [
$this->trans('commands.debug.update.messages.module'),
$this->trans('commands.debug.update.messages.post-update'),
$this->trans('commands.debug.update.messages.description')
];
$tableRows = [];
foreach ($postUpdates as $module => $module_updates) {
foreach ($module_updates['pending'] as $postUpdateFunction => $message) {
$tableRows[] = [
$module,
$postUpdateFunction,
$message,
];
}
}
$this->getIo()->table($tableHeader, $tableRows);
}
}
@@ -7,6 +7,7 @@
namespace Drupal\Console\Command\Update;
use Drupal\Console\Command\Shared\UpdateTrait;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
@@ -20,6 +21,8 @@
class ExecuteCommand extends Command
{
use UpdateTrait;
/**
* @var Site
*/
@@ -129,21 +132,22 @@ protected function execute(InputInterface $input, OutputInterface $output)
$start = $this->getUpdates($this->module!=='all'?$this->module:null);
$updates = update_resolve_dependencies($start);
$dependencyMap = [];
$allowUpdate = false;
foreach ($updates as $function => $update) {
$dependencyMap[$function] = !empty($update['reverse_paths']) ? array_keys($update['reverse_paths']) : [];
}
if (!$this->checkUpdates($start, $updates)) {
if ($this->module === 'all') {
$this->getIo()->warning(
$this->getIo()->info(
sprintf(
$this->trans(
'commands.update.execute.messages.no-pending-updates'
)
)
);
} else {
$this->getIo()->warning(
$this->getIo()->info(
sprintf(
$this->trans(
'commands.update.execute.messages.no-module-updates'
@@ -152,27 +156,34 @@ protected function execute(InputInterface $input, OutputInterface $output)
)
);
}
$this->getIo()->info('');
} else {
$this->showUpdateTable($updates, $this->trans('commands.update.execute.messages.pending-updates'));
$allowUpdate = $this->getIo()->confirm(
$this->trans('commands.update.execute.questions.update'),
true
);
try {
$this->runUpdates(
$updates
);
if($allowUpdate) {
$this->runUpdates(
$updates
);
}
} catch (\Exception $e) {
watchdog_exception('update', $e);
$this->getIo()->error($e->getMessage());
return 1;
}
}
// Post Updates are only safe to run after all schemas have been updated.
if (!$this->getUpdates()) {
$this->runPostUpdates($postUpdates);
$this->chainQueue->addCommand('update:entities');
}
$postUpdates = $this->runPostUpdates();
$this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
if($postUpdates || $allowUpdate) {
$this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
}
return 0;
}
@@ -259,13 +270,29 @@ private function runUpdates(
*/
private function runPostUpdates()
{
$postUpdates = $this->postUpdateRegistry->getPendingUpdateInformation();
if(!$postUpdates = $this->postUpdateRegistry->getPendingUpdateInformation()) {
$this->getIo()->info(
$this->trans('commands.update.execute.messages.no-pending-post-updates')
);
return 0;
}
$this->showPostUpdateTable($postUpdates, $this->trans('commands.update.execute.messages.pending-post-updates'));
$allowPostUpdate = $this->getIo()->confirm(
$this->trans('commands.update.execute.questions.post-update'),
true
);
if(!$allowPostUpdate) {
return 0;
}
foreach ($postUpdates as $module => $updates) {
foreach ($updates['pending'] as $updateName => $update) {
$this->getIo()->info(
sprintf(
$this->trans('commands.update.execute.messages.executing-update'),
$this->trans('commands.update.execute.messages.executing-post-update'),
$updateName,
$module
)
@@ -285,6 +312,8 @@ private function runPostUpdates()
}
}
$this->chainQueue->addCommand('update:entities');
return true;
}
@@ -309,6 +338,7 @@ protected function getUpdateList()
{
$start = [];
$updates = update_get_update_list();
foreach ($updates as $module => $update) {
$start[$module] = $update['start'];
}

0 comments on commit 404a026

Please sign in to comment.
You can’t perform that action at this time.