ECA Processing Queued Task error

Issue information

From user: freelock

Related to !436 (closed)

Contribution record

Fork management

Problem/Motivation

When processing a task from the queue, \Drupal\eca_queue\Task::isDueForProcessing() throws an exception, "Typed property Drupal\eca_queue\Task::$time must not be accessed before initialization". This makes queue processing fail.

Steps to reproduce

Create a model that uses the ECA processing queued task event. Use an "Add to queue" action to add something to the queue. Run cron.

Proposed resolution

This is a regression from Commit 776e9526, for #3375167: PHPStand level 6 fixes. That commit added dependency injection to inject the time service, instead of calling it using the non-DI \Drupal::time() call.

The problem is, this task object is unserialized from the queue, and so its constructor is not called -- according to the docs for unserialize(), it explicitly skips the constructor.

Remaining tasks

We could implement an __unserialize() method to re-add the time service, but I'm thinking it's easier/cleaner to just revert to using \Drupal::time() -- I'm not aware of a standard way to do dependency injection on unserialized objects, so I would tend to go with the simpler solution rather than adding complexity here.

Edited by drupalbot
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information