diff --git a/includes/batch.inc b/includes/batch.inc index 5cff354ea8..51df0df02e 100644 --- a/includes/batch.inc +++ b/includes/batch.inc @@ -1,4 +1,5 @@ notice(strip_tags($value)); - } - elseif ($name == 'error_message') { - Drush::logger()->error(strip_tags($value)); - } - parent::offsetSet($name, $value); - } -} - /** * Process a Drupal batch by spawning multiple Drush processes. * @@ -111,7 +90,7 @@ function drush_batch_command($id) { function _drush_backend_batch_process($command = 'batch-process', $args = [], $options = []) { $result = NULL; - $batch =& batch_get(); + $batch = &batch_get(); if (isset($batch)) { $process_info = [ @@ -176,7 +155,7 @@ function _drush_backend_batch_process($command = 'batch-process', $args = [], $o * A results array. */ function _drush_batch_command($id) { - $batch =& batch_get(); + $batch = &batch_get(); $data = Database::getConnection()->select('batch', 'b') ->fields('b', ['batch']) @@ -215,8 +194,8 @@ function _drush_batch_command($id) { * reached. */ function _drush_batch_worker() { - $batch =& batch_get(); - $current_set =& _batch_current_set(); + $batch = &batch_get(); + $current_set = &_batch_current_set(); $set_changed = TRUE; if (empty($current_set['start'])) { @@ -237,7 +216,7 @@ function _drush_batch_worker() { $finished = 1; if ($item = $queue->claimItem()) { - list($function, $args) = $item->data; + [$callback, $args] = $item->data; // Build the 'context' array and execute the function call. $batch_context = [ @@ -246,20 +225,17 @@ function _drush_batch_worker() { 'finished' => &$finished, 'message' => &$task_message, ]; - // Magic wrap to catch changes to 'message' key. - $batch_context = new DrushBatchContext($batch_context); // Tolerate recoverable errors. // See https://github.com/drush-ops/drush/issues/1930 $halt_on_error = \Drush\Drush::config()->get('runtime.php.halt-on-error', TRUE); \Drush\Drush::config()->set('runtime.php.halt-on-error', FALSE); - $message = call_user_func_array($function, array_merge($args, [&$batch_context])); - if (!empty($message)) { - Drush::logger()->notice($message); + call_user_func_array($callback, array_merge($args, [&$batch_context])); + if (!empty($task_message)) { + Drush::logger()->notice(strip_tags($task_message)); } \Drush\Drush::config()->set('runtime.php.halt-on-error', $halt_on_error); - $finished = $batch_context['finished']; if ($finished >= 1) { // Make sure this step is not counted twice when computing $current. $finished = 0; @@ -371,8 +347,8 @@ function _drush_batch_finished() { */ function _drush_batch_shutdown() { if ($batch = batch_get()) { - /** @var \Drupal\Core\Batch\BatchStorage $batch_storage */ - $batch_storage = \Drupal::service('batch.storage'); - $batch_storage->update($batch); + /** @var \Drupal\Core\Batch\BatchStorage $batch_storage */ + $batch_storage = \Drupal::service('batch.storage'); + $batch_storage->update($batch); } } diff --git a/src/Commands/core/UpdateDBCommands.php b/src/Commands/core/UpdateDBCommands.php index a7225862aa..35f167c930 100644 --- a/src/Commands/core/UpdateDBCommands.php +++ b/src/Commands/core/UpdateDBCommands.php @@ -8,7 +8,6 @@ use Drush\Log\SuccessInterface; use Drush\Drupal\DrupalUtil; use Drush\Attributes as CLI; -use DrushBatchContext; use Consolidation\OutputFormatters\StructuredData\RowsOfFields; use Consolidation\OutputFormatters\StructuredData\UnstructuredListData; use Consolidation\SiteAlias\SiteAliasManagerAwareInterface; @@ -155,10 +154,10 @@ public function process(string $batch_id, $options = ['format' => 'json']): Unst * The update number to run. * @param array $dependency_map * The update dependency map. - * @param DrushBatchContext $context + * @param array $context * The batch context object. */ - public static function updateDoOne(string $module, int $number, array $dependency_map, DrushBatchContext $context): void + public static function updateDoOne(string $module, int $number, array $dependency_map, array $context): void { $function = $module . '_update_' . $number; @@ -233,9 +232,7 @@ public static function updateDoOne(string $module, int $number, array $dependenc if (!empty($ret['#abort'])) { // Record this function in the list of updates that were aborted. $context['results']['#abort'][] = $function; - // Setting this value will output an error message. - // @see \DrushBatchContext::offsetSet() - $context['error_message'] = "Update failed: $function"; + Drush::logger()->error("Update failed: $function"); } // Record the schema update if it was completed successfully. @@ -246,8 +243,6 @@ public static function updateDoOne(string $module, int $number, array $dependenc } else { drupal_set_installed_schema_version($module, $number); } - // Setting this value will output a success message. - // @see \DrushBatchContext::offsetSet() $context['message'] = "Update completed: $function"; } } @@ -259,7 +254,7 @@ public static function updateDoOne(string $module, int $number, array $dependenc * The post-update function to execute. * The batch context object. */ - public static function updateDoOnePostUpdate(string $function, DrushBatchContext $context): void + public static function updateDoOnePostUpdate(string $function, array $context): void { $ret = []; @@ -335,12 +330,8 @@ public static function updateDoOnePostUpdate(string $function, DrushBatchContext if (!empty($ret['#abort'])) { // Record this function in the list of updates that were aborted. $context['results']['#abort'][] = $function; - // Setting this value will output an error message. - // @see \DrushBatchContext::offsetSet() - $context['error_message'] = "Update failed: $function"; + Drush::logger()->error("Update failed: $function"); } elseif ($context['finished'] == 1 && empty($ret['#abort'])) { - // Setting this value will output a success message. - // @see \DrushBatchContext::offsetSet() $context['message'] = "Update completed: $function"; } } diff --git a/src/Drupal/Commands/core/DeployHookCommands.php b/src/Drupal/Commands/core/DeployHookCommands.php index 80abdea2aa..0f8d913000 100644 --- a/src/Drupal/Commands/core/DeployHookCommands.php +++ b/src/Drupal/Commands/core/DeployHookCommands.php @@ -15,7 +15,6 @@ use Drupal\Core\Utility\Error; use Drush\Commands\DrushCommands; use Drush\Drush; -use DrushBatchContext; use Drush\Exceptions\UserAbortException; use Psr\Log\LogLevel; @@ -154,7 +153,7 @@ public function process(string $batch_id, $options = ['format' => 'json']): Unst /** * Batch command that executes a single deploy hook. */ - public static function updateDoOneDeployHook(string $function, DrushBatchContext $context): void + public static function updateDoOneDeployHook(string $function, array $context): void { $ret = []; @@ -232,12 +231,8 @@ public static function updateDoOneDeployHook(string $function, DrushBatchContext if (!empty($ret['#abort'])) { // Record this function in the list of updates that were aborted. $context['results']['#abort'][] = $function; - // Setting this value will output an error message. - // @see \DrushBatchContext::offsetSet() - $context['error_message'] = "Deploy hook failed: $function"; + Drush::logger()->error("Deploy hook failed: $function"); } elseif ($context['finished'] == 1 && empty($ret['#abort'])) { - // Setting this value will output a success message. - // @see \DrushBatchContext::offsetSet() $context['message'] = "Performed: $function"; } }