Skip to content
Snippets Groups Projects

fix the issue

1 file
+ 11
6
Compare changes
  • Side-by-side
  • Inline
+ 11
6
@@ -435,7 +435,8 @@ class BatchOperations implements ContainerInjectionInterface {
return;
}
$this->checkAndSetCanRun($this->executor);
$sandbox['multi_run_state_key'] = "cbo_{$script_name}";
// Initialize multi_run_state_key if not set
$sandbox['multi_run_state_key'] = isset($sandbox['multi_run_state_key']) ? $sandbox['multi_run_state_key'] : "cbo_{$script_name}";
    • This is the first run of sandbox init. There should be no other instance before this, because prior to this, $sandbox does not exist. This check is not necessary.

Please register or sign in to reply
// This seems like the first run, see if there is already a state saved
// from a previous attempt.
$last_run_completed = $this->state->get($sandbox['multi_run_state_key']);
@@ -535,16 +536,18 @@ class BatchOperations implements ContainerInjectionInterface {
// Determine when to stop batching.
$sandbox['current'] = ($sandbox['total'] - count($sandbox['items_to_process']));
// Save the 'current' value to state, to record a successful processOne().
$this->state->set($sandbox['multi_run_state_key'], $sandbox['current']);
if (isset($sandbox['multi_run_state_key'])) {
    • This actually needs to get set, no matter what. We need to make sure that $sandbox['multi_run_state_key'] exists before it gets to this point.

Please register or sign in to reply
$this->state->set($sandbox['multi_run_state_key'], $sandbox['current']);
}
$sandbox['#finished'] = (empty($sandbox['total'])) ? 1 : ($sandbox['current'] / $sandbox['total']);
$vars = [
'@completed' => $sandbox['current'],
'@element' => implode(',', $sandbox['this_batch']),
'@total' => $sandbox['total'],
'@percentage' => (int) (($sandbox['current'] / $sandbox['total']) * 100),
'@percentage' => (int)(($sandbox['current'] / $sandbox['total']) * 100),
'@skipped_count' => count($sandbox['skipped_items']),
];
// The batch is done, reset the info from last batch.
// The batch is done, reset the info from the last batch.
$sandbox['this_batch'] = [];
$message = t('Processed @element. [@percentage%] [@completed/@total]', $vars);
@@ -563,8 +566,10 @@ class BatchOperations implements ContainerInjectionInterface {
$this->logger->info("$logged_message </br> $summary", $vars);
// Delete the state as it is no longer needed.
$this->state->delete($sandbox['multi_run_state_key']);
// Delete the state as it is no longer needed if 'multi_run_state_key' is set.
    • This also is non optional. It needs to get cleared. We need to make sure that $sandbox['multi_run_state_key'] exists before it gets to this point.

Please register or sign in to reply
if (isset($sandbox['multi_run_state_key'])) {
$this->state->delete($sandbox['multi_run_state_key']);
}
$this->state->delete(self::RUNNING_KEY);
}
return $message;
Loading