Problem/Motivation

A batch builder object was added in #2401797: Introduce a batch builder class to make the batch API easier to use. The Drupal core should be updated to use the batch builder.

The code to update can most easily be found by looking for the uses of batch_set(). Example usage is in the class comment for \Drupal\Core\Batch\BatchBuilder.

Proposed resolution

Use BatchBuilder in the following core modules:

Remaining tasks

  • Fix remaining test failures/code review items in the following core modules:
    • simpletest
    • system
    • update
  • Review patch
  • needs a followup

List of contributors

overall: john@johncook.me.uk, mradcliffe
- config: rajeshwari10 at Valuebound, RajeevK at Sirius, Yogesh Pawar at QED42, James.Shee
- locale: lcngeo
- migrate_drupal_ui: rajeshwari10 at Valuebound, RajeevK at Sirius, Yogesh Pawar at QED42
- node: rajeshwari10 at Valuebound, RajeevK at Sirius, borisson_
- simpletest: time2buzzthetower, RajeevK at Sirius
- system: ccasals at Portland Webworks
- update: kavo
- user: ccasals at Portland Webworks

CommentFileSizeAuthor
#71 interdiff-66-71.txt9.14 KBjungle
#71 2875279-71.patch38.91 KBjungle
#68 2875279-8.9.x-68.patch41.37 KBjungle
#68 raw-interdiff-66-68.txt1.87 KBjungle
#66 interdiff-64-66.txt1.38 KBjungle
#66 2875279-66.patch41.4 KBjungle
#64 interdiff-63-64.txt526 bytesjungle
#64 2875279-64.patch41.31 KBjungle
#63 interdiff-58-63.txt6.71 KBjungle
#63 2875279-63.patch41.32 KBjungle
#58 interdiff-57-58.txt587 bytesjungle
#58 2875279-58.patch43.9 KBjungle
#57 53-57.txt10.88 KBjungle
#57 2875279-57.patch44.02 KBjungle
#53 interdiff-52-53.txt16.77 KBjungle
#53 2875279-53.patch41.37 KBjungle
#52 interdiff-2875279-50-52.txt2.85 KBvoleger
#52 2875279-52.patch41.32 KBvoleger
#50 interdiff-49-50.txt782 bytesjungle
#50 2875279-50.patch40.92 KBjungle
#49 2875279-49.patch40.92 KBjungle
#49 interdiff-45-49.txt1.58 KBjungle
#45 drupal-2875279-batchbuilder-45.patch41.15 KBjpatel657
#42 drupal-2875279-batchbuilder-42.patch40.91 KBmrinalini9
#36 interdiff-35-36.txt489 bytesJohn Cook
#36 drupal-2875279-batchbuilder-36.patch41.32 KBJohn Cook
#35 interdiff-34-35.txt1.63 KBJohn Cook
#35 drupal-2875279-batchbuilder-35.patch41.79 KBJohn Cook
#34 drupal-2875279-batchbuilder-34.patch43.42 KBJohn Cook
#29 drupal-2875279-batchbuilder-29.patch43.54 KBJohn Cook
#27 drupal-2875279-batchbuilder-26.patch43.39 KBJohn Cook
#25 interdiff-2875279-23-25.txt1.82 KBJohn Cook
#25 drupal-2875279-batchbuilder-25.patch43.37 KBJohn Cook
#23 interdiff-2875279-22-23.txt1.82 KBJohn Cook
#23 drupal-2875279-batchbuilder-23.patch43.51 KBJohn Cook
#22 interdiff-2875279-21-22.txt5.57 KBJohn Cook
#22 drupal-2875279-batchbuilder-22.patch43.85 KBJohn Cook
#21 interdiff-2875279-20-21.txt1.12 KBJohn Cook
#21 drupal-2875279-batchbuilder-21.patch42.7 KBJohn Cook
#20 interdiff-2875279-19-20.txt1.25 KBJohn Cook
#20 drupal-2875279-batchbuilder-20.patch42.72 KBJohn Cook
#19 interdiff-2875279-17-19.txt1.11 KBJohn Cook
#19 drupal-2875279-batchbuilder-19.patch41.47 KBJohn Cook
#18 drupal-2875279-batchbuilder-17.patch41.31 KBJohn Cook
#17 interdiff-2875279-16-17.txt985 bytesJohn Cook
#16 interdiff-2875279-15-16.txt5.74 KBJohn Cook
#16 drupal-2875279-batchbuilder-16.patch41.37 KBJohn Cook
#15 interdiff-2875279-14-15.txt2.28 KBJohn Cook
#15 drupal-2875279-batchbuilder-15.patch40.53 KBJohn Cook
#14 interdiff-2875279-13-14.txt8.23 KBJohn Cook
#14 drupal-2875279-batchbuilder-14.patch40.28 KBJohn Cook
#13 interdiff-2875279-11-13.txt5.35 KBJohn Cook
#13 drupal-2875279-batchbuilder-13.patch37.39 KBJohn Cook
#11 drupal-2875279-batchbuilder-11.patch34.66 KBJohn Cook
#8 drupal-2875279-batchbuilder-8.patch34.82 KBmradcliffe

