Problem/Motivation

When updating to a newer version of scheduler module, I see an error like these:
TypeError: Drupal\content_calendar\EventSubscriber\SchedulerPublishSubScriber::onNodePublish(): Argument #1 ($event) must be of type Drupal\scheduler\SchedulerEvent, Drupal\scheduler\Event\SchedulerEvent given in Drupal\content_calendar\EventSubscriber\SchedulerPublishSubScriber->onNodePublish()

Steps to reproduce

Update to latest scheduler version and try to have a content published at certain time.

Proposed resolution

Fix the namespace in content_calendar

Move the namespace aliases in Scheduler

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#2 scheduler_namespace_change.patch1011 bytesnkoporec

Issue fork scheduler-3476369

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:

Comments

nkoporec created an issue. See original summary.

nkoporec’s picture

StatusFileSize
new1011 bytes

This will require a new major release since its not BC, just putting it here for now and let people test it before we merge this.

nkoporec’s picture

Status: Active » Needs review
dieterholvoet’s picture

Status: Needs review » Needs work

Instead of replacing the class I would add a class_exists check, that way we can keep it backwards compatible. Also, please start a MR, patches have been deprecated for a while on Drupal.org.

zartab farooquee’s picture

The error occurs because the SchedulerEvent class was moved from Drupal\scheduler\SchedulerEvent to Drupal\scheduler\Event\SchedulerEvent in a newer version of the Scheduler module that's the region

Update this old namespace use Drupal\scheduler\SchedulerEvent; // to New namespace use Drupal\scheduler\Event\SchedulerEvent;

dieterholvoet’s picture

Title: TypeError: Drupal\content_calendar\EventSubscriber\SchedulerPublishSubScriber::onNodePublish(): Argument #1 ($event) must be of type Drupal\scheduler\SchedulerEvent, Drupal\scheduler\Event\SchedulerEvent given in Drupal\content_calendar\EventSubscriber\Sc » Argument #1 ($event) must be of type Drupal\scheduler\SchedulerEvent, Drupal\scheduler\Event\SchedulerEvent given
Project: Content Planner » Scheduler

The src/SchedulerEvent.php file in the scheduler module contains a class_alias statement that should prevent this error, but it seems like that file isn't being autoloaded. If I copy-paste that statement to the start of the subscriber file, the error doesn't occur. Maybe we could try manually instructing Composer to autoload that file.

dieterholvoet’s picture

Status: Needs work » Needs review

Here's a simpler idea: let's add the class aliases to the scheduler.module file. Drupal core does this as well, in sdc.module.

jonathan1055’s picture

Hi dieterholvoet
Please can you give a link to the core code where there is the example of doing this.

Also I think the version of Scheduler you mean for this change is 2.x ? I guess that this issue's version 8.x-1.x was a left-over from when it was raised in the Content Planner queue.

dieterholvoet’s picture

Version: 8.x-1.x-dev » 2.x-dev

Yes, I changed the version. Here's sdc.module.

jonathan1055’s picture

Status: Needs review » Needs work

I think you are doing some work on this, as I see you created the issue fork 30 mins ago. The version was 8.x-1.x then, so you will need to update the fork to 2.x

dieterholvoet’s picture

Status: Needs work » Needs review
jonathan1055’s picture

This looks good, thanks for doing the changes.
I am going to add test coverage for the aliases, as that was not included before.

jonathan1055’s picture

Issue summary: View changes

The tests work as expected. PHPUnit passes with the aliases moved, and there is one more test showing in the Events group.

The test only changes job, that is the new test but without the changes to the non-test code, failed as expected with the same error you got:

TypeError:
    Drupal\scheduler_api_legacy_test\EventSubscriber::apiTestNodePrePublish():
    Argument #1 ($event) must be of type Drupal\scheduler\SchedulerEvent,
    Drupal\scheduler\Event\SchedulerEvent given

jonathan1055’s picture

Status: Needs review » Fixed

Merged and fixed.

Can you use the -dev version of Scheduler to test this?
I could also make a new release soon, if it is urgent to fix your site?

dieterholvoet’s picture

Not urgent for me! I'm sure any other people can use the patch until a new release is created.

jonathan1055’s picture

OK thanks for the feedback. This is the only bug fixed since 2.1.0 released 15 August , so I don't think we need a new release just yet

Status: Fixed » Closed (fixed)

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