We're looking to include as part of our website development to production deployment strategy a step which would delete all nodes of a certain type which have a given tag from the website before moving it out to a staging server. Clearly the View Bulk Operations module is going to be useful for this, but we'd like to do this in batch mode so I'm looking to kick off that process from Drush.

Does anyone have experience in kicking off a view bulk operation from Drush or could give me some idea where to start? I have added my first simple command to Drush, so at least I can do that part. I don't know if I have to create an action for the bulk operation and then use drush to invoke the action, or should I do it some other way.

Comments

moshe weitzman’s picture

you want something like:


$result = db_query("SELECT nid from node where type = 'foo'");
while ($row = db_fetch_object($result)) {
  node_delete($row->nid);
}

moshe weitzman’s picture

Status: Active » Fixed

Note that you probably want to flush the node_load() static cache after each delete so as to reduce memory consumption.

We don't need batch api or bulk operations like features since this is command line and thus no php timeout.

sprior’s picture

Status: Fixed » Active

I was hoping to keep the specific query code out of the code directly invoked by Drush. Maybe define the view bulk operation (I'm talking specifically about the Views Bulk Operation module) as an action, then create some kind of generic action invocation code that Drush actually calls. I'm also hoping to use a named view instead of a hardcoded query so that it can be changed via the view UI.

Does this make any more sense?

moshe weitzman’s picture

Makes sense, but I certainly would implement the stated command using VBO acd actions. Thats two many dependencies for a simple task. It is your command though.

sprior’s picture

After doing some digging into VBO it appears that the bulk operations part is actually done on the client side which then feeds a set of individual operations to the server - not what I'm looking for.

So what I'm looking for now is to accept the name of a view and then loop through the hits of that view and perform some action on those results - similar to what you gave above, but if I can avoid hardcoding the SQL query into it I'd be happier.

sprior’s picture

Status: Active » Closed (fixed)

I was able to figure out how from within Drush to take the name of a view then iterate through its results and perform an operation on them.