Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bulk conversion #56

Closed
jeffpaul opened this issue Nov 16, 2021 · 5 comments · Fixed by #70
Closed

Bulk conversion #56

jeffpaul opened this issue Nov 16, 2021 · 5 comments · Fixed by #70
Assignees
Labels
help wanted Extra attention is needed type:enhancement New feature or request.
Milestone

Comments

@jeffpaul
Copy link
Member

Is your enhancement related to a problem? Please describe.
As noted on Twitter (and in a couple other dotorg/etc. places), some folks are requesting the ability to bulk convert posts vs. the one-at-a-time approach that C2B was built for.

It works wonderfully, but there's no bulk conversion option. Anyone with more than a few hundred posts has got a ton of manual work ahead of them. CLI is always preferred (over a Bulk Edit dropdown on the All Posts table list view).

Is there a way to to this function in bulk without having to open every single post?

Describe the solution you'd like
Initial approach is probably a CLI command as that limits the use to more technical users who we can gain initial feedback from before considering whether to expose this in a Bulk Edit dropdown option or not.

Designs
The CLI command could default to all posts in a specified post type, but accept a list or range of IDs to convert as an option? Open to how we might structure the commend / input / output.

Describe alternatives you've considered

Additional context

@jeffpaul jeffpaul added type:enhancement New feature or request. help wanted Extra attention is needed labels Nov 16, 2021
@jeffpaul jeffpaul added this to the Future Release milestone Nov 16, 2021
@jeffpaul jeffpaul moved this to Incoming in Open Source Practice Nov 16, 2021
@jeffpaul jeffpaul moved this from Incoming to Backlog in Open Source Practice Nov 16, 2021
@ActuallyConnor
Copy link

What are the functions to call to convert a post to block?

@dsawardekar
Copy link
Collaborator

@ActuallyConnor Most of the transformation happens client-side in the Browser. This makes a WP CLI based solution difficult, as it has to match all the core & custom raw handling api's on the backend.

One way we have gotten around this limitation is by building a Puppeteer (or similar) script. The script works like this,

  1. Load the Block Editor screen in the Admin (/wp-admin/post.php?post=N)
  2. Wait for the Block Editor to finish transforming the classic editor blocks. (a second or two)
  3. Hit the Update button to save the post to the BE.
  4. Repeat for other post ids.

Hope that helps.

@conatus
Copy link

conatus commented Dec 9, 2021

Hello all!

Really impressed with this plugin so far and the "just in time" approach is a nice one. I also think batch processing would be really useful (for our use-case) and for that of the wider community.

However, as @dsawardekar notes, this spends on using client side code, in particular, looping over all the blocks on the page (after conversion) and running rawHandler over them, which is the set of transformations applied here - https://github.com/WordPress/gutenberg/tree/trunk/packages/blocks/src/api/raw-handling

Obviously you can run Javascript without a browser, but looking through this code in Gutenberg, a great deal depends on the browser environment existing.

What one is tempted to do here is write an application in Javascript that queries the WordPress database and then uses these transformations directly on the HTML (if possible) then saves the results back out. This seems to break some pretty fundamental assumptions of this project, for example, that it is in PHP, with client-side Javascript.

Another approach would be to port a sub-set of these transformations to PHP. You could even use a PHP DOM manipulation library to port the code more quickly - handling the insertion of Gutenberg comments and so on.

I am not sure of the best way forward here, so would welcome everyone in the community throwing around ideas. Happy to try some experiments out and see how far we get!

@conatus
Copy link

conatus commented Dec 9, 2021

Note this is also how the relatively popular Bulk Block Converter also operates, except this runs this using the WordPress API rather than loading it on the editor page.

https://github.com/ZamanehMedia/vo-bulk-block-converter/blob/f2aa48e5e9d4185cdd70fc8bc3b9c938beb3be8b/js/scripts.js#L166-L172

@conatus
Copy link

conatus commented Dec 14, 2021

Also the way in which this plugin from Automattic works, though how the PHP elements operate isn't clear to me.

Automattic/newspack-content-converter#97

@jeffpaul jeffpaul moved this from Backlog to To Do in Open Source Practice Dec 22, 2021
@mehulkaklotar mehulkaklotar self-assigned this Jan 5, 2022
@mehulkaklotar mehulkaklotar moved this from To Do to In Progress in Open Source Practice Jan 6, 2022
@jeffpaul jeffpaul modified the milestones: Future Release, 1.1.0 Jun 24, 2022
Repository owner moved this from In Progress to Merged in Open Source Practice Jul 8, 2022
@vikrampm1 vikrampm1 moved this from Merged to Done/Released in Open Source Practice Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed type:enhancement New feature or request.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants