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

Misc fixes #109

Merged
merged 10 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,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
55 changes: 34 additions & 21 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,19 @@ on: pull_request

jobs:
tests:
name: "WP: ${{ matrix.wp }} - PHP: ${{ matrix.php }}"
name: "WP: ${{ matrix.wp_version }} - PHP: ${{ matrix.php }}"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [7.4, 8.0, 8.1, 8.2, 8.3]
wp: ['latest']
php: ['7.4', '8.0', '8.1', '8.2', '8.3']
wp_version: ['latest']
mysql: [8.0]

include:
- php: '7.4'
wp_version: '6.1'
env:
WP_VERSION: ${{ matrix.wp }}

services:
mysql:
image: mysql:${{ matrix.mysql }}
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=wp_cli_test --entrypoint sh mysql:${{ matrix.mysql }} -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password"
WP_VERSION: ${{ matrix.wp_version }}

steps:
- name: Cancel previous runs of this workflow (pull requests only)
Expand All @@ -48,26 +43,44 @@ jobs:
php-version: ${{ matrix.php }}
extensions: gd, imagick, mysql, zip
coverage: none
tools: composer
tools: composer:v2

- name: Install Composer dependencies & cache dependencies
- name: Install Composer dependencies
uses: ramsey/composer-install@v2

- name: Start MySQL server
run: sudo systemctl start mysql
- name: Setup MySQL Server
id: setup-mysql
uses: shogo82148/actions-setup-mysql@v1
with:
mysql-version: ${{ matrix.mysql }}
auto-start: true
root-password: root
user: wp_cli_test
password: password1
my-cnf: |
default_authentication_plugin=mysql_native_password

- name: Configure DB environment
run: |
export MYSQL_HOST=127.0.0.1
export MYSQL_TCP_PORT=${{ job.services.mysql.ports['3306'] }}
echo "MYSQL_HOST=127.0.0.1" >> $GITHUB_ENV
echo "MYSQL_TCP_PORT=3306" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBROOTUSER=root" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBROOTPASS=root" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBUSER=root" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBPASS=root" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBHOST=$MYSQL_HOST:$MYSQL_TCP_PORT" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBNAME=wp_cli_test" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBUSER=wp_cli_test" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBPASS=password1" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBHOST=127.0.0.1:3306" >> $GITHUB_ENV

- name: Prepare tests
env:
WP_VERSION: '${{ matrix.wp_version }}'
WP_CLI_TEST_DBTYPE: 'mysql'
WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock'
run: composer prepare-tests

- name: Run Behat
env:
WP_VERSION: '${{ matrix.wp_version }}'
WP_CLI_TEST_DBTYPE: 'mysql'
WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock'
run: composer behat || composer behat-rerun
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

