Manually execute a rule set across large set of data = Drupal 7 + Rules + Views Bulk Operations

Manually execute a rule set across large set of data = Drupal 7 + Rules + Views Bulk Operations


I have a content type with roughly 50k nodes and I have a view that displays some summarize data of the nodes. I decided I wanted to group the view items by a category that wasn't available or envisioned during the inception period of the data and site. I could go to my content type and add a new field, dump the data, fix it by using feeds tamper or something, and reimport it. OR, much simpler, use Rule Sets and Views Bulk Operations to get the job done.


I have a bunch of accounts for each lab and roughly 20 labs. I need to put the lab names into two different groups. So I went to my content type and created a new field call lab category. I then went to Rules->Components->Add New Component. On this screen you need to give it a name and choose what kind of data type you will be manipulation. In my case, this was data type: node. Give it a label and machine name and leave usage to parameter. Click save and onto next screen. Cick Add Rule. On this screen it is a bit like adding a normal rule except you need to add a condition Entity has field for EACH field you intend to use/manipulate. So add a condition, choose entity has field, in the data selector window choose the name of your data type (WITHOUT the colon) and then below that choose the field. 

Next I used data comparison as a way to say if the lab name is this, set the lab category to this. My final condition list looked like this:

For my action I used Set a data value so I could set the category to whatever I wanted provided the conditions above passed. Once you have everything setup click save changes. Go back to your componenst list and click execute. Well, I thought it would loop through my data and apply my new values, but it didn't. Then I had the bright idea of what if Views Bulk Operations could somehow use the ruleset. Well I was right.

In my case I already had a views bulk operations view setup to help me delete content. So I simply went to that view, clicked on the Bulk operations content field and scrolled down to selected operations and there it was, my rule set. So I checked it as an option, saved, went back to my view, and applied my rule. It ran through all my content and changed all the data values I needed. w00t.

I could see this method being useful in many circumstances. I have already used it a second time to group account names and numbers based on certain criteria. Again, its something that comes up after the final build of the project and someone goes I would love this to be added. A lot less painful and dumping and reloading data!

about the author

David Leary

related posts