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
Comments
Comment #2
nkoporecThis 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.
Comment #3
nkoporecComment #4
dieterholvoet commentedInstead of replacing the class I would add a
class_existscheck, that way we can keep it backwards compatible. Also, please start a MR, patches have been deprecated for a while on Drupal.org.Comment #5
zartab farooquee commentedThe 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;
Comment #6
dieterholvoet commentedThe 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.
Comment #7
dieterholvoet commentedHere's a simpler idea: let's add the class aliases to the
scheduler.modulefile. Drupal core does this as well, insdc.module.Comment #8
jonathan1055 commentedHi 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.
Comment #9
dieterholvoet commentedYes, I changed the version. Here's sdc.module.
Comment #10
jonathan1055 commentedI 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
Comment #12
dieterholvoet commentedComment #13
jonathan1055 commentedThis looks good, thanks for doing the changes.
I am going to add test coverage for the aliases, as that was not included before.
Comment #14
jonathan1055 commentedThe 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:
Comment #16
jonathan1055 commentedMerged 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?
Comment #17
dieterholvoet commentedNot urgent for me! I'm sure any other people can use the patch until a new release is created.
Comment #18
jonathan1055 commentedOK 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