This library adheres to [Semantic Versioning](https://semver.org/) and [Keep a CHANGELOG](https://keepachangelog.com/en/1.0.0/).

## 3.0.1 Unpublished

### Changed

* `wp bp tool signup` supports multisite.
* `wp bp signup`:
* `list`: list 50 items by default, instead of 1.
* added support for more object fields.
* Avoid the `generate_callback` method to appear as a valid command by turning it into a protected method.
* Added `composer phpunit` as an alias for `composer behat`.

## 3.0.0

## Added
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"scripts": {
"behat": "run-behat-tests",
"behat-rerun": "rerun-behat-tests",
"phpunit": "behat",
"lint": "run-linter-tests",
"phpcs": "run-phpcs-tests",
"phpcbf": "run-phpcbf-cleanup",
Expand Down
2 changes: 1 addition & 1 deletion src/command.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ function ( $component ) {
* @param array $assoc_args Command arguments.
* @param callable $callback Callback to execute.
*/
public function generate_callback( $message, $assoc_args, $callback ) {
protected function generate_callback( $message, $assoc_args, $callback ) {
$format = WP_CLI\Utils\get_flag_value( $assoc_args, 'format', 'progress' );
$limit = $assoc_args['count'];
$notify = false;
Expand Down
42 changes: 31 additions & 11 deletions src/signup.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
*
* ## EXAMPLES
*
* # Add a signup.
* $ wp bp signup create --user-login=test_user [email protected]
* Success: Successfully added new user signup (ID #345).
*
* # Activate a signup.
* $ wp bp signup activate ee48ec319fef3nn4
* Success: Signup activated, new user (ID #545).
*
Expand All @@ -25,12 +27,14 @@ class Signup extends BuddyPressCommand {
* @var array
*/
protected $obj_fields = [
'signup_id',
'user_login',
'id',
'user_name',
'user_login',
'user_email',
'registered',
'meta',
'activation_key',
'registered',
'count_sent',
];

/**
Expand Down Expand Up @@ -70,7 +74,7 @@ public static function check_dependencies() {
* [--porcelain]
* : Output only the new signup id.
*
* ## EXAMPLE
* ## EXAMPLES
*
* # Add a signup.
* $ wp bp signup create --user-login=test_user [email protected]
Expand Down Expand Up @@ -155,9 +159,16 @@ public function create( $args, $assoc_args ) {
*
* ## EXAMPLES
*
* $ wp bp signup get 123
* $ wp bp signup get [email protected]
* $ wp bp signup get 123 --match-field=id
* # Get a signup.
* $ wp bp signup get 35 --fields=id,user_login,user_name,count_sent
* +------------+------------+
* | Field | Value |
* +------------+------------+
* | id | 35 |
* | user_login | user897616 |
* | user_name | Test user |
* | count_sent | 4 |
* +------------+------------+
*/
public function get( $args, $assoc_args ) {
$signup = $this->get_signup_by_identifier( $args[0], $assoc_args );
Expand Down Expand Up @@ -220,7 +231,7 @@ function ( $signup_id ) {
* <signup-id>
* : Identifier for the signup. Can be a signup ID, an email address, or a user_login.
*
* ## EXAMPLE
* ## EXAMPLES
*
* # Activate a signup.
* $ wp bp signup activate ee48ec319fef3nn4
Expand Down Expand Up @@ -301,7 +312,7 @@ function ( $assoc_args, $format ) use ( $random_login, $email_domain ) {
* <signup-id>
* : Identifier for the signup. Can be a signup ID, an email address, or a user_login.
*
* ## EXAMPLE
* ## EXAMPLES
*
* # Resend activation e-mail to a newly registered user.
* $ wp bp signup resend [email protected]
Expand All @@ -326,9 +337,12 @@ public function resend( $args, $assoc_args ) {
*
* ## OPTIONS
*
* [--fields=<value>]
* [--<field>=<value>]
* : One or more parameters to pass. See \BP_Signup::get()
*
* [--fields=<fields>]
* : Fields to display.
*
* [--count=<number>]
* : How many signups to list.
* ---
Expand All @@ -355,14 +369,20 @@ public function resend( $args, $assoc_args ) {
* 70 71 72 73 74
*
* # List 100 signups and return the count.
* $ wp bp signup list --number=100 --format=count
* $ wp bp signup list --count=100 --format=count
* 100
*
* # List active signups.
* $ wp bp signup list --active=1 --count=10
* 50
*
* @subcommand list
*/
public function list_( $args, $assoc_args ) {
$formatter = $this->get_formatter( $assoc_args );

$assoc_args['number'] = $assoc_args['count'];

if ( in_array( $formatter->format, [ 'ids', 'count' ], true ) ) {
$assoc_args['fields'] = 'ids';
}
Expand Down
30 changes: 18 additions & 12 deletions src/tool.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* $ wp bp tool version
* BuddyPress: 6.0.0
*
* # Reinstall BuddyPress default emails.
* $ wp bp tool reinstall --yes
* Success: Emails have been successfully reinstalled.
* # Activate the signup tool.
* $ wp bp tool signup 1
* Success: Signup tool updated.
*
* @since 1.5.0
*/
Expand Down Expand Up @@ -47,10 +47,9 @@ public static function check_dependencies() {
* - group-count
* - blog-records
* - count-members
* - last-activity
* ---
*
* ## EXAMPLE
* ## EXAMPLES
*
* # Repair the friend count.
* $ wp bp tool repair friend-count
Expand Down Expand Up @@ -109,16 +108,23 @@ public function version() {
* Success: Signup tool updated.
*/
public function signup( $args ) {
$status = wp_validate_boolean( $args[0] );

// Bail early.
if ( bp_get_signup_allowed() ) {
WP_CLI::error( 'The BuddyPress signup feature is already allowed.' );
}
if ( is_multisite() ) {
$retval = get_site_option( 'registration' );

$retval = bp_update_option( 'users_can_register', $args[0] );
if ( 'all' === $retval && $status ) {
WP_CLI::error( 'Both sites and user accounts registration is already allowed.' );
}

$current = $status ? 'all' : 'none';
update_site_option( 'registration', $current );
} else {
if ( bp_get_signup_allowed() && $status ) {
WP_CLI::error( 'The BuddyPress signup feature is already allowed.' );
}

if ( false === $retval ) {
WP_CLI::error( 'Could not update the signup tool.' );
bp_update_option( 'users_can_register', $status );
}

WP_CLI::success( 'Signup tool updated.' );
Expand Down
Loading