In a Dev category discussion titled ‘Batch processing to search and replace in all posts’, dandv seeks a Ruby script to perform bulk text replacements in posts after migrating from MyBB, such as converting [hr] to ---------- or fixing quote lines. sam suggests using script/discourse remap, but dandv notes it’s too broad and doesn’t handle post rebaking, excerpts, or reply relationships — critical for quote fixes. codinghorror agrees a safer, post-scoped variant is needed. dandv mentions import plugin authors could adapt such a tool and shares a Node.js API-based alternative. codinghorror formally requests techAPJ to create a dedicated rake task for post-only string replacements. techAPJ confirms its completion, linking to the new task: remap all posts matching a string.
Is there a simple Ruby script somewhere that can be easily tweaked to do a search and replace in all posts?
I’ve migrated from MyBB and there are some tiny formatting tweaks that need to be made, e.g. replace [hr] with ----------, or convert the quote lines. I’m very new to Ruby (basically learned enough last night to submit that quoteline conversion PR), so I’m looking for a skeleton script that loops through existing posts.
remap does a search and replace on text and char columns across all tables - a little rough of a tool. Also, how would the raw → cooked conversion be handled?
Is there a higher-level way of altering and rebaking posts, that would take into account things like re-computing excerpts, quoted posts and reply relationships? The latter are especially important when fixing the quote line after the import.
@techapj I would like a rake task that does string replacements scoped to just posts, if you can add that to your todo list. It can be a variant of the rake task that already exists, just a bit more specific in what it affects..