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

feat(content-distribution): migrator #185

Merged
merged 40 commits into from
Jan 22, 2025

Conversation

miguelpeixe
Copy link
Member

@miguelpeixe miguelpeixe commented Jan 14, 2025

Implements a migration tool so sites using Distributor can move to our content distribution functionality for posts being distributed within the network.

The migration is done via CLI:

NAME

  wp newspack network distributor migrate

DESCRIPTION

  Migrate posts from Distributor to Newspack Network's content distribution

SYNOPSIS

  wp newspack network distributor migrate [<post-id>] [--batch-size=<batch-size>]
  [--all] [--strict] [--delete]

OPTIONS

  [<post-id>]
    The ID of the post to migrate.

  [--batch-size=<batch-size>]
    Number of posts to migrate in each batch.
    ---
    default: 50
    ---

  [--all]
    Migrate all posts.

  [--strict]
    Whether to only migrate if all distributed posts can be migrated.

  [--delete]
    Whether to deactivate and delete the Distributor plugin after migrating all
    posts. This will only take effect if all posts were able to migrate.

The tool migrates Distributor's subscriptions, using its metadata to create an outgoing post. A data event is dispatched to migrate the incoming posts so this is handled asynchronously. Because of that, it runs in batches of 50.

Testing

  1. In your network setup, make sure you have Distributor configured to all sites in the network
  2. Create a new site, outside the network, and add it to your Distributor connections in order to test an attempt to migrate content distributed to a site outside the network
  3. Publish posts with the following Distributor distribution:
    1. to 1 site within the network
    2. to 1 site outside the network
    3. to 2 sites within the network
    4. to all sites (within and outside the network)
  4. Run the CLI to migrate the first post:
wp newspack network distributor migrate {post_id}
  1. Visit the post origin and confirm the 🌐 panel reflects the correct setup
  2. Confirm the post no longer has "Distributor" settings
  3. Make a change and save
  4. Make sure the network events are synced in all nodes: wp newspack-network sync-all
  5. Confirm the change is distributed via the network's content distribution
  6. Run the CLI to migrate all posts in strict mode:
wp newspack network distributor migrate --all --strict
  1. Confirm no posts were migrated
  2. Run the CLI to migrate all posts:
wp newspack network distributor migrate --all
  1. Confirm that the posts with distribution outside the network were not migrated
  2. For the posts that were able to migrate, repeat steps 5-8 for each post
  3. Delete the posts that are being distributed outside the network and publish a new post distributed, via Distributor, within the network
  4. Run the CLI again, but now flagging the plugin deletion:
wp newspack network distributor migrate --all --delete
  1. Confirm the plugin has been deleted after the migration

@miguelpeixe miguelpeixe changed the base branch from trunk to fix/content-distribution-site-hash January 15, 2025 12:51
Base automatically changed from fix/content-distribution-site-hash to trunk January 15, 2025 20:42
@miguelpeixe miguelpeixe marked this pull request as ready for review January 16, 2025 18:59
@miguelpeixe miguelpeixe requested a review from a team as a code owner January 16, 2025 18:59
@miguelpeixe miguelpeixe self-assigned this Jan 16, 2025
@miguelpeixe miguelpeixe requested review from naxoc and leogermani and removed request for a team January 16, 2025 18:59
@miguelpeixe miguelpeixe marked this pull request as draft January 17, 2025 21:42
Copy link
Member

@naxoc naxoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a couple of smaller things in code – will do a test next, but m not sure I entirely get step 3.

Are these assumptions correct?

Let's say I have hub.test, node1.test, node2.test, node3.test.
hub, node1, and node2 are networked (content distribution enabled). node3 is not. All sites have distributor enabled and are networked.

  • to 1 site within the network - so post on hub and distribute to node1?
  • to 1 site outside the network - so post on hub and distribute to node3?
  • to 2 sites within the network - so post on hub and distribute to node1 and node2?
  • to all sites (within and outside the network) - so post on hub and distribute to node1, node2, and node3? (I guess this one is not so hard to understand).

Am I right about the above?

@miguelpeixe
Copy link
Member Author

Thanks for the review, @naxoc!

Am I right about the above?

Yes, that's the setup for testing.

A few things were missing to handle the incoming posts migration, which have been implemented in 1d5f4d1 and improved logging was also added in 6f7af2c

@miguelpeixe miguelpeixe requested a review from naxoc January 21, 2025 13:44
Copy link
Member

@naxoc naxoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 🎉

I ran through the testing scenario and it works like a charm now.

@miguelpeixe miguelpeixe merged commit 06ec18a into trunk Jan 22, 2025
4 checks passed
@miguelpeixe miguelpeixe deleted the feat/content-distribution-migrator branch January 22, 2025 18:45
Copy link

Hey @miguelpeixe, good job getting this PR merged! 🎉

Now, the needs-changelog label has been added to it.

Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label.

If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label.

Thank you! ❤️

matticbot pushed a commit that referenced this pull request Jan 23, 2025
# [2.5.0-alpha.1](v2.4.0...v2.5.0-alpha.1) (2025-01-23)

### Bug Fixes

* **content-distribution:** block additional UI components ([#197](#197)) ([3f30cdb](3f30cdb))
* **content-distribution:** handling multiple post meta ([#199](#199)) ([c93084d](c93084d))
* **content-distribution:** Improve CSS for blocked editor ([#193](#193)) ([295bdad](295bdad)), closes [#181](#181)
* **content-distribution:** persist site hash ([#186](#186)) ([120b759](120b759))
* **content-distribution:** prevent consecutive dispatches ([#198](#198)) ([2149a62](2149a62))
* **content-distribution:** refactor outgoing post js ([#188](#188)) ([cc08edc](cc08edc))
* **memberships:** remove managed fields on cancel or expire ([#192](#192)) ([67a5cf0](67a5cf0))

### Features

* **content-distribution:** Block the editor for incoming posts ([#181](#181)) ([48b4cae](48b4cae))
* **content-distribution:** confirm dialog for unlinking and relinking posts ([#190](#190)) ([f36bb28](f36bb28))
* **content-distribution:** migrator ([#185](#185)) ([06ec18a](06ec18a))
* **content-distribution:** post status on create ([#189](#189)) ([1ad3e0c](1ad3e0c))
* sync multiple user roles ([#187](#187)) ([9fa833c](9fa833c))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 2.5.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants