FriendsOfFlarum / formatting

Customize TextFormatter with plugins through the admin interface
MIT License
22 stars 10 forks source link

how do I rerun parse period of s9e\TextFormatter for all existing posts? #32

Closed n0099 closed 1 year ago

n0099 commented 2 years ago

I've just add site defines for s9e\TextFormatter\Plugins\MediaEmbed in https://github.com/s9e/TextFormatter/pull/181, it's works fine for newly published or edited posts.

But existing link in old posts which stored in database are not wrapped with <SITE></SITE>, so links will not transform to <iframe> by s9e\TextFormatter\Renderer.

I guess the wrapping is done by s9e\TextFormatter\Parser, so I'm wondering how can I re-parse all posts without edit them one by one.

clarkwinkelmann commented 2 years ago

I have been thinking about this for a long time but didn't get a chance to do it so far.

I was thinking of merging extensions like https://github.com/migratetoflarum/recalculate-meta and https://github.com/migratetoflarum/renumber-posts into a single big extension to re-generate everything pre-computed in Flarum.

The basic theory would be a command (ideally for the command line so no issue of timeout) that loops through posts, uses TextFormatter to unparse posts, and then immediately feeds the raw text back through TextFormatter.

The same extension could be used to rename domains in URLs for migrations and other general cleanup/rename operations.

I don't think such a script exists at this time unfortunately.

Without an extension the only solution is indeed to edit every post manually and change at least one character to make Flarum re-compile the post.

JoshyPHP commented 2 years ago

I agree, having a tool that reparses everything is a good idea. I wrote something like that for phpBB and in hindsight, I think that most of the original design decisions described in that post held up. You can check out the live code in phpBB's repository. It's only missing the ability to filter what posts get reparsed based on their content, e.g. only posts that contain <MEDIA or ://. Something that I added later but never got merged.

Anyway, here's a concise list of relevant observations:

  1. You need some kind of plugin system or adapters so you can reparse any type of content agnostically: posts, private messages, other stuff created by extensions. The Symfony container lets services tag themselves for auto-discovery of reparsable content.
  2. Some extensions toggle the state/availability of some features at parsing time (e.g. only X users can do Y) but don't save that state.

If you tag me when you open a new branch for it, I'll keep an eye on it in case I have anything relevant to add.

n0099 commented 1 year ago

I don't think such a script exists at this time unfortunately.

Now we have: https://github.com/club-1/flarum-ext-chore-commands