Skip to content

Conversation

@naxoc
Copy link
Member

@naxoc naxoc commented Dec 9, 2024

This adds a CLI command to distribute a post.

I added support for passing 'all' or a list of urls to the --sites param, but not site_ids. The original task was —sites(all|site_ids|site_urls). Is the site ids thing necessary? I feel like it might introduce more error than convenience. I'm happy to add it if we have a use case that makes sense.

I didn't add tests because it doesn't make much sense to test CLI commands that just calls code that has tests.

This one relies on #164 being merged for sync to work.

How to test

# Create a post on the hub:
wp post create --post_content="Oh, wow" --post_status=publish --post_title="I'll go places from $(wp option get blogname)"
# Grab the ID and call this:
wp newspack network distribute post <post-id> --sites=https://node1.test
# Check that the post shows up.

# Now do it again with one more site to test the adding of sites:
wp newspack network distribute post <post-id> --sites=https://node2.test

# Create another post and test with 'all'
wp newspack network distribute post <post-id> --sites=all

# Now find a page ID and run the below. It should throw an error
wp newspack network distribute post <page-id> --sites=https://google.com

miguelpeixe and others added 23 commits November 28, 2024 12:24
* feat: content distribution class

* feat: insert linked post

* refactor: use site url instead of ID

* chore: lint

* feat: return errors on post insert

* chore: lint

* feat: support webhooks request priority

* feat: unlink functionality and unit tests

* chore: lint

* feat: introduce 'linked_post_inserted' hook and listener

* chore: lint

* fix: listener hook name

* fix: typo

* chore: better docblocks

* chore: remove redundant code

* test: persist post hash

* test: remove unnecessary assertion

* refactor: distribute_post() to use handle_post_updated() method

* refactor: post hash is now network post id

* chore: update comment
@naxoc naxoc requested a review from a team as a code owner December 9, 2024 12:04
@naxoc naxoc changed the base branch from trunk to epic/content-distribution December 9, 2024 12:05
@naxoc naxoc self-assigned this Dec 10, 2024
Base automatically changed from epic/content-distribution to trunk December 12, 2024 13:00
@naxoc
Copy link
Member Author

naxoc commented Dec 12, 2024

OK, @miguelpeixe – I had to update the test a bit with some mockery, but I think this is ready for re-review.

Note that the set_config() now returns the config – I use it to write a message to the CLI. Let me know if that makes no sense.

@naxoc naxoc requested a review from miguelpeixe December 12, 2024 15:44
Copy link
Member

@miguelpeixe miguelpeixe left a comment

Choose a reason for hiding this comment

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

That's perfect! Thank you for all the revisions 🎉

One nitpicky thing below

Comment on lines +100 to +102
// If there are urls not already in the config, add them. Note that we don't support
// removing urls from the config.
$config['site_urls'] = array_unique( array_merge( $config['site_urls'], $site_urls ) );
Copy link
Member

Choose a reason for hiding this comment

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

Can we unit test this new thing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep! I added a test 👍

@naxoc naxoc changed the title feat: add CLI command for distribute post feat(content-distribution): add CLI command for distribute post Dec 12, 2024
@naxoc naxoc merged commit 7a43b86 into trunk Dec 12, 2024
@github-actions
Copy link

Hey @naxoc, 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 10, 2025
# [2.4.0-alpha.1](v2.3.4...v2.4.0-alpha.1) (2025-01-10)

### Bug Fixes

* **content-distribution:** post insertion hook and additional meta for incoming post event ([#173](#173)) ([48df13c](48df13c))
* load text domain on init hook ([#171](#171)) ([01fb89c](01fb89c))

### Features

* content distribution - experimental ([#168](#168)) ([dc837d8](dc837d8))
* **content-distribution:** add CLI command for distribute post ([#159](#159)) ([7a43b86](7a43b86)), closes [#155](#155) [#156](#156) [#157](#157) [#160](#160) [#165](#165)
* **content-distribution:** canonical url ([#177](#177)) ([5ca60ce](5ca60ce))
* **content-distribution:** capability and admin page ([#176](#176)) ([5285285](5285285))
* **content-distribution:** control distribution meta and prevent multiple dispatches ([#170](#170)) ([e76a2dc](e76a2dc))
* **content-distribution:** editor plugin for distribution ([#167](#167)) ([e10aef4](e10aef4))
* **content-distribution:** handle status changes ([#166](#166)) ([4af5da1](4af5da1))
* **content-distribution:** log incoming post errors ([#182](#182)) ([74c9119](74c9119))
* **content-distribution:** posts column ([#178](#178)) ([8e07640](8e07640))
* **content-distribution:** reserved taxonomies ([#174](#174)) ([a2c54d2](a2c54d2))
* **content-distribution:** sync comment and ping statuses ([#179](#179)) ([90c5425](90c5425))
* **content-distribution:** sync post meta ([#163](#163)) ([353a3d8](353a3d8))
* **event-log:** collapse data ([#180](#180)) ([956219d](956219d))
* limit purchase of a network membership ([#169](#169)) ([deb2683](deb2683))
@matticbot
Copy link
Contributor

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

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Jan 20, 2025
# [2.4.0](v2.3.4...v2.4.0) (2025-01-20)

### Bug Fixes

* **content-distribution:** post insertion hook and additional meta for incoming post event ([#173](#173)) ([48df13c](48df13c))
* load text domain on init hook ([#171](#171)) ([01fb89c](01fb89c))

### Features

* content distribution - experimental ([#168](#168)) ([dc837d8](dc837d8))
* **content-distribution:** add CLI command for distribute post ([#159](#159)) ([7a43b86](7a43b86)), closes [#155](#155) [#156](#156) [#157](#157) [#160](#160) [#165](#165)
* **content-distribution:** canonical url ([#177](#177)) ([5ca60ce](5ca60ce))
* **content-distribution:** capability and admin page ([#176](#176)) ([5285285](5285285))
* **content-distribution:** control distribution meta and prevent multiple dispatches ([#170](#170)) ([e76a2dc](e76a2dc))
* **content-distribution:** editor plugin for distribution ([#167](#167)) ([e10aef4](e10aef4))
* **content-distribution:** handle status changes ([#166](#166)) ([4af5da1](4af5da1))
* **content-distribution:** log incoming post errors ([#182](#182)) ([74c9119](74c9119))
* **content-distribution:** posts column ([#178](#178)) ([8e07640](8e07640))
* **content-distribution:** reserved taxonomies ([#174](#174)) ([a2c54d2](a2c54d2))
* **content-distribution:** sync comment and ping statuses ([#179](#179)) ([90c5425](90c5425))
* **content-distribution:** sync post meta ([#163](#163)) ([353a3d8](353a3d8))
* **event-log:** collapse data ([#180](#180)) ([956219d](956219d))
* limit purchase of a network membership ([#169](#169)) ([deb2683](deb2683))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 2.4.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@adekbadek adekbadek deleted the feat/distribute-post-cli branch August 28, 2025 07:16
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.

5 participants