I originally made this request as part of a comment on another issue (http://drupal.org/node/665080#comment-3251118), but it bears having its own issue since it would be pretty helpful on its own.
Currently, the machine-readable names for individual rules are automatically generated by the system; the default seems to be "rules_n", where "n" is a unique serial ID. If those rules are exported as part of a feature, the same technique is used, except the "rules" portion is replaced by the name of the exported feature.
This approach leads to issues like the one I mentioned above, along with #756888: rules being overwritten by adding new rules; the serial ID appended to the module name isn't really unique enough to avoid naming conflicts. Personally, I think it would be much better if we could specify our own machine-readable name instead, like we already can with rule sets. This is also consistent with the way machine-readable names work on other Drupal components (content types, views, imagecache presets, etc.), and fits better with the features module's philosophy of how machine names should be used (see http://drupalcode.org/viewvc/drupal/contributions/modules/features/API.t... under "Terminology" …technically "rules_n" isn't _just_ a numerically-generated serial ID, but it isn't much better).
All that said, I do like the approach of prefixing the machine name with the name of the providing module. That could easily be formalized in code while still allowing for user-authored unique machine names.
Thanks!
Adam
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | rules-874802-8.patch | 20.23 KB | fabsor |
| #19 | rules-874802-6.patch | 19.45 KB | fabsor |
| #15 | rules-874802-5.patch | 17.15 KB | fabsor |
| #12 | rules-874802-4.patch | 8.45 KB | fabsor |
| #10 | rules-874802-3.patch | 8.5 KB | fabsor |
Comments
Comment #1
fagoAgreed. It works that way for d7, but if we implement that for d6 we need to find a way to still auto-generate a machine name, so that creating rules doesn't necessarily involve even a step more (= finding a machine name).
Comment #2
jazzslider commentedMakes sense to me. Really, as long as we can expect that the _human_-readable names of rules within a given module are unique, we could generate the machine names from them. The formula would be "$module_$name" where $module is the name of the providing module and $name is the rule's human-readable name, converted to all lowercase letters and underscores. $name might also need to be shortened somewhat depending on how verbose the human-readable name happens to be.
Do you know off-hand if there's a core API function that can do that kind of conversion? I know pathauto does it, but it might be using its own functions, and I don't think this'd be worth adding a dependency for.
I'll do some digging and see what I can find out; at any rate, it seems like it'd be a good formula for auto-generating these.
Thanks!
Adam
Comment #3
fago"$module_$name" would be fine, as long as we have a way of ensuring it stays unique. E.g. adding two rules with the same label has to work too.
I'm just aware of the little nice js snippet of d7 that does it nicely, but allows the user to specify a custom name too; e.g. it's used here http://api.drupal.org/api/function/node_type_form/7
We also use it for rules 7.x-2.x, but I don't know whether this could be easily backported to d6?
Comment #4
wizonesolutionsSubscribing. If there are any tasks I could take on for this...let me know, and if I have some time I'll take a stab.
Comment #5
fabsor commentedHi!
Here is a patch that does the following:
* Adds the field "Machine Name" to the add form.
* Adds javascript that creates a machine names on the fly just as in the D7 version. This javascript is a modified version of what they use in features, and creates machine names the same way.
* Fixes the import page so that it can be used with real machine name.
* Removes the logic for enumerating rule names in the features integration. The features integration now uses the same machine names as those created in the UI, to avoid duplication of rules.
Review time! =)
Comment #6
fabsor commentedChanging back to the appropriate component.
Comment #7
itangalo commentedI tried the patch on a clean D6 install (Drupal 6.19, Rules 1.3). It seems that the machine name is not called correctly when creating a new triggered rule.
I got the following error when I created a triggered rule with name 'Alpha' and automatic machine name 'rules_alpha':
user warning: Unknown column 'alpha' in 'where clause' query: SELECT COUNT(*) FROM 100929_rules_rules WHERE name = alpha in /Users/johan/Sites/100929/sites/all/modules/rules/rules_admin/rules_admin.rule_forms.inc on line 92.A similar error is displayed when adding rules to rule sets.
The rules seem to trigger fine, though – the actions are carried out and it looks well.
Everything seems to be working well together with Features as well – I've tried exporting, importing, enabling, disabling both triggered rules and rule sets inside features (even on the same site where they were created).
Good patch! Just a small bit left.
Comment #8
fabsor commentedOops, forgot '' in the query. Here's a fix for that.
Comment #9
fabsor commentedForgot to set status.
Comment #10
fabsor commentedI forgot the db_result around the db_query. Here is a fix.
Comment #11
klausitrailing white space
Powered by Dreditor.
Comment #12
fabsor commentedFixed coding standard issue above and some other coding standards errors.
Comment #13
itangalo commentedLooks fine to me!
+1, but I suggest one or two more reviews should be added before marking it RTBC.
Comment #14
fagothanks for working on that :)
I gave the patch a test and but the machine name field did not appear for me (on add). Apart from that I think it should be visible during edit too. I think it's fine if people can rename existing rules and it's the same for rules 2.
I'd like machine names to match
[a-z][a-z0-9_]*as I suggested in http://drupal.org/node/902644#comment-3536372. I think we can stay with the same JS regex for that."Machine name" should run through t() too.
Comment #15
fabsor commentedH!
Thanks for the review!
The javascript should have shown up on the add page, at least it does so on my machine. Could it be cache-related?.
Anyway here's a new patch that does the following:
* Changed so that the first character must be a letter (we now use [a-z][a-z0-9_]*)
* Changed the javascript so that it changes a machine name which contains anything else than [a-z] as the first character to be replaced by the chacter 'a'. If anyone knows a more fitting replacement, be free to pop in a suggestion.
* Added the possibility to edit rules machine names. I must say that I don't agree with you that the machine names should be changable, since that can screw up features a bit. If you change the machine name which you have in a feature for instance, this will cause the rule to duplicate, since the feature contains a codified version of the same rule, and there's really no clean way of preventing that.
* Since you currently can't change machine names for rule sets, I added the possibility of doing that as well.
* Rewrote machine name validation for rule sets, all machine name validations are now performed by the function rules_admin_validate_machine_name. By doing this, we also squashed a bug when creating rule sets, Currently, there is no check that the machine name already exists for rule sets, which causes the rule set add form to overwrite an existing rule set if it has the same name. This can't happen anymore.
* Fixed translation in javascript.
As you can see, the javascript is not on the edit form. I did this since we don't want the machine name to change just because we change the label. This is also how it is handled in the D7 version of rules.
Comment #16
fagowow, good work.
Well renaming Rule sets might produce troubles, e.g. in actions or other components referring to them. So I don't think we have to provide that, but I guess we can leave it up the user if he really wants too? For triggered rules, I'd expect no such problems. However you are right with the features problem. To solve that we need to disallow renaming Rules provided in code, e.g. just show the name with the form element #disabled.
So I agree with you, generally allowing renames is problematic. So either way, disallow renames at all or just disallow renames for exported rules, would be ok for me.
There should be no leading slash.
Redirects from submith handlers should be issued via FAPI.
Hm, rule sets not necessarily start with a leading 'rules_' because modules may specify custom names. In that case I'd suggest just displaying that + set the form element to #disabled.
Again, redirects in submit handlers have to use FAPI.
* If I clone a Rule, there is no name prefilled. I'd suggest just doing it like Rules2: Add in the JS for machine name generation and append an _(cloned) to the label resulting in an appended _cloned in the machine name too.
Comment #17
fabsor commentedThanks for the review.
I will be coming back with a fixed patch later, just setting the issue to the right status for now =)
Comment #18
rickvug commentedSub. Great work here!
Comment #19
fabsor commentedHi!
This new patch fixes the errors in the review above and makes sure that only rules and rule sets that have the status "custom" can have their name changed.
I have left the feature to rename a rule set, since that is how it is for D7, but it can be easily removed. If we do that then we should probably open another issue for D7 and suggest removing the feature from there as well.
Comment #20
rickvug commentedI tested this path for a good 20 minutes and was unable to break it. I simulated upgrading to machine names (machine names are just the previous triggered rule id). Worked just fine. Exporting to a feature worked as per normal. The locked machine name for rules defined in code also works as one would expected.
Certainly +1 from me. Tempted to mark as RTBC...
Comment #21
bobodrone commentedHi,
This patch works very well and solves all my problems with features and rules.
Nice job!
+1 for me.
Comment #22
fagoSry, for coming back so late to this.
I've gave this another test-run and the improvements look great. However it looks like rule-sets are broken now - there are no rules listed any more even if a set has rules.
Apart from that I found a coding style issue:
missing space, after if.
Hm, I guess too much of this comment is gone? At least it has to start uppercase.
Comment #23
fabsor commentedAh, I did not use the full rule name as input to rules_admin_overview_table.
Here is a patch that fixes that problem and the coding style errors above.
Comment #24
fagoThat looks great. I gave this another test-run and everything seems to work fine. -> Committed!
Thanks for your patience to bring that home! :)
Comment #26
mitchell commentedMoving to "Provided Module Integrations" component.