Skip to content

Commit

Permalink
More tweaks and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
renatonascalves committed Feb 6, 2024
1 parent e0a3293 commit 3d4c2e2
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This library adheres to [Semantic Versioning](https://semver.org/) and [Keep a C
* Misc linting updates
* Github Action: Testing against PHP 8.3
* Updated deprecated function from `bp_get_group_permalink` into `bp_get_group_url`
* Activity: make tests more deterministic

## 2.0.2

Expand Down
2 changes: 1 addition & 1 deletion features/activity-meta.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ Feature: Manage BuddyPress Activity custom fields
"""

When I try `wp bp activity meta get 999999 foo`
Then the return code should be 1
Then STDERR should be:
"""
Error: Could not find the activity with ID 999999.
"""
And the return code should be 1

When I run `wp bp activity meta set {ACTIVITY_ID} foo '[ "1", "2" ]' --format=json`
Then STDOUT should not be empty
Expand Down
2 changes: 1 addition & 1 deletion features/activity.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Feature: Manage BuddyPress Activities
Then STDOUT should be a number
And save STDOUT as {MEMBER_ID}

When I run `wp bp activity create --porcelain`
When I run `wp bp activity create --component=activity --porcelain`
Then STDOUT should be a number
And save STDOUT as {ACTIVITY_ID}

Expand Down
2 changes: 1 addition & 1 deletion features/component.feature
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ Feature: Manage BuddyPress Components
| core |

When I try `wp bp component list --type=retired`
Then the return code should be 1
Then STDERR should be:
"""
Error: There is no component available.
"""
And the return code should be 1

When I run `wp bp component activate groups`
Then STDOUT should contain:
Expand Down
2 changes: 1 addition & 1 deletion features/group-meta.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Feature: Manage BuddyPress Group custom fields
"""

When I try `wp bp group meta get 999999 foo`
Then the return code should be 1
Then STDERR should be:
"""
Error: Could not find the group with ID 999999.
"""
And the return code should be 1

When I run `wp bp group meta set {GROUP_ID} foo '[ "1", "2" ]' --format=json`
Then STDOUT should not be empty
Expand Down
46 changes: 42 additions & 4 deletions features/sitewide-notice.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ Feature: Manage BuddyPress Site Notices
Then STDOUT should be a number
And save STDOUT as {NOTICE_ID}

When I run `wp bp notice deactivate {NOTICE_ID}`
Then STDOUT should contain:
"""
Success: Sitewide notice has been deactivated.
"""

When I run `wp bp notice activate {NOTICE_ID}`
Then STDOUT should contain:
"""
Success: Sitewide notice activated.
"""

When I run `wp bp notice get {NOTICE_ID} --fields=id,subject,message`
Then STDOUT should be a table containing rows:
| Field | Value |
Expand All @@ -37,15 +49,41 @@ Feature: Manage BuddyPress Site Notices
Then STDOUT should be a number
And save STDOUT as {NOTICE_TWO_ID}

When I run `wp bp notice list --fields=id,subject,message`
When I run `wp bp notice list --fields=id,subject,message,is_active`
Then STDOUT should be a table containing rows:
| id | subject | message | is_active |
| {NOTICE_ONE_ID} | Test | Content | 0 |
| {NOTICE_TWO_ID} | Test 2 | Content 2 | 1 |

When I try `wp bp notice activate 999999`
Then the return code should be 1
Then STDERR should be:
"""
Error: No sitewide notice found by that ID.
"""

When I run `wp bp notice activate {NOTICE_ONE_ID}`
Then STDOUT should contain:
"""
Success: Sitewide notice activated.
"""

When I run `wp bp notice list --fields=id,subject,message,is_active`
Then STDOUT should be a table containing rows:
| id | subject | message |
| {NOTICE_ONE_ID} | Test | Content |
| {NOTICE_TWO_ID} | Test 2 | Content 2 |
| id | subject | message | is_active |
| {NOTICE_ONE_ID} | Test | Content | 1 |
| {NOTICE_TWO_ID} | Test 2 | Content 2 | 0 |

When I run `wp bp notice delete {NOTICE_ONE_ID} {NOTICE_TWO_ID} --yes`
Then STDOUT should contain:
"""
Success: Sitewide notice deleted {NOTICE_ONE_ID}.
Success: Sitewide notice deleted {NOTICE_TWO_ID}.
"""

When I try `wp bp notice deactivate 999999`
Then the return code should be 1
Then STDERR should be:
"""
Error: No sitewide notice found by that ID.
"""
4 changes: 2 additions & 2 deletions features/xprofile-data.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ Feature: Manage BuddyPress XProfile Data

When I try `wp bp xprofile data delete --user-id={USER_ID} --yes`
Then the return code should be 1
Then STDERR should contain:
Then STDERR should be:
"""
Either --field-id or --delete-all must be provided
Error: Either --field-id or --delete-all must be provided.
"""

When I run `wp bp xprofile data delete --user-id={USER_ID} --field-id={FIELD_ID} --yes`
Expand Down
72 changes: 61 additions & 11 deletions src/sitewide-notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,9 @@ public static function check_dependencies() {
* @alias add
*/
public function create( $args, $assoc_args ) {
$r = wp_parse_args(
$assoc_args,
[
'subject' => '',
'message' => '',
]
);

$notice = new BP_Messages_Notice();
$notice->subject = $r['subject'];
$notice->message = $r['message'];
$notice->subject = $assoc_args['subject'];
$notice->message = $assoc_args['message'];
$notice->date_sent = bp_core_current_time();
$notice->is_active = 1;
$retval = $notice->save(); // Create it.
Expand Down Expand Up @@ -213,7 +205,7 @@ public function delete( $args, $assoc_args ) {
function ( $notice_id ) {
$notice = new BP_Messages_Notice( $notice_id );

if ( $notice->delete() ) {
if ( ! empty( $notice->date_sent ) && $notice->delete() ) {
return [ 'success', sprintf( 'Sitewide notice deleted %d.', $notice_id ) ];
}

Expand All @@ -222,6 +214,64 @@ function ( $notice_id ) {
);
}

/**
* Activate a sitewide notice.
*
* ## OPTIONS
*
* <notice-id>
* : Identifier for the notice.
*
* ## EXAMPLE
*
* $ wp bp notice activate 123
* Success: Sitewide notice activated.
*/
public function activate( $args ) {
$notice = new BP_Messages_Notice( $args[0] );

if ( ! $notice->date_sent ) {
WP_CLI::error( 'No sitewide notice found by that ID.' );
}

$notice->is_active = 1;

if ( ! $notice->save() ) {
WP_CLI::error( 'Could not activate sitewide notice.' );
}

WP_CLI::success( 'Sitewide notice activated.' );
}

/**
* Deactivate a sitewide notice.
*
* ## OPTIONS
*
* <notice-id>
* : Identifier for the notice.
*
* ## EXAMPLE
*
* $ wp bp notice deactivate 123
* Success: Sitewide notice has been deactivated.
*/
public function deactivate( $args ) {
$notice = new BP_Messages_Notice( $args[0] );

if ( ! $notice->date_sent ) {
WP_CLI::error( 'No sitewide notice found by that ID.' );
}

$notice->is_active = 0;

if ( ! $notice->save() ) {
WP_CLI::error( 'Could not deactivate sitewide notice.' );
}

WP_CLI::success( 'Sitewide notice has been deactivated.' );
}

/**
* Get a list of sitewide notices.
*
Expand Down

0 comments on commit 3d4c2e2

Please sign in to comment.