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.

Comments

jcnventura created an issue. See original summary.

karishmaamin’s picture

Status: Active » Needs review
StatusFileSize
new1.55 KB

Removed $this->t(), Please review

Status: Needs review » Needs work

The last submitted patch, 2: 3159239-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

vuil’s picture

Status: Needs work » Needs review
StatusFileSize
new1.88 KB

  • vuil committed 974d76f on 8.x-1.x
    Issue #3159239 by karishmaamin, vuil: Error: Using $this when not in...
jcnventura’s picture

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

ALL the $this usags must be removed.

Pooja Ganjage’s picture

StatusFileSize
new3.62 KB

Hi,

I am applying patch for not using $this.

Kindly review this patch once.

Thanks.

Pooja Ganjage’s picture

Status: Needs work » Needs review
Pooja Ganjage’s picture

I 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.

Pooja Ganjage’s picture

sumachaa’s picture

replace $this->messenger with something like below

$messenger = \Drupal::messenger();

jcnventura’s picture

Status: Needs review » Needs work

I don't think that the src/Commands/Drush9BatchProcessingCommands.php file 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() to t(), 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.

jcnventura’s picture

In reply to #9, the problem here is that BatchService::processMyNode() and BatchService::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 using static.

karishmaamin’s picture

Status: Needs work » Needs review
StatusFileSize
new1.11 KB

Replaced $this->messenger with \Drupal::messenger() as mentioned in #11, please review

Status: Needs review » Needs work

The last submitted patch, 14: 3159239-14.patch, failed testing. View results

jcnventura’s picture

Status: Needs work » Needs review

Yes, I think with #14, the example will actually execute.

vuil’s picture

Status: Needs review » Reviewed & tested by the community

  • vuil committed 59272e1 on 8.x-1.x authored by karishmaamin
    Issue #3159239 by karishmaamin, Pooja Ganjage, vuil, jcnventura, vuil:...
vuil’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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