Issue fork drupal-2875279

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

John Cook created an issue. See original summary.

John Cook’s picture

Issue summary: View changes
John Cook’s picture

Title: META ISSUE: Update core modules to use the new batch service » [META] Update core modules to use the new batch service

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

John Cook’s picture

Title: [META] Update core modules to use the new batch service » [META] Update core modules to use the new batch builder
Issue summary: View changes
Parent issue: #2875151: [META] Implement Batch API as a service » #2401797: Introduce a batch builder class to make the batch API easier to use
Related issues: -#2401797: Introduce a batch builder class to make the batch API easier to use

Updated the summary.

alexpott’s picture

Please let's do the sub issues here in one patch rather than multiple patches. They are the same task - see https://www.drupal.org/core/scope

mradcliffe’s picture

Title: [META] Update core modules to use the new batch builder » Update core modules to use the new batch builder
Issue summary: View changes
Status: Active » Needs review
FileSize
34.82 KB

Here's a combined patch from all the closed child issues. It'll probably fail tests and get back to Needs Work based on some of the child issues.

I added contributors from the child issues to the issue summary and removed the Meta since it's no longer a meta.

mradcliffe’s picture

Issue summary: View changes
Status: Needs review » Needs work

Adding some of my reviews:

I found that _locale_translation_batch_status_operations is a wrapper for generating multiple operations using the 'locale_translation_batch_status_check' callback. I think we may need to think of a way to keep adding multiple operations?

