Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:10up/convert-to-blocks into feat…
Browse files Browse the repository at this point in the history
…ure/58-settings-ui
  • Loading branch information
Sidsector9 committed Jan 5, 2023
2 parents d33e248 + fc8f1ac commit 83d5399
Show file tree
Hide file tree
Showing 21 changed files with 3,222 additions and 5,267 deletions.
2 changes: 2 additions & 0 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
/.git
/.github
/.wordpress-org
/assets
/bin
/config
/node_modules
/tests

Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/build-release-zip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Build release zip

on:
workflow_dispatch:
push:
branches:
- trunk

jobs:
build:
name: Build release zip
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}

- name: Setup node version and npm cache
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'npm'

- name: Install Node dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --no-optional

- name: Build plugin
run: npm run build

- name: Generate ZIP file
uses: 10up/action-wordpress-plugin-build-zip@stable
30 changes: 30 additions & 0 deletions .github/workflows/no-response.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: No Response

# **What it does**: Closes issues where the original author doesn't respond to a request for information.
# **Why we have it**: To remove the need for maintainers to remember to check back on issues periodically to see if contributors have responded.
# **Who does it impact**: Everyone that works on docs or docs-internal.

on:
issue_comment:
types: [created]
schedule:
# Schedule for five minutes after the hour, every hour
- cron: '5 * * * *'

