We are running the dev branch of scheduler, and after doing a recent composer update, some ajax requests started returning:

Fatal error: Class 'Drupal\rules\Core\RulesConditionBase' not found in /modules/contrib/scheduler/src/Plugin/Condition/NodeIsScheduledForPublishing.php on line 23

Installing the rules module solved the problem, but if rules is going to be a dependency, it should be listed as one.


This problem was originally reported by mikemccaffrey on #2651348-28: Port Rules integration for Scheduler to Drupal 8 but is better as a separate specific issue.

Comments

jonathan1055 created an issue. See original summary.

jonathan1055’s picture

We do not want to insist that the Rules module is a requirement, because it is not needed for Scheduler. The rules components are provided for those who want to use them, they are entirely optional. The executable Scheduler code which triggers the events is protected inside calls to "moduleExists('rules')" and this works fine when running the site.

There must be some way to avoid the errors you have found. I'll do some investigation.

Jonathan

morsok’s picture

Status: Active » Needs work

If you don't want to enforce a dependency on Rules (which is a good thing to me), then there is only one option since the auto-loader will always throws the missing class exception : you must put all the integration code into a sub-module (scheduler_rules maybe ?) which will depends on rules.

So the main scheduler module will not have the dependency and no errors, and if rules integration is needed you only have to activate the sub-module.

jonathan1055’s picture

Assigned: Unassigned » jonathan1055
Issue summary: View changes
Related issues: +#2778375: Release 1.0-alpha2

Hi Morsok,
Thanks for the info, that is really helpful. Yes I had been thinking that a sub-module might solve the problem, but was not sure if there was a simpler way. But if the auto-loader will always detect the missing classes then it seems that a sub-module is the right solution.

I'll work on this, and hopefully it won't be too long before you get your alpha2 release :-)

Jonathan

jonathan1055’s picture

Status: Needs work » Needs review
StatusFileSize
new68.2 KB

I have moved all the Rules-related code out of the main module and into a sub-module scheduler_rules_integration. In summary, this involved:

  1. create folder scheduler_rules_integration and add scheduler_rules_integration.info.yml
  2. set the dependency on rules in this new .yml file
  3. move .rules_defaults.inc and .rules.events.yml into this new module folder and rename
  4. move four conditions and four action files into scheduler_rules_integration/src/Plugin
  5. move six event files into scheduler_rules_integration/src/Event
  6. changed the namespace of the conditions from Drupal\scheduler\Plugin\Condition to Drupal\scheduler_rules_integration\Plugin\Condition (but the internal id is not changed)
  7. likewise for actions and events
  8. create scheduler_rules_integration.module and move into it the Rules code from hook_node_presave() and hook_node_insert()
  9. remove rules code from SchedulerManager.php and instead call a new function _scheduler_rules_integration_dispatch_cron_event() to invoke the cron events

If the Rules module is not enabled then scheduler_rules_integration cannot be enabled. This prevents the dependency errors as reported in this issue and in #2790471: When editing a block: Fatal error: Class 'Core\RulesConditionBase' not found

I have also tested each part manually and it all works OK. I have written tests to cover all the rules actions, conditions and events, before making this change, and checking it afterwards, and I am happy that it all works. However, uploading these tests does not currently work on drupal.org testbots - I have raised #2775519: Automated testing for 3rd-party modules integrating with Rules

@mikemccaffrey If it is possible for you to test this patch and see if your composer errors are corrected that would be very helpful.

slasher13’s picture

Status: Needs review » Reviewed & tested by the community

Had the same problem. This patch fixed it. Didn't test the Rules integration.

  • jonathan1055 committed 30ece5e on 8.x-1.x
    Issue #2790459 by jonathan1055, morsok: Move all Rules integration code...
jonathan1055’s picture

Title: Composer expects Rules condition class to exist. » Move Rules integration code into a sub-module for accurate dependencies
Status: Reviewed & tested by the community » Fixed

Thanks morsok for the advice and thanks slasher13 for the review.
This is a good fix. Committed and done.

jonathan1055’s picture

Assigned: jonathan1055 » Unassigned

Unassigning

Status: Fixed » Closed (fixed)

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