Maybe BatchBuilder should be able to add multiple operations in a new addOperations method?

  1. +++ b/core/modules/locale/locale.compare.inc
    @@ -236,17 +237,14 @@ function locale_translation_batch_status_build($projects = [], $langcodes = [])
    +    ->addOperation('_locale_translation_batch_status_operations', [$projects, $langcodes, $options]);
    

    I'm not sure if this is the correct callback for this batch.

    _locale_translation_batch_status_operations() returns an array of operations based on some logic and the operation is locale_translation_batch_status_check.

    Additionally I think that we would need to add a @deprecated annotation into the _locale_translation_batch_status_operations function if it's no longer needed.

  2. +++ b/core/modules/locale/locale.fetch.inc
    @@ -33,20 +35,19 @@ function locale_translation_batch_update_build($projects = [], $langcodes = [],
    -  $operations = array_merge($operations, _locale_translation_fetch_operations($projects, $langcodes, $options));
    +  $batch_builder->addOperation('_locale_translation_fetch_operations', [$projects, $langcodes, $options]);
    

    Same as above.

  3. +++ b/core/modules/locale/locale.fetch.inc
    @@ -67,15 +68,14 @@ function locale_translation_batch_fetch_build($projects = [], $langcodes = [], $
    +    ->addOperation('_locale_translation_fetch_operations', [$projects, $langcodes, $options])
    

    Same as above. Operation is locale_translation_batch_status_check?

  4. +++ b/core/modules/system/src/Controller/DbUpdateController.php
    @@ -617,13 +618,14 @@ protected function triggerBatch(Request $request) {
    +      ->setTitle(t('Updating'))
    

    Missing a $this->t() instead of t().

  5. +++ b/core/modules/system/src/Controller/DbUpdateController.php
    @@ -617,13 +618,14 @@ protected function triggerBatch(Request $request) {
    +      ->addOperation($operations[])
    
    +++ b/core/modules/system/tests/modules/batch_test/batch_test.module
    @@ -42,11 +43,11 @@ function _batch_test_batch_1() {
    +    ->addOperation($operations[])
    
    @@ -94,11 +92,11 @@ function _batch_test_batch_3() {
    +    ->addOperation($operations[])
    
    @@ -123,11 +121,11 @@ function _batch_test_batch_4() {
    +    ->addOperation($operations[])
    
    @@ -145,11 +143,11 @@ function _batch_test_batch_5() {
    +    ->addOperation($operations[])
    

    I think these need multiple addOperation calls unless BatchBuilder can accept multiple operations in a new method.

  6. +++ b/core/modules/system/tests/modules/batch_test/batch_test.module
    @@ -60,14 +61,11 @@ function _batch_test_batch_2() {
    +    ->addOperation(['_batch_test_callback_2', [1, $total, $sleep]])
    
    +++ b/core/modules/system/tests/modules/batch_test/src/Controller/BatchTestController.php
    @@ -47,9 +48,9 @@ public function testLargePercentage() {
    +      ->addOperation(['_batch_test_nested_drupal_form_submit_callback', [$value]])
    

    Shouldn't this be

    addOperation('_batch_test_Callback_2', [1, $total, $sleep]) instead?

John Cook’s picture

Issue tags: +Nwdug_may18
John Cook’s picture

Status: Needs work » Needs review
FileSize
34.66 KB

The patch from #8 needed a re-roll, so here it is.

I'm still expecting this to fail many tests and this patch does not address any of the points from @mradcliffe.

Status: Needs review » Needs work

The last submitted patch, 11: drupal-2875279-batchbuilder-11.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

John Cook’s picture

I've made a new patch that addresses point 1 - 3 from #9 by @mradcliffe.

I'll have a look at the rest of the problems shortly.

John Cook’s picture

Another patch. This one to address point 4–6 from #9.

I'm still expecting a lot of failed tests.

John Cook’s picture

Fixed a bug in the DbUpdateController class.

John Cook’s picture

I've discovered that the callable type hint requires that the function be in memory, especially when running tests.

Because for this I've added an include_once when the ::setFile() is called on a BatchBuilder object. The method calls also need to be in the correct order, with the call to ::setFile() being before the methods that set the callback functions.

I'm adding the novice tag for changing the order of the method calls for the error-ing tests.

John Cook’s picture

FileSize
985 bytes

I've removed the inclusion of a file that no longer exists.

John Cook’s picture

John Cook’s picture

There is currently a bug with Batch API and non-progressive batches and a work around is currently required.

The progressive/non-progressive bug has already been raised as #638712: Make non-progressive batch operations possible.

John Cook’s picture

The changes in comment #16 broke one of the BatchBuilder's own tests. This update fixes that test.

John Cook’s picture

There were a couple of rouge references to $this in some functions (not part of a class). This patch removes them.

John Cook’s picture

I've worked on the few failing tests from #21.

John Cook’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Novice
FileSize
43.51 KB
1.82 KB

Addressed the coding standards from the testbot.

Removed the novice tag.

alexpott’s picture

+++ b/core/modules/system/tests/src/Unit/Batch/BatchBuilderTest.php
@@ -114,10 +114,10 @@ public function testSetErrorMessage() {
     $batch = (new BatchBuilder())
-      ->setFile('filename.php')
+      ->setFile(__DIR__ . '/../../../modules/batch_test/batch_test.set_file_test.inc')
       ->toArray();
 
-    $this->assertEquals('filename.php', $batch['file']);
+    $this->assertEquals(__DIR__ . '/../../../modules/batch_test/batch_test.set_file_test.inc', $batch['file']);

Let's put this file in core/modules/system/tests/fixtures/batch

it's not part of that test module really.

Also this test shouldn't be in system. It should be in core/tests/Drupal/Tests/Core/Batch - can you open an issue to move it there?

John Cook’s picture

I've created a new issue to move the test class – #2982983: Batch Builder tests in the wrong location.

And 'batch_test.set_file_test.inc' has been moved as requested.

Status: Needs review » Needs work

The last submitted patch, 25: drupal-2875279-batchbuilder-25.patch, failed testing. View results

John Cook’s picture

Status: Needs work » Needs review
FileSize
43.39 KB

Fixed the merge conflict.

Status: Needs review » Needs work

The last submitted patch, 27: drupal-2875279-batchbuilder-26.patch, failed testing. View results

John Cook’s picture

Status: Needs work » Needs review
FileSize
43.54 KB

Re-rolled #27 because of recent commits.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joachim’s picture

+++ b/core/lib/Drupal/Core/Batch/BatchBuilder.php
@@ -205,12 +205,17 @@ public function setErrorMessage($message) {
+   * The file needs to be set before using ::addOperation(),
+   * ::setFinishCallback(), or any other function that uses callbacks from the
+   * file. This is so that PHP knows about the included functions.
+   *
    * @param string $filename
    *   The path to the file.
    *
    * @return $this
    */
   public function setFile($filename) {
+    include_once $filename;

This change looks like it's fixing a bug in BatchBuilder itself. That's out of scope for this issue, surely?

quietone’s picture

Status: Needs review » Needs work

Changing to NW for the question in #31.

John Cook’s picture

I've created a new issue for comment #31. #3028621: BatchBuilder included files fails

John Cook’s picture

A re-roll of the commit from #29.

John Cook’s picture

I've removed the bug fix code from the patch, but that means that this is now dependent on #3028621: BatchBuilder included files fails being committed.

John Cook’s picture

Removed a testing file that is now provided elsewhere.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

andypost’s picture

Issue tags: +Needs reroll
mrinalini9’s picture

Assigned: Unassigned » mrinalini9
mrinalini9’s picture

Assigned: mrinalini9 » Unassigned
Status: Needs work » Needs review
FileSize
40.91 KB

Rerolled patch #36 for 9.1.x, please review.

Status: Needs review » Needs work

The last submitted patch, 42: drupal-2875279-batchbuilder-42.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jpatel657’s picture

Assigned: Unassigned » jpatel657
Status: Needs work » Active
jpatel657’s picture

Assigned: jpatel657 » Unassigned
Status: Active » Needs review
FileSize
41.15 KB

Code sniffer has been updated..

Status: Needs review » Needs work

The last submitted patch, 45: drupal-2875279-batchbuilder-45.patch, failed testing. View results

jungle’s picture

Title: Update core modules to use the new batch builder » [PP-1] Update core modules to use the new batch builder
Status: Needs work » Postponed
Related issues: +#3028621: BatchBuilder included files fails
jungle’s picture

Title: [PP-1] Update core modules to use the new batch builder » Update core modules to use the new batch builder
Status: Postponed » Needs review

The blocker is in, re-queued a test.

jungle’s picture

+++ b/core/modules/config/src/Form/ConfigSingleImportForm.php
@@ -411,19 +411,16 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
-          'finished' => [ConfigImporterBatch::class, 'finish'],
...
+          ->setFinishCallback([ConfigSync::class, 'finishBatch'])
...
-          $batch['operations'][] = [[ConfigImporterBatch::class, 'process'], [$config_importer, $sync_step]];
+          $batch_builder->addOperation([ConfigSync::class, 'processBatch'], [$config_importer, $sync_step]);

Class/callbacks should not be changed.

jungle’s picture

FileSize
40.92 KB
782 bytes
+++ b/core/modules/system/tests/modules/batch_test/batch_test.module
@@ -119,21 +111,18 @@ function _batch_test_batch_4() {
-  $operations[] = ['_batch_test_nested_batch_callback', [[2]]];
+  $batch_builder->addOperation('_batch_test_nested_batch_callback');

Parameter lost

jungle’s picture

+++ b/core/modules/system/tests/modules/batch_test/batch_test.module
@@ -88,22 +82,20 @@ function _batch_test_batch_3() {
   $total = 10;
   $sleep = (1000000 / $total) * 2;
...
   for ($i = 1; $i <= round($total / 2); $i++) {
-    $operations[] = ['_batch_test_callback_1', [$i, $sleep]];

Room to improve/micro optimization in _batch_test_batch_*(). could do in a separate issue. Fewer iterations $total < 10, smaller $sleep if possible?

voleger’s picture

FileSize
41.32 KB
2.85 KB

Added some missing replacements and removed the redundant variable.

jungle’s picture

FileSize
41.37 KB
16.77 KB

@voleger, many thanks for fixing the tests.

Refactoring a bit to keep them consistent like below.

$batch_builder = (new BatchBuilder())
  // Call `setFile()` first, even it's not mandatory.
  ->setFile()
  // The rest.
  ...

batch_set($batch_builder->toArray());
jungle’s picture

Continue with #53

+++ b/core/modules/system/tests/modules/batch_test/batch_test.module
@@ -38,7 +37,6 @@ function _batch_test_batch_1() {
-  /** @var \Drupal\Core\Batch\BatchBuilder $batch_builder */

@@ -82,11 +80,9 @@ function _batch_test_batch_3() {
-  /** @var \Drupal\Core\Batch\BatchBuilder $batch_builder */

@@ -111,7 +108,6 @@ function _batch_test_batch_4() {
-  /** @var \Drupal\Core\Batch\BatchBuilder $batch_builder */

@@ -135,13 +132,13 @@ function _batch_test_batch_5() {
-  /** @var \Drupal\Core\Batch\BatchBuilder $batch_builder */

@@ -155,13 +152,13 @@ function _batch_test_batch_6() {
-  /** @var \Drupal\Core\Batch\BatchBuilder $batch_builder */

@@ -179,7 +176,6 @@ function _batch_test_batch_7() {
-  /** @var \Drupal\Core\Batch\BatchBuilder $batch_builder */

Type hints are unnecessary here. Unlike other variables, without it, autocomplete feature in PHPStorm still works.

jungle’s picture

Issue tags: +Bug Smash Initiative

#3028621 is relevant to this, which is a bug, so tagging Bug Smash Initiative as well.

quietone’s picture

Status: Needs review » Needs work

Due to my interest in migrate I started at the migrate drupal ui form and reviewed to the end, missing the beginning of the patch. Now, my eyes have had enough so not looking at the first part of the patch.

The tests are passing and there are no coding standard notifications. Nice.

I noticed that the added use statement is inconsistently placed, sometimes it is in alphabetical order and sometimes not. I find it easier to skim that list if they are in alphabetical order so, if possible, let's make that consistent. Another inconsistency is the change from t() to $this->t(). I think changing those is out of scope for this issue so should be removed. Unless, of course, I am wrong about that.

  1. +++ b/core/modules/migrate_drupal_ui/src/Form/ReviewForm.php
    @@ -5,6 +5,7 @@
    +use Drupal\Core\Batch\BatchBuilder;
    

    Please keep in alphabetical order.

  2. +++ b/core/modules/node/node.admin.inc
    @@ -6,6 +6,7 @@
    +use Drupal\Core\Batch\BatchBuilder;
    

    Can we keep this is alphabetical order?

  3. +++ b/core/modules/node/node.admin.inc
    @@ -34,21 +35,15 @@ function node_mass_update(array $nodes, array $updates, $langcode = NULL, $load
    -      // We use a single multi-pass operation, so the default
    -      // 'Remaining x of y operations' message will be confusing here.
    -      'progress_message' => '',
    

    Why is this removed?

  4. +++ b/core/modules/node/node.module
    @@ -1039,14 +1040,11 @@ function node_access_rebuild($batch_mode = FALSE) {
    +        ->addOperation('_node_access_rebuild_batch_operation')
    

    Why is the second parameter removed?

  5. +++ b/core/modules/update/src/Controller/UpdateController.php
    @@ -59,16 +60,13 @@ public function updateStatus() {
    +      ->addOperation([$this->updateManager, 'fetchDataBatch'])
    

    Why is the second parameter removed?

  6. +++ b/core/modules/update/src/Form/UpdateManagerUpdate.php
    @@ -12,6 +12,7 @@
    +use Drupal\Core\Batch\BatchBuilder;
    
    +++ b/core/modules/update/update.authorize.inc
    @@ -12,6 +12,7 @@
    +use Drupal\Core\Batch\BatchBuilder;
    

    Also out of alpha order.

  7. +++ b/core/modules/update/update.authorize.inc
    @@ -91,25 +90,18 @@ function update_authorize_run_update($filetransfer, $projects) {
    -    // @todo Use a different finished callback for different messages?
    

    Should this todo stay?

  8. +++ b/core/modules/user/user.module
    @@ -614,13 +615,6 @@ function user_cancel($edit, $uid, $method) {
    -  // Initialize batch (to set title).
    -  $batch = [
    -    'title' => t('Cancelling account'),
    -    'operations' => [],
    -  ];
    -  batch_set($batch);
    

    Why is this batch no longer needed?

jungle’s picture

Status: Needs work » Needs review
FileSize
44.02 KB
10.88 KB

@quietone, many thanks for your detailed review!

  1. Fixed use statements order in 12 files related, including #56.1, 2 and 6
  2. #56.3. added back
  3. #56.4, 5, the 2nd parameter is optional, but added back.
      public function addOperation(callable $callback, array $arguments = []) {
      
  4. #56.7 Added back.
  5. #56.8 Added back.
  6. Another inconsistency is the change from t() to $this->t()

    I think it's ok. in classes/traits we use $this->t() if possible, otherwise, use t().

jungle’s picture

FileSize
43.9 KB
587 bytes
+++ b/core/modules/user/user.module
@@ -615,11 +616,9 @@ function user_cancel($edit, $uid, $method) {
   // Initialize batch (to set title).
-  $batch = [
-    'title' => t('Cancelling account'),
-    'operations' => [],
-  ];
-  batch_set($batch);
+  $batch_builder = (new BatchBuilder())
+    ->setTitle(t('Cancelling account'));
+  batch_set($batch_builder->toArray());

@@ -630,22 +629,19 @@ function user_cancel($edit, $uid, $method) {
-  // Finish the batch and actually cancel the account.
-  $batch = [
-    'title' => t('Cancelling user account'),
-    'operations' => [
-      ['_user_cancel', [$edit, $account, $method]],
-    ],
-  ];
+  // Initialize batch (to set title).
+  $batch_builder = (new BatchBuilder())

Self review, the 2nd comment is wrong.

quietone’s picture

@jungle, oh, sorry. I think I didn't explain the alphabetization of the use statement clearly. I mean just add theuse Drupal\Core\Batch\BatchBuilder; in the 'best' alphabetical position possible. That is, where the use statements are already ordered it should be easy to add this new line. When this list is not order, do the best one can. Alphabetizing the whole list of use statements is out of scope.

jungle’s picture

Re #59 @quietone, no worries, however, as I already did, I do not think it's necessary to revert them, or if you think it's necessary, setting back to NW, please, thanks!

jonathanshaw’s picture

  1. +++ b/core/modules/locale/locale.compare.inc
    @@ -260,20 +261,20 @@ function locale_translation_batch_status_build($projects = [], $langcodes = [])
    + * @internal
    

    Out of scope?

  2. +++ b/core/modules/locale/locale.fetch.inc
    @@ -33,20 +35,19 @@ function locale_translation_batch_update_build($projects = [], $langcodes = [],
    +    ->setErrorMessage('Error importing translation files')
    ...
    +    ->setErrorMessage(t('Error importing translation files'));
    

    Duplicate setErrorMessage

  3. +++ b/core/modules/locale/locale.fetch.inc
    @@ -33,20 +35,19 @@ function locale_translation_batch_update_build($projects = [], $langcodes = [],
    -  $operations = array_merge($operations, _locale_translation_fetch_operations($projects, $langcodes, $options));
    

    Is the effect of this array_merge replicated?

quietone’s picture

Status: Needs review » Needs work

NW for #61 and #59 (to stay strictly in scope).

jungle’s picture

Status: Needs work » Needs review
FileSize
41.32 KB
6.71 KB

@quietone, @jonathanshaw, thanks for reviewing!

Addressing #59 and #61.1, 2.

Re #61.3. Should be ok, array_merge() is not used anymore.

  // Check status of local and remote translation files.
  _locale_translation_batch_status_operations($batch_builder, $projects, $langcodes, $status_options);
  // Download and import translations.
  _locale_translation_fetch_operations($batch_builder, $projects, $langcodes, $options);

And, BTW, $batch_builder is an object. no need to prepend &

jungle’s picture

FileSize
41.31 KB
526 bytes
+++ b/core/modules/node/node.admin.inc
@@ -34,21 +35,19 @@ function node_mass_update(array $nodes, array $updates, $langcode = NULL, $load
+    ;

Leftover, removing.

jonathanshaw’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/locale/locale.fetch.inc
    @@ -89,20 +90,28 @@ function locale_translation_batch_fetch_build($projects = [], $langcodes = [], $
    + * @internal
    

    out of scope?

  2. +++ b/core/modules/migrate_drupal_ui/src/Form/ReviewForm.php
    @@ -240,20 +241,11 @@ public function buildForm(array $form, FormStateInterface $form_state) {
    -      'progress_message' => '',
    ...
    +    $batch_builder = (new BatchBuilder())
    +      ->setTitle($this->t('Running upgrade'))
    +      ->addOperation([MigrateUpgradeImportBatch::class, 'run'], [array_keys($this->migrations), $config])
    +      ->setFinishCallback([MigrateUpgradeImportBatch::class, 'finished']);
    +    batch_set($batch_builder->toArray());
    

    Missing setProgressMessage('')

Otherwise RTBC I think.

I've tried to read through it all and check every batch builder call perfectly duplicates the original.

jungle’s picture

Status: Needs work » Needs review
FileSize
41.4 KB
1.38 KB

@jonathanshaw many thanks for the great review!

Hopefully, this is the last iteration. I did a self-review as well.

Addressing #65

jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community
jungle’s picture

FileSize
1.87 KB
41.37 KB

@jonathanshaw, thanks for RTBC-ing.

Uploading a patch for 8.9.x which should be applicable to 9.0.x as well,

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/locale/locale.compare.inc
    @@ -236,44 +237,42 @@ function locale_translation_batch_status_build($projects = [], $langcodes = [])
    -function _locale_translation_batch_status_operations($projects, $langcodes, $options = []) {
    -  $operations = [];
    -
    +function _locale_translation_batch_status_operations(BatchBuilder $batch_builder, $projects, $langcodes, $options = []) {
    
    +++ b/core/modules/locale/locale.fetch.inc
    @@ -88,21 +89,27 @@ function locale_translation_batch_fetch_build($projects = [], $langcodes = [], $
    -function _locale_translation_fetch_operations($projects, $langcodes, $options) {
    -  $operations = [];
    -
    +function _locale_translation_fetch_operations(BatchBuilder $batch_builder, $projects, $langcodes, $options) {
    

    These methods are marked @internal but I don't think we should optimise this here. We should continue to call them and do something like

    array_walk($operations, function ($operation) use ($batch_builder) {
    call_user_func_array([$batch_builder, 'addOperation'], $operation);
    }
    

    And then file a follow-up to do this - where can discus any BC implications properly. I've not found any contrib usages. So we might decide to go forward as is but having this as part of this change makes it harder to have that discussion.

  2. +++ b/core/modules/locale/locale.compare.inc
    @@ -236,44 +237,42 @@ function locale_translation_batch_status_build($projects = [], $langcodes = [])
    -      $operations[] = ['locale_translation_batch_status_check', [$project, $langcode, $options]];
    +      $batch_builder->addOperation(
    +        'locale_translation_batch_status_check',
    +        [
    +          $project, $langcode, $options,
    +        ]
    +      );
    
    +++ b/core/modules/locale/locale.fetch.inc
    @@ -88,21 +89,27 @@ function locale_translation_batch_fetch_build($projects = [], $langcodes = [], $
    -        $operations[] = ['locale_translation_batch_fetch_download', [$project, $langcode]];
    +        $batch_builder->addOperation(
    +          'locale_translation_batch_fetch_download',
    +          [
    +            $project,
    +            $langcode,
    +          ]
    +        );
    ...
    -      $operations[] = ['locale_translation_batch_fetch_import', [$project, $langcode, $options]];
    +      $batch_builder->addOperation(
    +        'locale_translation_batch_fetch_import',
    +        [
    +          $project,
    +          $langcode,
    +          $options,
    +        ]
    +      );
    
    +++ b/core/modules/system/src/Controller/DbUpdateController.php
    @@ -604,7 +610,14 @@ protected function triggerBatch(Request $request) {
    -        $operations[] = ['update_do_one', [$update['module'], $update['number'], $dependency_map[$function]]];
    +        $batch_builder->addOperation(
    +          'update_do_one',
    +          [
    +            $update['module'],
    +            $update['number'],
    +            $dependency_map[$function],
    +          ]
    +        );
    

    These changes make it header to read than it was and in other places we've kept the single line. Why are we doing this here?

Note as a task and one that should not result in any underlying change this will only get committed to the latest development branch.

jungle’s picture

Thanks @alexpott!

#69.1, a great feedback!

Re #69.2

If the line declaring an array spans longer than 80 characters, each element should be broken into its own line

Per Drupal.Arrays.Array.LongLineDeclaration, for example, even it's an unapplied rule ATM. i am going to changing,

$batch_builder->addOperation(
+        'locale_translation_batch_fetch_import',
+        [
+          $project,
+          $langcode,
+          $options,
+        ]
+      );

to

$batch_builder->addOperation('locale_translation_batch_fetch_import', [
   $project,
   $langcode,
   $options,
]);

Instead of a single line.

$batch_builder->addOperation('locale_translation_batch_fetch_import', [$project, $langcode, $options]);

jungle’s picture

+++ b/core/modules/system/src/Controller/DbUpdateController.php
@@ -613,20 +626,13 @@ protected function triggerBatch(Request $request) {
-      $operations[] = ['drupal_flush_all_caches', []];
+      $batch_builder->addOperation('drupal_flush_all_caches');

Although, by default, the 2nd parameter is [], adding back still. And addressing #69.

quietone’s picture

Issue summary: View changes
Status: Needs review » Needs work

Really nice to see the progress here. Just a few things I noticed.

In #51, this was tagged as needs followup. I could not find where the followup was made. Setting to NW.

I reviewed the patch and notice two inconsistencies, one is that sometimes t() is replaced with $this-t() and sometimes when an array spans longer that 80 characters it is broken into multiple lines and sometimes that is not done (also reported in $69). For me, both of those changes are out of scope and do add to the time it takes to review the patch. There is enough to review here that adding those changes, and done inconsistently, makes this harder to review.

  1. +++ b/core/modules/config/src/Form/ConfigSingleImportForm.php
    @@ -411,19 +412,16 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
    +          $batch_builder->addOperation([ConfigImporterBatch::class, 'process'], [$config_importer, $sync_step]);
    

    There are many changes like this where the line is greater than 80 characters and the array is not split onto multiple lines. Which is correct here as that would be out of scope.

  2. +++ b/core/modules/system/src/Controller/DbUpdateController.php
    @@ -604,7 +610,11 @@ protected function triggerBatch(Request $request) {
    -        $operations[] = ['update_do_one', [$update['module'], $update['number'], $dependency_map[$function]]];
    +        $batch_builder->addOperation('update_do_one', [
    +          $update['module'],
    +          $update['number'],
    +          $dependency_map[$function],
    +        ]);
    

    And yet, as pointed out in #69 this one is changed. I think this is out of scope.

  3. +++ b/core/modules/config/src/Form/ConfigSync.php
    @@ -364,19 +365,16 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
    +          ->setTitle($this->t('Synchronizing configuration'))
    ...
    +          ->setInitMessage($this->t('Starting configuration synchronization.'))
    +          ->setProgressMessage($this->t('Completed step @current of @total.'))
    +          ->setErrorMessage($this->t('Configuration synchronization has encountered an error.'));
    

    The changes to using $this->t are also out of scope.

  4. +++ b/core/modules/system/src/Form/PrepareModulesEntityUninstallForm.php
    @@ -180,19 +181,12 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
    +      ->setTitle($this->t('Deleting @entity_type_plural', ['@entity_type_plural' => $entity_type_plural]))
    

    As above.

  5. +++ b/core/modules/update/src/Controller/UpdateController.php
    @@ -59,16 +60,13 @@ public function updateStatus() {
    +      ->setTitle($this->t('Checking available update data'))
    ...
    +      ->setProgressMessage($this->t('Trying to check available update data ...'))
    +      ->setErrorMessage($this->t('Error checking available update data.'))
    

    As above.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

andypost’s picture

Spokje made their first commit to this issue’s fork.

Spokje’s picture

Assigned: Unassigned » Spokje

Used 2875279-71.patch for a reroll on 9.3.x in the new MR.

Not addressed anything from #72 (yet).

Spokje’s picture

Spokje’s picture

Status: Needs work » Needs review

- Addressed #72.2
- Found the same issue in core/modules/config/src/Form/ConfigSync.php, addressed that as well.
- Addressed #72.5

Not sure if this is because of changes between the review and now, but I found that both #72.3 and #72.4 are currently in both before and after using $this->t.
So have not addressed those.

Back to NR.

Spokje’s picture

Assigned: Spokje » Unassigned
jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs followup

I'm worried that creating a follow-up for #51 just clogs the issue queue with a task of minor benefit that will never get done. Optimizing the test suite is probably best done systematically using profiling to identify the best places to concentrate attention. It's a possible follow-up but not a NECESSARY one, so no "needs follow-up".

In which case this is RTBC AFAIK.

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

This looks good to me, but it needs a rebase.

jungle’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll

Setting back to RTBC

  • catch committed c5886a7 on 9.3.x
    Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe,...

catch credited James.Shee.

catch credited RajeevK.

catch credited borisson_.

catch credited ccasals.

catch credited lcngeo.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Adding commit credit from the issue summary (thanks for including that).

Committed c5886a7 and pushed to 9.3.x. Thanks!

andypost’s picture

The follow-up is related, needs to get rid of batch_set() #2875151: [META] Implement Batch API as a service

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.