jobs:
noResponse:
runs-on: ubuntu-latest
steps:
- uses: lee-dohm/no-response@v0.5.0
with:
token: ${{ github.token }}
daysUntilClose: 14 # Number of days of inactivity before an Issue is closed for lack of response
responseRequiredLabel: "needs:feedback" # Label indicating that a response from the original author is required
closeComment: >
This issue has been automatically closed because there has been no response
to our request for more information. With only the
information that is currently in the issue, we don't have enough information
to take action. Please reach out if you have or find the answers we need so
that we can investigate further. See [this blog post on bug reports and the
importance of repro steps](https://www.lee-dohm.com/2015/01/04/writing-good-bug-reports/)
for more information about the kind of information that may be helpful.
20 changes: 20 additions & 0 deletions .github/workflows/wordpress-latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "WordPress version checker"
on:
push:
branches:
- develop
- trunk
pull_request:
branches:
- develop
schedule:
- cron: '0 0 * * 1'

jobs:
wordpress-version-checker:
runs-on: ubuntu-latest
steps:
- name: WordPress version checker
uses: skaut/wordpress-version-checker@v1.2.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
Binary file added .wordpress-org/screenshot-1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file, per [the Ke

## [Unreleased] - TBD

## [1.1.0] - 2022-07-28
### Added
- Support for bulk migrating Classic Editor items to the Block Editor, utilizing WP-CLI (props [@dsawardekar](https://github.com/dsawardekar), [@jeffpaul](https://github.com/jeffpaul), [@gthayer](https://github.com/gthayer), [@faisal-alvi](https://github.com/faisal-alvi) via [#70](https://github.com/10up/convert-to-blocks/pull/70)).
- Dependency security scanning (props [@jeffpaul](https://github.com/jeffpaul), [@Sidsector9](https://github.com/Sidsector9) via [#64](https://github.com/10up/convert-to-blocks/pull/64)).

### Fixed
- Added polyfill to fix PHPUnit tests (props [@cadic](https://github.com/cadic), [@iamdharmesh](https://github.com/iamdharmesh) via [#69](https://github.com/10up/convert-to-blocks/pull/69)).

### Changed
- Bump WordPress version "tested up to" 6.0 (props [@mohitwp](https://github.com/mohitwp), [@jeffpaul](https://github.com/jeffpaul), [@cadic](https://github.com/cadic), [@iamdharmesh](https://github.com/iamdharmesh) via [#59](https://github.com/10up/convert-to-blocks/pull/59), [#67](https://github.com/10up/convert-to-blocks/pull/67)).

### Security
- Bump `path-parse` from 1.0.6 to 1.0.7 (props [@dependabot](https://github.com/apps/dependabot) via [#55](https://github.com/10up/convert-to-blocks/pull/55)).
- Bump `ajv` from 6.10.0 to 6.12.6 (props [@dependabot](https://github.com/apps/dependabot) via [#60](https://github.com/10up/convert-to-blocks/pull/60)).
- Bump `tar` from 4.4.8 to 4.4.19 (props [@dependabot](https://github.com/apps/dependabot) via [#61](https://github.com/10up/convert-to-blocks/pull/61)).
- Bump `terser` from 4.6.0 to 4.8.1 (props [@dependabot](https://github.com/apps/dependabot) via [#74](https://github.com/10up/convert-to-blocks/pull/74)).

## [1.0.2] - 2021-07-12
### Changed
- Bump WordPress version "tested up to" 5.8 (props [@psorensen](https://github.com/psorensen), [@BBerg10up](https://github.com/BBerg10up), [@jeffpaul](https://github.com/jeffpaul) via [#47](https://github.com/10up/convert-to-blocks/pull/47), [#50](https://github.com/10up/convert-to-blocks/pull/50)).
Expand Down Expand Up @@ -44,6 +61,7 @@ All notable changes to this project will be documented in this file, per [the Ke
- Initial release of Convert to Blocks.

[Unreleased]: https://github.com/10up/convert-to-blocks/compare/trunk...develop
[1.1.0]: https://github.com/10up/convert-to-blocks/compare/1.0.2...1.1.0
[1.0.2]: https://github.com/10up/convert-to-blocks/compare/1.0.1...1.0.2
[1.0.1]: https://github.com/10up/convert-to-blocks/compare/cf8c873...1.0.1
[1.0.0]: https://github.com/10up/convert-to-blocks/tree/cf8c873ae4f88286723f6e996fbab4c1f8cf2940
6 changes: 4 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ The `develop` branch is the development branch which means it contains the next
## Release instructions

1. Branch: Starting from `develop`, cut a release branch named `release/X.Y.Z` for your changes.
1. Version bump: Bump the version number in `config.php`, `convert-to-blocks.php`, `readme.txt`, and `package.json` if it does not already reflect the version being released. Update both the plugin "Version:" property in `convert-to-blocks.php` and the plugin `$plugin_version` constant in `config.php`.
1. Version bump: Bump the version number in `config.php`, `convert-to-blocks.php`, `readme.txt`, `package.json` and `package-lock.json` if it does not already reflect the version being released. Update both the plugin "Version:" property in `convert-to-blocks.php` and the plugin `$plugin_version` constant in `config.php`.
1. Changelog: Add/update the changelog in `CHANGELOG.md` and `readme.txt`.
1. Props: update `CREDITS.md` with any new contributors, confirm maintainers are accurate.
1. New files: Check to be sure any new files/paths that are unnecessary in the production version are included in `.distignore`.
1. Readme updates: Make any other readme changes as necessary. `README.md` is geared toward GitHub and `readme.txt` contains WordPress.org-specific content. The two are slightly different.
1. Merge: Make a non-fast-forward merge from your release branch to `develop` (or merge the pull request), then do the same for `develop` into `trunk` (`git checkout trunk && git merge --no-ff develop`). `trunk` contains the stable development version.
1. Merge: Make a non-fast-forward merge from your release branch to `develop` (or merge the pull request), then do the same for `develop` into `trunk`, ensuring you pull the most recent changes into `develop` first (`git checkout develop && git pull origin develop && git checkout trunk && git merge --no-ff develop`). `trunk` contains the stable development version.
1. Push: Push your `trunk` branch to GitHub (e.g. `git push origin trunk`).
1. [Compare](https://github.com/10up/convert-to-blocks/compare/trunk...develop) trunk to develop to ensure no additional changes were missed.
1. Test the pre-release ZIP locally by [downloading](https://github.com/10up/convert-to-blocks/actions/workflows/build-release-zip.yml) it from the Build release zip action artifact and installing it locally. Ensure this zip has all the files we expect, that it installs and activates correctly and that all basic functionality is working
1. Release: Create a [new release](https://github.com/10up/convert-to-blocks/releases/new), naming the tag and the release with the new version number, and targeting the `trunk` branch. Paste the changelog from `CHANGELOG.md` into the body of the release and include a link to the [closed issues on the milestone](https://github.com/10up/convert-to-blocks/milestone/#?closed=1). The release should now appear under [releases](https://github.com/10up/convert-to-blocks/releases).
1. SVN: Wait for the [GitHub Action](https://github.com/10up/convert-to-blocks/actions) to finish deploying to the WordPress.org repository. If all goes well, users with SVN commit access for that plugin will receive an emailed diff of changes.
1. Check WordPress.org: Ensure that the changes are live on https://wordpress.org/plugins/convert-to-blocks/. This may take a few minutes.
Expand Down
2 changes: 1 addition & 1 deletion CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The following individuals are responsible for curating the list of issues, respo

Thank you to all the people who have already contributed to this repository via bug reports, code, design, ideas, project management, translation, testing, etc.

[Darshan Sawardekar (@dsawardekar)](https://github.com/dsawardekar), [Taylor Lovett (@tlovett1)](https://github.com/tlovett1), [Tyler Bailey (@TylerB24890)](https://github.com/TylerB24890), [Jeffrey Paul (@jeffpaul)](https://github.com/jeffpaul), [Tung Du (@dinhtungdu)](https://github.com/dinhtungdu), [Diana Padron](https://profiles.wordpress.org/dianapadron), [Barry Ceelen (@barryceelen)](https://github.com/barryceelen), [Darin Kotter (@dkotter)](https://github.com/dkotter), [Peter Sorensen (@psorensen)](https://github.com/psorensen), [Brandon Berg (@BBerg10up)](https://github.com/BBerg10up), [Hashim Warren (@hashimwarren)](https://github.com/hashimwarren), [Jason LeMahieu (@MadtownLems)](https://github.com/MadtownLems), [Simon Carne](https://profiles.wordpress.org/scarne/), [Rodrigo Arias (@rodrigo-arias)](https://github.com/rodrigo-arias).
[Darshan Sawardekar (@dsawardekar)](https://github.com/dsawardekar), [Taylor Lovett (@tlovett1)](https://github.com/tlovett1), [Tyler Bailey (@TylerB24890)](https://github.com/TylerB24890), [Jeffrey Paul (@jeffpaul)](https://github.com/jeffpaul), [Tung Du (@dinhtungdu)](https://github.com/dinhtungdu), [Diana Padron](https://profiles.wordpress.org/dianapadron), [Barry Ceelen (@barryceelen)](https://github.com/barryceelen), [Darin Kotter (@dkotter)](https://github.com/dkotter), [Peter Sorensen (@psorensen)](https://github.com/psorensen), [Brandon Berg (@BBerg10up)](https://github.com/BBerg10up), [Hashim Warren (@hashimwarren)](https://github.com/hashimwarren), [Jason LeMahieu (@MadtownLems)](https://github.com/MadtownLems), [Simon Carne](https://profiles.wordpress.org/scarne/), [Rodrigo Arias (@rodrigo-arias)](https://github.com/rodrigo-arias), [Gary Thayer (@gthayer)](https://github.com/gthayer), [Faisal Alvi (@faisal-alvi)](https://github.com/faisal-alvi), [Siddharth Thevaril (@Sidsector9)](https://github.com/Sidsector9), [Max Lyuchin (@cadic)](https://github.com/cadic), [Dharmesh Patel (@iamdharmesh)](https://github.com/iamdharmesh), [Mohit Dadhich (@mohitwp)](https://github.com/mohitwp), [GitHub Dependabot (@dependabot)](https://github.com/apps/dependabot).

## Libraries

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

Convert to Blocks is a WordPress plugin that transforms classic editor content to blocks on-the-fly. After installing Gutenberg or upgrading to WordPress 5.0+, your content will be displayed in "Classic Editor Blocks". While these blocks are completely functional and will display fine on the frontend of your website, they do not empower editors to fully make use of the block editing experience. In order to do so, your classic editor posts need to be converted to blocks. This plugin does that for you "on the fly". When an editor goes to edit a classic post, the content will be parsed into blocks. When the editor saves the post, the new structure will be saved into the database. This strategy reduces risk as you are only altering database values for content that needs to be changed.

### Bulk migration of Classic Editor items to the Block Editor

The `wp convert-to-blocks start` [WP-CLI command](https://github.com/10up/convert-to-blocks/blob/4df0e970c51eee8d84e3edf3c6210dc10011d574/includes/ConvertToBlocks/MigrationCommand.php) that converts posts iteratively in the browser without requiring any manual input. One caveat worth mentioning is that Gutenberg is a CPU intensive application. You will want to keep your computer plugged in before doing this!

![Demo of WP-CLI command](.wordpress-org/screenshot-1.gif "Example of a convert-to-blocks WP-CLI command bulk migration")

## Requirements

* PHP 7.0+
Expand Down
52 changes: 42 additions & 10 deletions assets/js/editor/editor.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import ClassicBlockTransformer from './transform/ClassicBlockTransformer';
import MigrationClient from './transform/MigrationClient';

let loaded = false;

/**
* ConnectToBlocksSupport connects the JS implementation of
* Connect to Blocks to Gutenberg JS.
* ConvertToBlocksSupport connects the JS implementation of
* Convert to Blocks to Gutenberg JS.
*/
class ConnectToBlocksEditorSupport {
class ConvertToBlocksEditorSupport {
/**
* Returns the singleton instance of ConnectToBlocksEditorSupport.
* Returns the singleton instance of ConvertToBlocksEditorSupport.
*
* @returns {ConnectToBlocksEditorSupport}
* @returns {ConvertToBlocksEditorSupport}
*/
static getInstance() {
if (!this.instance) {
this.instance = new ConnectToBlocksEditorSupport();
this.instance = new ConvertToBlocksEditorSupport();
}

return this.instance;
}

/**
* Activates the ConnectToBlocksEditorSupport
* Activates the ConvertToBlocksEditorSupport
*/
enable() {
document.addEventListener('DOMContentLoaded', this.didBlockEditorLoad.bind(this));
Expand All @@ -38,14 +41,43 @@ class ConnectToBlocksEditorSupport {

registerPlugin('convert-to-blocks', {
render: () => {
transformer.execute();
// Don't render more than once, to avoid triggering multiple migrations
if (loaded) {
return null;
}

loaded = true;

// This delay allows Gutenberg to initialize legacy content into freeform blocks
setTimeout(() => {
const result = transformer.execute();
const config = window.convert_to_blocks_agent || false;

// if no migration config, then ignore this request
if (!config) {
return null;
}

const client = new MigrationClient(config);

// if no blocks transformed, then we can jump to the next post
if (!result) {
client.next();
return null;
}

client.save();

return null;
}, 500);

return null;
},
});
}
}

const support = ConnectToBlocksEditorSupport.getInstance();
const support = ConvertToBlocksEditorSupport.getInstance();
support.enable();

export default ConnectToBlocksEditorSupport;
export default ConvertToBlocksEditorSupport;
7 changes: 7 additions & 0 deletions assets/js/editor/transform/ClassicBlockTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ class ClassicBlockTransformer {
*/
constructor() {
this.wp = window.wp;
this.didTransform = false;
}

/**
* Runs the Classic to Gutenberg Block transform on the current document.
*
* @returns {boolean} The result of the transformation.
*/
execute() {
const coreEditor = this.wp.data.select('core/block-editor');
Expand All @@ -23,6 +26,8 @@ class ClassicBlockTransformer {
/* Currently set to do 3 levels of recursion */
this.convertBlocks(blocks, 1, 3);
}

return this.didTransform;
}

/**
Expand Down Expand Up @@ -65,6 +70,8 @@ class ClassicBlockTransformer {
this.wp.data
.dispatch('core/block-editor')
.replaceBlocks(block.clientId, this.blockHandler(block));

this.didTransform = true;
} else if (block.innerBlocks && block.innerBlocks.length > 0) {
this.convertBlocks(block.innerBlocks);
}
Expand Down
104 changes: 104 additions & 0 deletions assets/js/editor/transform/MigrationClient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
const { wp, location } = window;

/**
* MigrationClient provides the client-side support for the BE MigrationAgent.
*/
class MigrationClient {
/**
* Initializes the client with the specified config settings.
*
* @param {object} config The convert to blocks config
*/
constructor(config) {
this.config = config;
this.saved = false;
this.didNext = false;
}

/**
* Saves the curent post by manually dispatching savePost.
*/
save() {
// don't rerun after save
if (this.saved) {
return;
}

this.saved = true;

const { dispatch, subscribe } = wp.data;
const editor = dispatch('core/editor');

subscribe(this.didSave.bind(this));
editor.savePost();
}

/**
* On Post save, runs the next post migration.
*/
didSave() {
const { select } = wp.data;
const isSavingPost = select('core/editor').isSavingPost();
const isAutosavingPost = select('core/editor').isAutosavingPost();

if (isAutosavingPost && !isSavingPost) {
return;
}

if (this.hasNext()) {
this.next();
}
}

/**
* Checks if there is a post in the queue.
*
* @returns {boolean} True or false if next is present.
*/
hasNext() {
if (this.didNext) {
return false;
}

if (!this.hasNextConfig()) {
return false;
}

return this.config.agent.next;
}

/**
* Navigates to the next post to migrate.
*/
next() {
if (!this.hasNextConfig()) {
return;
}

this.didNext = true;
location.href = this.config.agent.next;
}

/**
* Checks if the next migration post data is present in config.
*
* @returns {boolean} True or false if next config is present
*/
hasNextConfig() {
if (!this.config) {
return false;
}

if (!this.config.agent) {
return false;
}

if (!this.config.agent.next) {
return false;
}

return true;
}
}

export default MigrationClient;
Loading

0 comments on commit 83d5399

Please sign in to comment.