2

There is an field list overview in the reports for Views that shows the fields used.

Here is a sample of it:

enter image description here

Is there a quick way to find out which fields are used with Rules? It would be enough to check if a certain field is used by Rules.

SOLUTION:

As I don't have a special SQL tool drush works too by entering a query similar to what's included in the accepted answer:

drush sqlq "SELECT id,plugin,active,name,label FROM rules_config WHERE data LIKE '%points_dec%'"
  • The "solution" you added in your 2nd revision is indeed another variation (if you have Drush available). However I think you should move that to an additional answer (eventually with something like "using the query in the accepted answer ...", if you want to do so). – Pierre.Vriens Dec 1 '17 at 10:56
  • Hi Pierre! The essence of the problem (finding a quick way to get the used modules) and most difficult part was the SQL statement that you provided so i think its fine as it is. Many thanks for that! – user24957 Dec 1 '17 at 12:26
3

Consider a rule as in this (random) sample (in Rules export format):

{ "rules_new_node_with_special_optionlist_value" : {
    "LABEL" : "New node with special optionlist value",
    "PLUGIN" : "reaction rule",
    "ACTIVE" : false,
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_insert" : [] },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_optionlist" } },
      { "data_is" : { "data" : [ "node:field-optionlist" ], "value" : "C" } }
    ],
    "DO" : [
      { "drupal_message" : { "message" : "A new node got created with option list value =  \u0022[node:field-optionlist]\u0022" } }
    ]
  }
}

Obviously, the above rule uses a field with machine name field_optionlist.

Execute an SQL query on the Drupal database which looks like so:

SELECT id,plugin,active,name,label
FROM `rules_config`
WHERE `data` LIKE '%optionlist%'
LIMIT 3

The results I get by using this query (limited to the first 3 results only) looks like so:

id  plugin         active  name                                           label

20  reaction rule  0       rules_verify_updates_to_node_properties        Verify updates to node properties
21  reaction rule  0       rules_new_node_with_special_optionlist_value   New node with special optionlist value
28  rule           1       rules_set_an_initial_value_for_a_text_field    Set an initial value for a text field

Obviously, the result with id=21 matches with my (random) sample rule.

To execute the above query, you can use whatever SQL query tool, such as PhpMyAdmin. Or if you rather want to have a site building tool, just use the Forena module (disclosure: I'm a co-maintainer). After you enable this module, these are the steps required to find the answer to your question:

  • Use relative link /admin/structure/forena/data/add (= Create New SQL Query).
  • Select a "Data source" in which the SQL statement (= data block) will be stored (saved).
  • Enter the above SQL statement, and use the Test Changes button (to prototype your SQL).
  • Voilà, there is the (prototyping) result.

The above should answer the "It would be enough to check if a certain field is used by Rules" part of your question, but if you want to further improve this prototype, use the power of Forena to build a custom report from it, and make all sort of magic happen, eg:

  • export it to a CSV.
  • eMail it to somewhere.
  • ...

Note: the above approach works for all sorts of "Rules queries" ... after all, in the above query I used (part of) the machine name of some field (= optionlist). Do an educated guess what kind of results you get if you would use the machine name of:

  • a content type, e.g: article.
  • a rules component, e.g: rules_send_email_notification.
  • a module that some rule(s) depend on, e.g: webform_rules.
  • @user24957 merci for the confirmation (and accept/+1) ... May I say "What else did yu expect"? Or rather "I bet you now know why yesterday I asked about your deadline?" (because I first wanted to do some experiments in my own environment ...). BTW, the challenge in your question gave me an idea about a new contributed module, named something like "Rules Reporting" (suggestions for a better name welcome ...). – Pierre.Vriens Dec 1 '17 at 9:21
  • Forena looks interesting, too. I might need such a functionality for a project. May I suggest to add a screenshot on the module description page (or at least the linked samples page) showing such a report. But this is not about the main question so Ill cut it here. :) – user24957 Dec 1 '17 at 12:31
  • @user24957 "interesting" is an understatement I think, especially if you'd know the effort it took me to actually find the appropriate SQL to answer your question (in about 30 secs of prototyping I knew the SQL I was looking for, including the table name to be used). But there is more: the same technique can be used for other modules (eg: which views refer to this field, a kind of alternative to the field list screenprint in your question). Stay tuned for a (self answered) question I'm thinking of (with all sorts of Forena facilities included, and the "report specs" aka ".frx" file). – Pierre.Vriens Dec 1 '17 at 12:42
0

There's no admin screen, but if you are using the Features module and you have exported all your rules as a feature, then you can use grep.

cd myfeaturesfolder

grep my_field *

  • Thanks for the suggestion but I am not using Features. I was thinking about exporting all Rules and components manually and search therein, but I was hoping there is something quicker. – user24957 Nov 30 '17 at 8:47
  • That's basically what Features does-- it exports everything to code, which you can then search as text. It would definitely be faster to install Features and quickly export all the rules that way than to export rules one-by-one if you have a lot of rules. – Patrick Kenny Nov 30 '17 at 8:48
  • Using Feature is certainly quicker indeed. I will wait a few hours and accept this answer if there is no other simpler way (e.g. with Drush). – user24957 Nov 30 '17 at 8:54
  • Hi Pierre! no real deadline here. I really dont mind testing myself too. thanks – user24957 Nov 30 '17 at 9:34
  • @Pierre.Vriens This kind of comment should be on the original question, not my answer. – Patrick Kenny Nov 30 '17 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.