Skip to content

Commit

Permalink
Better error handling for update functions in wrong files (drush-ops#…
Browse files Browse the repository at this point in the history
…4471)

* Update UpdateDBCommands.php

* Fix coding standards spacings

* my_module.install not my_module.install.php
  • Loading branch information
jonathanjfshaw authored Jul 21, 2020
1 parent 458145d commit e4c9087
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Commands/core/UpdateDBCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ public static function updateDoOne($module, $number, array $dependency_map, Drus
}
} else {
$ret['#abort'] = ['success' => false];
Drush::logger()->warning(dt('Update function @function not found', ['@function' => $function]));
Drush::logger()->warning(dt('Update function @function not found in file @filename', [
'@function' => $function,
'@filename' => "$module.install",
]));
}

if (isset($context['sandbox']['#finished'])) {
Expand Down Expand Up @@ -300,7 +303,8 @@ public static function updateDoOnePostUpdate($function, DrushBatchContext $conte
}

list($module, $name) = explode('_post_update_', $function, 2);
module_load_include('php', $module, $module . '.post_update');
$filename = $module . '.post_update';
\Drupal::moduleHandler()->loadInclude($module, 'php', $filename);
if (function_exists($function)) {
if (empty($context['results'][$module][$name]['type'])) {
Drush::logger()->notice("Update started: $function");
Expand All @@ -327,8 +331,14 @@ public static function updateDoOnePostUpdate($function, DrushBatchContext $conte
'query' => t('%type: @message in %function (line %line of %file).', $variables),
];
}
} else {
$ret['#abort'] = ['success' => false];
Drush::logger()->warning(dt('Post update function @function not found in file @filename', [
'@function' => $function,
'@filename' => "$filename.php",
]));
}

if (isset($context['sandbox']['#finished'])) {
$context['finished'] = $context['sandbox']['#finished'];
unset($context['sandbox']['#finished']);
Expand Down

0 comments on commit e4c9087

Please sign in to comment.