In Rules 7.x we had the ability to make a rule inactive, but this has not been ported to 8.x yet. I am in the process of converting the contrib Scheduler modules's actions, conditions and events to 8.x #2651348: Port Rules integration for Scheduler to Drupal 8. I have created many test rules, but when working in a branch of our code which does not have the Scheduler 8.x rules work-in-progress the test rules I have created cause fatal errors because the implementations do not exist.
I need to make the rules inactive, but keep them so I can return to the work later. I presume that if I disable the entire Rules module then any created rules will be deleted. I can't find any export functionality so I guess that has not been ported yet either. I don't want to loose all my work, but equally I can't continue without patching or re-implementing my rules development work.
Any ideas?
Jonathan
[maintainer of Scheduler]
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | 2702127-16.dummy_no_changes.patch | 322 bytes | jonathan1055 |
| #12 | 2702127-12.rules_.enable_disable_toggle.patch | 6.51 KB | jonathan1055 |
| #4 | rules_list_enabled.png | 35.47 KB | yanniboi |
| #4 | rules_list_disabled.png | 39.72 KB | yanniboi |
| #4 | rules_settings_d8.png | 19.29 KB | yanniboi |
Comments
Comment #2
dasjoThanks for posting this.
Not sure if still relevant, but regarding your question / use Case about keeping the rules for later work, you can already Export/import rules using CMI
Comment #3
jonathan1055 commentedOK, I had not thought of that. Thanks for the hint. Yes I can see that I can export a single reaction rule, then delete the rule to allow a code switch to the non-rules branch, then re-import when I want to work on that branch of the code again. But I have created 15 separate reaction rules as part of testing my conversion from 7.x to 8.x so it is a great overhead in time to export all 15, delete them, then import all 15 later. And do that all again, if I need to switch branches to make a fix to the real code.
Are there any plans to implement the active/non-active toggle? If you would like it, but have not got round to looking at it, I could give it a try.
Comment #4
yanniboi commentedI've made a start of this on github here: https://github.com/fago/rules/pull/449
I have exposed the config entity operations for enable and disable by adding link templates and added a Controller to handle them.
I have also added the 'active' checkbox to reaction rule settings and made sure that the event subscriber only triggers active rules.
Screenshots attached (I also attached one screenshot of the settings from in d7 to show what the status checkbox looks like in d7).
Settings in D7
Settings in D8
Comment #5
jonathan1055 commentedThat looks brilliant. I've not got any account on github.com - what is the best way for me to test your changes? Can I extract them as a patch file? Or should I download your entire branch. I am currently on rule 8.x-3.0-alpha1+10-dev on my localhost, which is now a month out of date.
By the way, you confuse me when you say the screenshots are from D7 - this issue is only to fix D8, I think D7 version works just fine (?)
Comment #6
yanniboi commentedHi @jonathan1055, github automatically generates a patch from a pull request if you add '.patch' to the end of the pull request url, so in this case https://github.com/fago/rules/pull/449.patch.
I can see you confusion about me mentioning drupal 7. The reason is that when you are porting changes to drupal 8 and no one told you want a field title or description should be, the best thing to do is what did it look like in d7, and that is what you should do in d8 until someone tells you that something different is better.
In d7 the rule status was a checkbox with 'Active' as the title and no description, so that is what I did for d8 and the screenshot shows this.
Thanks for helping review :)
Comment #7
yanniboi commentedComment #8
jonathan1055 commentedThanks for the explanation. Thank you also for giving the url for the patch - that is very good, and I can see that you have made another commit and it all gets wrapped up into the one patch.
I have tested it manually and found no problems so far. Changing the status via the checkbox and via the drop-down list both work correctly with no errors. Enabled rules are triggered and disabled rules are not triggered.
I tried running the tests which you changed, by selecting just
\Drupal\Tests\rules\Functional\ConfigureAndExecuteTestand\Drupal\Tests\rules\Functional\UiPageTeston the testing UI page. However, this produced the error message "No test results to display". Not sure what is going on there - maybe these tests cannot be run in isolation?Hope that helps - and thank you for providing this functionality so quickly after I raised the issue.
Comment #9
klausiMakes sense - the only thing I saw was the CSRF security vulnerability. Can you make sure those routes have the csrf protection enabled?
Comment #10
yanniboi commentedUpdated
Comment #11
jonathan1055 commentedI was about to test the minor change from #10 but unfortunately the combined patch no longer applies (was ok at alpha1+12, but not now at alpha1+17). The problem is GenericEventSubscriber.php which has changed right at the point where this patch added the 'status=1' criteria:
Here is the code comparison:

I will revert to using alpha1+12 for now, as this toggle it vital for me, and it is not easy to see exactly how I should make the manual change for the failed hunk.
Comment #12
jonathan1055 commentedFollowing the reworking of GenericEventSubscriber onRulesEvent() as described above, I have finally worked out a way to filter for only enabled rules. I am sure this is not the best way, but it's a start. There is now no change to GenericEventSubscriber.php and the filtering is done in RulesExpression/Rule.php function executeWithState() instead. Apart from these two files, the other five in the patch have not changed.
I know that the entity.manager should be injected, but I am doing this just for 'proof of concept' or to see if others have better ways to do it. Also I realise that development has to take place on GitHub first. I am just submitting the patch to see how this goes and if I'm on the right lines.
Comment #14
jonathan1055 commentedWell, I have no idea what happened there, but one nice thing ... the two modified tests to check the enable/disable functionality both passed OK.
Comment #16
jonathan1055 commentedJust to see if those test failures are anything to do with my patch, here is a dummy patch which changes nothing but a comment.
Comment #17
fagoYep, the tests are green in general. Could you create a PR for your patch according to https://github.com/fago/rules#contributing ? This will re-trigger a new test run on travis-ci also, what includes code style checks.
Comment #18
sibustephen commented@fago, I will be looking into it.
Comment #19
tr commented@sibustephen Thanks! This feature is already implemented in D8 Rules Essentials Please install that module and try it out. The code is an updated version of the patch by @jonathan1055 from #12. As far as I know it's fully working, but if you find problems please report them in the D8 Rules Essentials issue queue. There's also Drush support for this feature in #3035337: Port rules.drush.inc to D8 which I hope to commit to Rules in the next few days.
I put the enable/disable functionality in that project and not here because it's entangled in UI changes and improvements that are not easily separated. My intention is to get this and all the other features fully working in that project before moving those features into Rules.
Also, @fago isn't very active in this project currently. We're not using his github repository for development right now - we're doing everything through the issue queue here. So for this an all other Rules issues you should be posting patches / reviewing patches here in the issue queue and not on github.
Comment #20
sharique commented@TR if it is working fine in tr_rulez, can we make a patch for this module?
Comment #21
tr commentedTagging issues that will be fixed by code moved from D8RE.
Comment #22
tr commentedCompleted by #3104328: Move list builders from D8RE into Rules
Comment #23
jonathan1055 commentedI was trying to make @yanniboi's code work back in 2016. Thank you @TR for all your work on this, and so many other Rules issues.