There's a serious problem in the example. You can't actually use those $this->somethig calls as the batch operations are not executed in an object context.
Please remove all use of $this in src/BatchService.php file.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | 3159239-14.patch | 1.11 KB | karishmaamin |
| #7 | 3159239.patch | 3.62 KB | Pooja Ganjage |
| #4 | 3159239-4.patch | 1.88 KB | vuil |
| #2 | 3159239-2.patch | 1.55 KB | karishmaamin |
Comments
Comment #2
karishmaamin commentedRemoved $this->t(), Please review
Comment #4
vuilComment #6
jcnventuraALL the $this usags must be removed.
Comment #7
Pooja Ganjage commentedHi,
I am applying patch for not using $this.
Kindly review this patch once.
Thanks.
Comment #8
Pooja Ganjage commentedComment #9
Pooja Ganjage commentedI would like to say that the issue is $this not used in object context but there is no static keyword defined for any method which doesn't have access to $this.
Comment #10
Pooja Ganjage commentedComment #11
sumachaa commentedreplace
$this->messengerwith something like below$messenger = \Drupal::messenger();Comment #12
jcnventuraI don't think that the
src/Commands/Drush9BatchProcessingCommands.phpfile needs to be changed.My previous Needs work was because it was simple to see that the code in #4 (later committed) only converted the
$this->t()tot(), but kept the use of$this->messenger. Even easier to see because they are at the start of half the lines in that patch. The solution is to use\Drupal::messenger()as suggested in #11.Comment #13
jcnventuraIn reply to #9, the problem here is that
BatchService::processMyNode()andBatchService::processMyNodeFinished()functions are used as callbacks to code that is executed in batch mode ouside of object context. This is why the problem exists even when not usingstatic.Comment #14
karishmaamin commentedReplaced $this->messenger with \Drupal::messenger() as mentioned in #11, please review
Comment #16
jcnventuraYes, I think with #14, the example will actually execute.
Comment #17
vuilComment #19
vuil