2

We're upgrading from Bootstrap 2 to 3. Now I need to replace CSS classes in the body fields of many nodes. This needs to be done in at least 5 sites. What is a good way to replace text in all nodes of a site?

Ideally I'd do it with something like drush replace old_str new_str. Found one thing from 2009 that didn't work at all and then I found drush sar, which didn't do the job either.

0

1 Answer 1

2

The Drush Search and Replace plugin may be of some use

This drush plugin performs a text search & replace on all content and content revisions in all text fields and all custom blocks on a Drupal site.

It does this directly in the database, not by loading, editing and then saving entities, so it is very fast. This also means you should clear the Drupal caches after you run this command.

Hopefully it goes without saying you should give this a dry run before applying it to a live site, how well it works will depend on exactly what data you have in the fields.

4
  • I ran into sar but it doesn't work. I'll add a bug report on d.o if nothing better pops up.
    – the
    Jul 26, 2014 at 13:23
  • It should work for trivial examples like 'row-fluid' => 'row', but obviously it's not going to work for 'span*' => 'col-md-*' and the more complex examples, as those can't be fixed with a simple string replace anyway. A regular expression would be prohibitively complex, so the only real option for those cases is to parse the HTML and loop through the nodes, checking the attributes as you go, changing what needs it, then exporting back to HTML before saving. I'd be surprised if there's a ready-made solution for that, it's a very specific use-case
    – Clive
    Jul 26, 2014 at 13:30
  • That's exactly what I tried, drush sar row-fluid row. Didn't work. No need for ready-made Bootstrap upgrade solution but I'll be happy to put the script I'll make somewhere in a gist.
    – the
    Jul 26, 2014 at 13:31
  • Ah ok, that probably is a bug then
    – Clive
    Jul 26, 2014 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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