Skip to content

Commit

Permalink
Merge pull request #107 from buddypress/feature/list-commands
Browse files Browse the repository at this point in the history
Update to all `list` commands
  • Loading branch information
renatonascalves authored Feb 16, 2024
2 parents bab292d + aa73db7 commit 0d325c0
Show file tree
Hide file tree
Showing 22 changed files with 239 additions and 170 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
steps:
- name: Cancel previous runs of this workflow (pull requests only)
if: ${{ github.event_name == 'pull_request' }}
uses: styfle/cancel-workflow-action@0.5.0
uses: styfle/cancel-workflow-action@0.12.0
with:
access_token: ${{ github.token }}

Expand Down
10 changes: 6 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,31 @@ This library adheres to [Semantic Versioning](https://semver.org/) and [Keep a C
* Support for the `--format` flag of the `generate` commands. One can render an output in a particular format.
* New commands:
* `wp bp notice` - Use it to manage Sitewide notices.
* `wp bp tool reinstall` - Alias of the `wp bp email reinstall` command, we will deprecate the latter in the future.
* `delete-comment` and `remove-comment` aliases added for the `wp bp activity` command.

### Changed

* Prefer short array syntax (This is different from WCS supports)
* Composer packages upgraded to their latest versions
* Several linting updates
* CI tests against PHP 8.3 now
* CI tests against PHP 8.3
* Updated deprecated function from `bp_get_group_permalink` into `bp_get_group_url`
* Activity command: make tests more deterministic
* Activity command: made tests more deterministic
* PHPDoc improvements
* All `generate` commands' output were standardized
* All `create` commands' output were standardized
* All `delete` commands' output were standardized
* All `delete` commands' alias were standardized
* All `list` commands were standardized
* Invalid `format` option `haml` removed
* `post-update` command updated to remove mention of default text creation
* `wp bp activity post-update`: removed mention of default text creation
* Removed `user_items` and `items` aliases from the `wp bp activity favorite list` command
* Confirmation message updated for `delete` commands that accepts multiple values
* `wp bp group invite remove` updated to `wp bp group invite uninvite` to avoid conflict with the `delete/remove` command
* `wp bp activity delete_comment` updated to `wp bp activity delete-comment`
* `generate` commands: avoid refetching user objects
* All `generate` command pass the `silent` flag
* Upgraded the `styfle/cancel-workflow-action` Github Action.

## 2.0.2

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"wp bp tool",
"wp bp signup",
"wp bp xprofile",
"wp bp notice",
"wp bp xprofile field",
"wp bp xprofile group",
"wp bp xprofile data",
Expand Down
13 changes: 4 additions & 9 deletions features/group-member.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ Feature: Manage BuddyPress Group Members
Success: Added user #{MEMBER_ID} to group #{GROUP_ID} as member.
"""

When I run `wp bp group member list {GROUP_ID} --fields=user_id`
When I run `wp bp group member list {GROUP_ID} --fields=id`
Then STDOUT should be a table containing rows:
| user_id |
| id |
| {CREATOR_ID} |
| {MEMBER_ID} |

Expand All @@ -40,9 +40,9 @@ Feature: Manage BuddyPress Group Members
Success: Member promoted to new role successfully.
"""

When I run `wp bp group member list {GROUP_ID} --fields=user_id --role=mod`
When I run `wp bp group member list {GROUP_ID} --fields=id --role=mod`
Then STDOUT should be a table containing rows:
| user_id |
| id |
| {MEMBER_ID} |

When I run `wp bp group member demote --group-id={GROUP_ID} --user-id={MEMBER_ID}`
Expand Down Expand Up @@ -79,8 +79,3 @@ Feature: Manage BuddyPress Group Members
"""
Success: Member #{MEMBER_ID} removed from the group #{GROUP_ID}.
"""

When I run `wp bp group member list {GROUP_ID} --fields=user_id --role=member,admin,mod,banned`
Then STDOUT should be a table containing rows:
| user_id |
| {CREATOR_ID} |
1 change: 1 addition & 0 deletions features/message.feature
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Feature: Manage BuddyPress Messages
| sender_id |
| {BOB_ID} |
| {SALLY_ID} |
| {BOB_ID} |

When I run `wp bp message list --user-id={SALLY_ID} --fields=thread_id,sender_id,subject,message`
Then STDOUT should be a table containing rows:
Expand Down
6 changes: 0 additions & 6 deletions features/tool.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,3 @@ Feature: Manage BuddyPress Tools
"""
Success: Signup tool updated.
"""

When I run `wp bp tool reinstall --yes`
Then STDOUT should contain:
"""
Success: Emails have been successfully reinstalled.
"""
4 changes: 1 addition & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

Manage BuddyPress through the command-line.

Quick links: [Installing](#installing) | [Using](#using) | [Support](#support)

## Installing

The `wp-cli-buddypress` comes installed by default with BuddyPress. So if you need to use the latest version, run:
Expand All @@ -12,7 +10,7 @@ The `wp-cli-buddypress` comes installed by default with BuddyPress. So if you ne
wp package install git@github.com:buddypress/wp-cli-buddypress.git
```

In many cases the default memory limit will not be enough to run composer so running the following instead is generally recommended:
In many cases the default memory limit will not be enough to run composer, so running the following instead is generally recommended:

```bash
php -d memory_limit=512M "$(which wp)" package install git@github.com:buddypress/wp-cli-buddypress.git
Expand Down
30 changes: 16 additions & 14 deletions src/activity-favorite.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ public function create( $args ) {

$activity = bp_activity_get_specific(
[
'activity_ids' => $activity_id,
'spam' => null,
'activity_ids' => $activity_id,
'spam' => null,
'display_comments' => true,
]
);

Expand Down Expand Up @@ -127,8 +128,9 @@ public function delete( $args, $assoc_args ) {

$activity = bp_activity_get_specific(
[
'activity_ids' => $activity_id,
'spam' => null,
'activity_ids' => $activity_id,
'spam' => null,
'display_comments' => true,
]
);

Expand Down Expand Up @@ -159,6 +161,12 @@ public function delete( $args, $assoc_args ) {
* [--<field>=<value>]
* : One or more parameters to pass to \BP_Activity_Activity::get()
*
* [--count=<number>]
* : How many activity favorites to list.
* ---
* default: 50
* ---
*
* [--format=<format>]
* : Render output in a particular format.
* ---
Expand All @@ -172,23 +180,15 @@ public function delete( $args, $assoc_args ) {
* - yaml
* ---
*
* [--count=<number>]
* : How many activity favorites to list.
* ---
* default: 50
* ---
*
* ## EXAMPLE
*
* # Get a user's favorite activity items.
* $ wp bp activity favorite list 315
*
* @subcommand list
* @alias items
* @alias user_items
* @alias user-items
*/
public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
public function list_( $args, $assoc_args ) {
$user = $this->get_user_id_from_identifier( $args[0] );
$favorites = bp_activity_get_user_favorites( $user->ID );

Expand All @@ -208,6 +208,8 @@ public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.Metho
WP_CLI::error( 'No favorite found for this user.' );
}

$this->get_formatter( $assoc_args )->display_items( $activities['activities'] );
$activities = $activities['activities'];
$formatter = $this->get_formatter( $assoc_args );
$formatter->display_items( 'ids' === $formatter->format ? wp_list_pluck( $activities, 'id' ) : $activities );
}
}
12 changes: 7 additions & 5 deletions src/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public function create( $args, $assoc_args ) {
*
* @subcommand list
*/
public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
public function list_( $args, $assoc_args ) {
$formatter = $this->get_formatter( $assoc_args );

$r = wp_parse_args(
Expand Down Expand Up @@ -612,11 +612,11 @@ public function ham( $args ) {
* ## EXAMPLES
*
* # Post an activity update.
* $ wp bp activity post_update --user-id=50 --content="Content to update"
* $ wp bp activity post-update --user-id=50 --content="Content to update"
* Success: Successfully updated with a new activity item (ID #13165)
*
* # Post an activity update.
* $ wp bp activity post_update --user-id=140
* $ wp bp activity post-update --user-id=140
* Success: Successfully updated with a new activity item (ID #4548)
*
* @alias post-update
Expand Down Expand Up @@ -774,6 +774,8 @@ protected function get_random_type_from_component( $component ) {
/**
* Generate item details.
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @since 1.1
*
* @param array $r Params.
Expand Down Expand Up @@ -852,7 +854,7 @@ protected function generate_item_details( $r ) {
}

if ( is_multisite() ) {
$r['item-id'] = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} ORDER BY RAND() LIMIT 1" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$r['item-id'] = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} ORDER BY RAND() LIMIT 1" );
} else {
$r['item-id'] = 1;
}
Expand All @@ -864,7 +866,7 @@ protected function generate_item_details( $r ) {
switch_to_blog( $r['item-id'] );
}

$comment_info = $wpdb->get_results( "SELECT comment_id, comment_post_id FROM {$wpdb->comments} ORDER BY RAND() LIMIT 1" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$comment_info = $wpdb->get_results( "SELECT comment_id, comment_post_id FROM {$wpdb->comments} ORDER BY RAND() LIMIT 1" );
$comment_id = $comment_info[0]->comment_id;
$comment = get_comment( $comment_id );

Expand Down
4 changes: 3 additions & 1 deletion src/command.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ protected function get_formatter( &$assoc_args ) {
/**
* Get a random user id.
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @since 1.1
*
* @return int
*/
protected function get_random_user_id() {
global $wpdb;
return $wpdb->get_var( "SELECT ID FROM $wpdb->users ORDER BY RAND() LIMIT 1" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
return (int) $wpdb->get_var( "SELECT ID FROM $wpdb->users ORDER BY RAND() LIMIT 1" );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/components.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public function deactivate( $args ) {
*
* @subcommand list
*/
public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
public function list_( $args, $assoc_args ) {
$formatter = $this->get_formatter( $assoc_args );

// Get type.
Expand Down
4 changes: 2 additions & 2 deletions src/email.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function create( $args, $assoc_args ) {

if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'edit' ) ) {
$input = \WP_CLI\Utils\get_flag_value( $assoc_args, 'content', '' );
$output = $this->_edit( $input, 'WP-CLI: New BP Email Content' );
$output = $this->edit_email( $input, 'WP-CLI: New BP Email Content' );

$assoc_args['content'] = ( $output ) ? $output : $input;
}
Expand Down Expand Up @@ -229,7 +229,7 @@ public function reinstall( $args, $assoc_args ) {
* @param string $title Post title.
* @return mixed
*/
protected function _edit( $content, $title ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
protected function edit_email( $content, $title ) {
$content = apply_filters( 'the_editor_content', $content );
$output = \WP_CLI\Utils\launch_editor_for_input( $content, $title );

Expand Down
28 changes: 20 additions & 8 deletions src/friends.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ public function check( $args ) {
* [--fields=<fields>]
* : Fields to display.
*
* [--count=<number>]
* : How many user's friends to list.
* ---
* default: 50
* ---
*
* [--format=<format>]
* : Render output in a particular format.
* ---
Expand All @@ -272,10 +278,16 @@ public function check( $args ) {
*
* @subcommand list
*/
public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
public function list_( $args, $assoc_args ) {
$formatter = $this->get_formatter( $assoc_args );
$user = $this->get_user_id_from_identifier( $args[0] );
$friends = \BP_Friends_Friendship::get_friendships( $user->ID );
$friends = \BP_Friends_Friendship::get_friendships(
$user->ID,
[
'page' => 1,
'per_page' => $assoc_args['count'],
]
);

if ( empty( $friends ) ) {
WP_CLI::error( 'This member has no friends.' );
Expand All @@ -289,18 +301,18 @@ public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.Metho
*
* ## OPTIONS
*
* [--count=<number>]
* : How many friendships to generate.
* ---
* default: 100
* ---
*
* [--initiator=<user>]
* : ID of the first user. Accepts either a user_login or a numeric ID.
*
* [--friend=<user>]
* : ID of the second user. Accepts either a user_login or a numeric ID.
*
* [--count=<number>]
* : How many friendships to generate.
* ---
* default: 100
* ---
*
* [--format=<format>]
* : Render output in a particular format.
* ---
Expand Down
Loading

0 comments on commit 0d325c0

Please sign in to comment.