Overwriting reference variable causes only some batch sets to run on installation

Created on 15 March 2020, over 4 years ago
Updated 15 February 2023, over 1 year ago

Some installation tasks (in my case installing local language po files) aren't being run. Only the last set of the batch in install_run_task() is being run.

The problem is caused by overwriting a reference variable in core/includes/install.core.inc in the batches loop, we use the variable $batch twice. This was introduced in #1993452: Fix confusing UX by merging "Translate configuration" into "Finish translations" task β†’

This is easier to demonstrated with an example of the code, rather than a Drupal test, maybe someone else can write the proper Drupal test. Below is a simple test using just PHP showing how using the same general code causes the problem.

<?php

class Test {

  function run() {
    $exsiting = $this->getTestResultsExisting();
    batch_reset();
    $fixed = $this->getTestResultsFixed();
    print_r(get_defined_vars());
  }

  function getTestResultsExisting() {
    $batches = [
      ['value' => 'test1'],
      ['value' => 'test2'],
    ];
    foreach ($batches as $batch) {
      batch_set($batch);

      $batch =& batch_get();
      $batch['progressive'] = FALSE;
    }

    $batch =& batch_get();
    return $batch;
  }

  function getTestResultsFixed() {
    $batches = [
      ['value' => 'test1'],
      ['value' => 'test2'],
    ];
    foreach ($batches as $batch_definition) {
      batch_set($batch_definition);

      $batch =& batch_get();
      $batch['progressive'] = FALSE;
    }

    $batch =& batch_get();
    return $batch;
  }

}

$test = new Test;
$test->run();

function &batch_get() {
  static $batch = [];
  return $batch;
}

function batch_set($batch_definition) {
  if ($batch_definition) {
    $batch =& batch_get();
    $batch_set = $batch_definition + ['sandbox' => []];
    $batch['sets'][] = $batch_set;
  }
}

function batch_reset() {
  $batch =& batch_get();
  $batch = [];
}
πŸ› Bug report
Status

Closed: cannot reproduce

Version

10.1 ✨

Component
InstallΒ  β†’

Last updated 2 days ago

No maintainer
Created by

πŸ‡ΊπŸ‡ΈUnited States douggreen Winchester, VA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States Kristen Pol Santa Cruz, CA, USA

    Since no additional information has been provided and it's been more than 3 months, I'm marking the issue "Closed (cannot reproduce)". If anyone can provide complete steps to reproduce the issue (starting from "Install Drupal core"), document those steps in the issue summary and set the issue status back to "Active" [or "Needs Work" if it has a patch, etc.].

Production build 0.71.5 2024