diff --git a/composer.lock b/composer.lock index d0393af86f..03b6d0ed7a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ccaaea671f5203685859d8d34df59ec5", + "content-hash": "1d1b53568a0f92fe5377981a1c639fa0", "packages": [], "packages-dev": [ { @@ -13,18 +13,19 @@ "source": { "type": "git", "url": "https://github.com/10up/phpcs-composer.git", - "reference": "2f5c3608bc03fe1ca65acf462dd7b5008f6829a0" + "reference": "5f9ac994db1af9924a71b0f5663fe7f6bd59c812" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/10up/phpcs-composer/zipball/2f5c3608bc03fe1ca65acf462dd7b5008f6829a0", - "reference": "2f5c3608bc03fe1ca65acf462dd7b5008f6829a0", + "url": "https://api.github.com/repos/10up/phpcs-composer/zipball/5f9ac994db1af9924a71b0f5663fe7f6bd59c812", + "reference": "5f9ac994db1af9924a71b0f5663fe7f6bd59c812", "shasum": "" }, "require": { + "automattic/vipwpcs": "^2.3", "dealerdirect/phpcodesniffer-composer-installer": "*", "phpcompatibility/phpcompatibility-wp": "^2", - "squizlabs/php_codesniffer": "^3.4.0", + "squizlabs/php_codesniffer": "3.7.1", "wp-coding-standards/wpcs": "*" }, "default-branch": true, @@ -43,7 +44,59 @@ "issues": "https://github.com/10up/phpcs-composer/issues", "source": "https://github.com/10up/phpcs-composer/tree/master" }, - "time": "2021-01-08T03:03:06+00:00" + "time": "2022-11-18T18:13:03+00:00" + }, + { + "name": "automattic/vipwpcs", + "version": "2.3.3", + "source": { + "type": "git", + "url": "https://github.com/Automattic/VIP-Coding-Standards.git", + "reference": "6cd0a6a82bc0ac988dbf9d6a7c2e293dc8ac640b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Automattic/VIP-Coding-Standards/zipball/6cd0a6a82bc0ac988dbf9d6a7c2e293dc8ac640b", + "reference": "6cd0a6a82bc0ac988dbf9d6a7c2e293dc8ac640b", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7", + "php": ">=5.4", + "sirbrillig/phpcs-variable-analysis": "^2.11.1", + "squizlabs/php_codesniffer": "^3.5.5", + "wp-coding-standards/wpcs": "^2.3" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^0.5", + "php-parallel-lint/php-parallel-lint": "^1.0", + "phpcompatibility/php-compatibility": "^9", + "phpcsstandards/phpcsdevtools": "^1.0", + "phpunit/phpunit": "^4 || ^5 || ^6 || ^7" + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/Automattic/VIP-Coding-Standards/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress VIP minimum coding conventions", + "keywords": [ + "phpcs", + "standards", + "wordpress" + ], + "support": { + "issues": "https://github.com/Automattic/VIP-Coding-Standards/issues", + "source": "https://github.com/Automattic/VIP-Coding-Standards", + "wiki": "https://github.com/Automattic/VIP-Coding-Standards/wiki" + }, + "time": "2021-09-29T16:20:23+00:00" }, { "name": "composer/installers", @@ -267,30 +320,30 @@ }, { "name": "doctrine/instantiator", - "version": "1.4.1", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc" + "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/10dcfce151b967d20fde1b34ae6640712c3891bc", - "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/0a0fa9780f5d4e507415a065172d26a98d02047b", + "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b", "shasum": "" }, "require": { "php": "^7.1 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^9", + "doctrine/coding-standard": "^9 || ^11", "ext-pdo": "*", "ext-phar": "*", "phpbench/phpbench": "^0.16 || ^1", "phpstan/phpstan": "^1.4", "phpstan/phpstan-phpunit": "^1", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "vimeo/psalm": "^4.22" + "vimeo/psalm": "^4.30 || ^5.4" }, "type": "library", "autoload": { @@ -317,7 +370,7 @@ ], "support": { "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/1.4.1" + "source": "https://github.com/doctrine/instantiator/tree/1.5.0" }, "funding": [ { @@ -333,7 +386,7 @@ "type": "tidelift" } ], - "time": "2022-03-03T08:28:38+00:00" + "time": "2022-12-30T00:15:36+00:00" }, { "name": "myclabs/deep-copy", @@ -396,16 +449,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.15.1", + "version": "v4.15.3", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "0ef6c55a3f47f89d7a374e6f835197a0b5fcf900" + "reference": "570e980a201d8ed0236b0a62ddf2c9cbb2034039" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/0ef6c55a3f47f89d7a374e6f835197a0b5fcf900", - "reference": "0ef6c55a3f47f89d7a374e6f835197a0b5fcf900", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/570e980a201d8ed0236b0a62ddf2c9cbb2034039", + "reference": "570e980a201d8ed0236b0a62ddf2c9cbb2034039", "shasum": "" }, "require": { @@ -446,9 +499,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.15.1" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.15.3" }, - "time": "2022-09-04T07:30:47+00:00" + "time": "2023-01-16T22:05:37+00:00" }, { "name": "phar-io/manifest", @@ -625,16 +678,16 @@ }, { "name": "phpcompatibility/phpcompatibility-paragonie", - "version": "1.3.1", + "version": "1.3.2", "source": { "type": "git", "url": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie.git", - "reference": "ddabec839cc003651f2ce695c938686d1086cf43" + "reference": "bba5a9dfec7fcfbd679cfaf611d86b4d3759da26" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/ddabec839cc003651f2ce695c938686d1086cf43", - "reference": "ddabec839cc003651f2ce695c938686d1086cf43", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/bba5a9dfec7fcfbd679cfaf611d86b4d3759da26", + "reference": "bba5a9dfec7fcfbd679cfaf611d86b4d3759da26", "shasum": "" }, "require": { @@ -671,26 +724,27 @@ "paragonie", "phpcs", "polyfill", - "standards" + "standards", + "static analysis" ], "support": { "issues": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/issues", "source": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie" }, - "time": "2021-02-15T10:24:51+00:00" + "time": "2022-10-25T01:46:02+00:00" }, { "name": "phpcompatibility/phpcompatibility-wp", - "version": "2.1.3", + "version": "2.1.4", "source": { "type": "git", "url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git", - "reference": "d55de55f88697b9cdb94bccf04f14eb3b11cf308" + "reference": "b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/d55de55f88697b9cdb94bccf04f14eb3b11cf308", - "reference": "d55de55f88697b9cdb94bccf04f14eb3b11cf308", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5", + "reference": "b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5", "shasum": "" }, "require": { @@ -725,26 +779,27 @@ "compatibility", "phpcs", "standards", + "static analysis", "wordpress" ], "support": { "issues": "https://github.com/PHPCompatibility/PHPCompatibilityWP/issues", "source": "https://github.com/PHPCompatibility/PHPCompatibilityWP" }, - "time": "2021-12-30T16:37:40+00:00" + "time": "2022-10-24T09:00:36+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.17", + "version": "9.2.24", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "aa94dc41e8661fe90c7316849907cba3007b10d8" + "reference": "2cf940ebc6355a9d430462811b5aaa308b174bed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/aa94dc41e8661fe90c7316849907cba3007b10d8", - "reference": "aa94dc41e8661fe90c7316849907cba3007b10d8", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2cf940ebc6355a9d430462811b5aaa308b174bed", + "reference": "2cf940ebc6355a9d430462811b5aaa308b174bed", "shasum": "" }, "require": { @@ -800,7 +855,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.17" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.24" }, "funding": [ { @@ -808,7 +863,7 @@ "type": "github" } ], - "time": "2022-08-30T12:24:04+00:00" + "time": "2023-01-26T08:26:55+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1053,20 +1108,20 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.25", + "version": "9.6.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "3e6f90ca7e3d02025b1d147bd8d4a89fd4ca8a1d" + "reference": "e7b1615e3e887d6c719121c6d4a44b0ab9645555" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3e6f90ca7e3d02025b1d147bd8d4a89fd4ca8a1d", - "reference": "3e6f90ca7e3d02025b1d147bd8d4a89fd4ca8a1d", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/e7b1615e3e887d6c719121c6d4a44b0ab9645555", + "reference": "e7b1615e3e887d6c719121c6d4a44b0ab9645555", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.3.1", + "doctrine/instantiator": "^1.3.1 || ^2", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", @@ -1104,7 +1159,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "9.5-dev" + "dev-master": "9.6-dev" } }, "autoload": { @@ -1135,7 +1190,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.25" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.3" }, "funding": [ { @@ -1151,7 +1206,7 @@ "type": "tidelift" } ], - "time": "2022-09-25T03:44:45+00:00" + "time": "2023-02-04T13:37:15+00:00" }, { "name": "sebastian/cli-parser", @@ -1519,16 +1574,16 @@ }, { "name": "sebastian/environment", - "version": "5.1.4", + "version": "5.1.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7" + "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/1b5dff7bb151a4db11d49d90e5408e4e938270f7", - "reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/830c43a844f1f8d5b7a1f6d6076b784454d8b7ed", + "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed", "shasum": "" }, "require": { @@ -1570,7 +1625,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/environment/issues", - "source": "https://github.com/sebastianbergmann/environment/tree/5.1.4" + "source": "https://github.com/sebastianbergmann/environment/tree/5.1.5" }, "funding": [ { @@ -1578,7 +1633,7 @@ "type": "github" } ], - "time": "2022-04-03T09:37:03+00:00" + "time": "2023-02-03T06:03:51+00:00" }, { "name": "sebastian/exporter", @@ -1892,16 +1947,16 @@ }, { "name": "sebastian/recursion-context", - "version": "4.0.4", + "version": "4.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "cd9d8cf3c5804de4341c283ed787f099f5506172" + "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/cd9d8cf3c5804de4341c283ed787f099f5506172", - "reference": "cd9d8cf3c5804de4341c283ed787f099f5506172", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1", + "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1", "shasum": "" }, "require": { @@ -1940,10 +1995,10 @@ } ], "description": "Provides functionality to recursively process PHP variables", - "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "homepage": "https://github.com/sebastianbergmann/recursion-context", "support": { "issues": "https://github.com/sebastianbergmann/recursion-context/issues", - "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.4" + "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.5" }, "funding": [ { @@ -1951,7 +2006,7 @@ "type": "github" } ], - "time": "2020-10-26T13:17:30+00:00" + "time": "2023-02-03T06:07:39+00:00" }, { "name": "sebastian/resource-operations", @@ -2010,16 +2065,16 @@ }, { "name": "sebastian/type", - "version": "3.2.0", + "version": "3.2.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", - "reference": "fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e" + "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e", - "reference": "fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7", + "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7", "shasum": "" }, "require": { @@ -2054,7 +2109,7 @@ "homepage": "https://github.com/sebastianbergmann/type", "support": { "issues": "https://github.com/sebastianbergmann/type/issues", - "source": "https://github.com/sebastianbergmann/type/tree/3.2.0" + "source": "https://github.com/sebastianbergmann/type/tree/3.2.1" }, "funding": [ { @@ -2062,7 +2117,7 @@ "type": "github" } ], - "time": "2022-09-12T14:47:03+00:00" + "time": "2023-02-03T06:13:03+00:00" }, { "name": "sebastian/version", @@ -2117,6 +2172,64 @@ ], "time": "2020-09-28T06:39:44+00:00" }, + { + "name": "sirbrillig/phpcs-variable-analysis", + "version": "v2.11.10", + "source": { + "type": "git", + "url": "https://github.com/sirbrillig/phpcs-variable-analysis.git", + "reference": "0f25a3766f26df91d6bdda0c8931303fc85499d7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sirbrillig/phpcs-variable-analysis/zipball/0f25a3766f26df91d6bdda0c8931303fc85499d7", + "reference": "0f25a3766f26df91d6bdda0c8931303fc85499d7", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "squizlabs/php_codesniffer": "^3.5.6" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || ^1.0", + "phpcsstandards/phpcsdevcs": "^1.1", + "phpstan/phpstan": "^1.7", + "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.5 || ^7.0 || ^8.0 || ^9.0", + "sirbrillig/phpcs-import-detection": "^1.1", + "vimeo/psalm": "^0.2 || ^0.3 || ^1.1 || ^4.24 || ^5.0@beta" + }, + "type": "phpcodesniffer-standard", + "autoload": { + "psr-4": { + "VariableAnalysis\\": "VariableAnalysis/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Sam Graham", + "email": "php-codesniffer-variableanalysis@illusori.co.uk" + }, + { + "name": "Payton Swick", + "email": "payton@foolord.com" + } + ], + "description": "A PHPCS sniff to detect problems with variables.", + "keywords": [ + "phpcs", + "static analysis" + ], + "support": { + "issues": "https://github.com/sirbrillig/phpcs-variable-analysis/issues", + "source": "https://github.com/sirbrillig/phpcs-variable-analysis", + "wiki": "https://github.com/sirbrillig/phpcs-variable-analysis/wiki" + }, + "time": "2023-01-05T18:45:16+00:00" + }, { "name": "squizlabs/php_codesniffer", "version": "3.7.1", @@ -2276,15 +2389,15 @@ }, { "name": "wpackagist-plugin/woocommerce", - "version": "7.0.0", + "version": "7.3.0", "source": { "type": "svn", "url": "https://plugins.svn.wordpress.org/woocommerce/", - "reference": "tags/7.0.0" + "reference": "tags/7.3.0" }, "dist": { "type": "zip", - "url": "https://downloads.wordpress.org/plugin/woocommerce.7.0.0.zip" + "url": "https://downloads.wordpress.org/plugin/woocommerce.7.3.0.zip" }, "require": { "composer/installers": "^1.0 || ^2.0" @@ -2294,16 +2407,16 @@ }, { "name": "yoast/phpunit-polyfills", - "version": "1.0.3", + "version": "1.0.4", "source": { "type": "git", "url": "https://github.com/Yoast/PHPUnit-Polyfills.git", - "reference": "5ea3536428944955f969bc764bbe09738e151ada" + "reference": "3c621ff5429d2b1ff96dc5808ad6cde99d31ea4c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Yoast/PHPUnit-Polyfills/zipball/5ea3536428944955f969bc764bbe09738e151ada", - "reference": "5ea3536428944955f969bc764bbe09738e151ada", + "url": "https://api.github.com/repos/Yoast/PHPUnit-Polyfills/zipball/3c621ff5429d2b1ff96dc5808ad6cde99d31ea4c", + "reference": "3c621ff5429d2b1ff96dc5808ad6cde99d31ea4c", "shasum": "" }, "require": { @@ -2311,7 +2424,7 @@ "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0" }, "require-dev": { - "yoast/yoastcs": "^2.2.0" + "yoast/yoastcs": "^2.2.1" }, "type": "library", "extra": { @@ -2351,7 +2464,7 @@ "issues": "https://github.com/Yoast/PHPUnit-Polyfills/issues", "source": "https://github.com/Yoast/PHPUnit-Polyfills" }, - "time": "2021-11-23T01:37:03+00:00" + "time": "2022-11-16T09:07:52+00:00" } ], "aliases": [], diff --git a/includes/classes/Command.php b/includes/classes/Command.php index a3dd3d4826..14e31480c7 100644 --- a/includes/classes/Command.php +++ b/includes/classes/Command.php @@ -170,8 +170,9 @@ public function deactivate_feature( $args, $assoc_args ) { * @param array $assoc_args Associative CLI args. */ public function list_features( $args, $assoc_args ) { + $list_all = \WP_CLI\Utils\get_flag_value( $assoc_args, 'all', null ); - if ( empty( $assoc_args['all'] ) ) { + if ( empty( $list_all ) ) { $features = Utils\get_option( 'ep_feature_settings', [] ); WP_CLI::line( esc_html__( 'Active features:', 'elasticpress' ) ); @@ -395,22 +396,15 @@ private function put_mapping_helper( $args, $assoc_args ) { * @param array $assoc_args Associative CLI args. */ public function get_mapping( $args, $assoc_args ) { - $defaults = [ - 'index-name' => $this->get_index_names(), - 'pretty' => false, - ]; - - if ( isset( $assoc_args['index-name'] ) ) { - $assoc_args['index-name'] = (array) $assoc_args['index-name']; - } + $pretty = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pretty' ); + $index_name = \WP_CLI\Utils\get_flag_value( $assoc_args, 'index-name' ); + $index_names = (array) ( ! empty( $index_name ) ? $index_name : $this->get_index_names() ); - $assoc_args = wp_parse_args( $assoc_args, $defaults ); - - $path = join( ',', $assoc_args['index-name'] ) . '/_mapping'; + $path = join( ',', $index_names ) . '/_mapping'; $response = Elasticsearch::factory()->remote_request( $path ); - $this->print_json_response( $response, $this->filter_boolean( $assoc_args['pretty'] ) ); + $this->print_json_response( $response, $pretty ); } /** @@ -427,15 +421,11 @@ public function get_mapping( $args, $assoc_args ) { * @param array $assoc_args Associative CLI args. */ public function get_cluster_indices( $args, $assoc_args ) { - $defaults = [ - 'pretty' => false, - ]; - - $assoc_args = wp_parse_args( $assoc_args, $defaults ); + $pretty = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pretty' ); $cluster_indices = Elasticsearch::factory()->get_cluster_indices(); - $this->pretty_json_encode( $cluster_indices, $this->filter_boolean( $assoc_args['pretty'] ) ); + $this->pretty_json_encode( $cluster_indices, $pretty ); } /** @@ -456,15 +446,14 @@ public function get_cluster_indices( $args, $assoc_args ) { */ public function get_indices( $args, $assoc_args ) { $defaults = [ - 'pretty' => false, 'status' => 'active', ]; - $assoc_args = wp_parse_args( $assoc_args, $defaults ); - + $assoc_args = wp_parse_args( $assoc_args, $defaults ); + $pretty = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pretty' ); $index_names = $this->get_index_names( $assoc_args['status'] ); - $this->pretty_json_encode( $index_names, $this->filter_boolean( $assoc_args['pretty'] ) ); + $this->pretty_json_encode( $index_names, $pretty ); } /** @@ -736,9 +725,9 @@ public function delete_transient_on_int( $signal_no ) { public function sync( $args, $assoc_args ) { global $wp_actions; - $setup_option = isset( $assoc_args['setup'] ) ? $assoc_args['setup'] : false; + $setup_option = \WP_CLI\Utils\get_flag_value( $assoc_args, 'setup', false ); - if ( true === $setup_option ) { + if ( $setup_option ) { WP_CLI::confirm( esc_html__( 'Indexing with setup option needs to delete Elasticsearch index first, are you sure you want to delete your Elasticsearch index?', 'elasticpress' ), $assoc_args ); } @@ -781,18 +770,20 @@ public function sync( $args, $assoc_args ) { add_action( 'ep_sync_put_mapping', [ $this, 'call_ep_cli_put_mapping' ], 10, 2 ); add_action( 'ep_index_batch_new_attempt', [ $this, 'should_interrupt_sync' ] ); - $no_bulk = ! empty( $assoc_args['nobulk'] ); + $no_bulk = ! empty( $assoc_args['nobulk'] ); + $static_bulk = \WP_CLI\Utils\get_flag_value( $assoc_args, 'static-bulk', null ); + $network_wide = \WP_CLI\Utils\get_flag_value( $assoc_args, 'network-wide', null ); $index_args = [ 'method' => 'cli', 'total_attempts' => 1, 'indexables' => $indexables, - 'put_mapping' => ! empty( $setup_option ), + 'put_mapping' => $setup_option, 'output_method' => [ $this, 'index_output' ], - 'network_wide' => ( ! empty( $assoc_args['network-wide'] ) ) ? $assoc_args['network-wide'] : null, + 'network_wide' => $network_wide, 'nobulk' => $no_bulk, 'offset' => ( ! empty( $assoc_args['offset'] ) ) ? absint( $assoc_args['offset'] ) : 0, - 'static_bulk' => ( ! empty( $assoc_args['static-bulk'] ) ) ? $assoc_args['static-bulk'] : null, + 'static_bulk' => $static_bulk, ]; if ( isset( $assoc_args['show-errors'] ) || ( isset( $assoc_args['show-bulk-errors'] ) && ! $no_bulk ) || ( isset( $assoc_args['show-nobulk-errors'] ) && $no_bulk ) ) { @@ -1037,11 +1028,7 @@ public function clear_sync() { * @param array $assoc_args Associative CLI args. */ public function get_ongoing_sync_status( $args, $assoc_args ) { - $defaults = [ - 'pretty' => false, - ]; - - $assoc_args = wp_parse_args( $assoc_args, $defaults ); + $pretty = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pretty' ); $indexing_status = Utils\get_indexing_status(); if ( empty( $indexing_status ) ) { @@ -1053,7 +1040,7 @@ public function get_ongoing_sync_status( $args, $assoc_args ) { ]; } - $this->pretty_json_encode( $indexing_status, $this->filter_boolean( $assoc_args['pretty'] ) ); + $this->pretty_json_encode( $indexing_status, $pretty ); } /** @@ -1071,14 +1058,10 @@ public function get_ongoing_sync_status( $args, $assoc_args ) { * @param array $assoc_args Associative CLI args. */ public function get_last_sync( $args, $assoc_args ) { - $defaults = [ - 'pretty' => false, - ]; + $pretty = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pretty' ); + $last_sync = \ElasticPress\IndexHelper::factory()->get_last_index(); - $assoc_args = wp_parse_args( $assoc_args, $defaults ); - $last_sync = \ElasticPress\IndexHelper::factory()->get_last_index(); - - $this->pretty_json_encode( $last_sync, $this->filter_boolean( $assoc_args['pretty'] ) ); + $this->pretty_json_encode( $last_sync, $pretty ); } /** @@ -1098,19 +1081,14 @@ public function get_last_sync( $args, $assoc_args ) { * @param array $assoc_args Associative CLI args. */ public function get_last_cli_sync( $args, $assoc_args ) { - $defaults = [ - 'pretty' => false, - ]; - - $assoc_args = wp_parse_args( $assoc_args, $defaults ); - + $pretty = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pretty' ); $last_sync = Utils\get_option( 'ep_last_cli_index', array() ); if ( isset( $assoc_args['clear'] ) ) { Utils\delete_option( 'ep_last_cli_index' ); } - $this->pretty_json_encode( $last_sync, $this->filter_boolean( $assoc_args['pretty'] ) ); + $this->pretty_json_encode( $last_sync, $pretty ); } @@ -1446,23 +1424,19 @@ public function call_ep_cli_put_mapping( $index_meta, $indexable ) { * @param array $assoc_args Associative CLI args. */ public function request( $args, $assoc_args ) { - $defaults = [ - 'pretty' => false, - ]; - - $assoc_args = wp_parse_args( $assoc_args, $defaults ); - - $path = $args[0]; - $method = isset( $assoc_args['method'] ) ? $assoc_args['method'] : 'GET'; - $body = isset( $assoc_args['body'] ) ? $assoc_args['body'] : ''; - $request_args = [ + $pretty = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pretty' ); + $debug_http_request = \WP_CLI\Utils\get_flag_value( $assoc_args, 'debug-http-request' ); + $path = $args[0]; + $method = isset( $assoc_args['method'] ) ? $assoc_args['method'] : 'GET'; + $body = isset( $assoc_args['body'] ) ? $assoc_args['body'] : ''; + $request_args = [ 'method' => $method, ]; if ( 'GET' !== $method && ! empty( $body ) ) { $request_args['body'] = $body; } - if ( ! empty( $assoc_args['debug-http-request'] ) ) { + if ( ! empty( $debug_http_request ) ) { add_filter( 'http_api_debug', function ( $response, $context, $transport, $request_args, $url ) { @@ -1514,7 +1488,7 @@ function ( $response, $context, $transport, $request_args, $url ) { WP_CLI::error( $response->get_error_message() ); } - $this->print_json_response( $response, $this->filter_boolean( $assoc_args['pretty'] ) ); + $this->print_json_response( $response, $pretty ); } /** @@ -1629,15 +1603,11 @@ protected function pretty_json_encode( $json_obj, $pretty_print_flag ) { * @subcommand get-search-template */ public function get_search_template( $args, $assoc_args ) { - $defaults = [ - 'pretty' => false, - ]; - - $assoc_args = wp_parse_args( $assoc_args, $defaults ); + $pretty = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pretty' ); $instant_results = Features::factory()->get_registered_feature( 'instant-results' ); $template = json_decode( $instant_results->epio_get_search_template() ); - $this->pretty_json_encode( $template, $assoc_args['pretty'] ); + $this->pretty_json_encode( $template, $pretty ); } /** @@ -1663,15 +1633,4 @@ public function delete_search_template() { $instant_results->epio_delete_search_template(); WP_CLI::success( esc_html__( 'Done.', 'elasticpress' ) ); } - - /** - * Whether a value can be evaluated as true or not. - * - * @since 4.4.1 - * @param string $value A string value that is going to be evaluated as bool or not. - * @return bool - */ - protected function filter_boolean( $value ) { - return filter_var( $value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE ); - } } diff --git a/includes/dashboard.php b/includes/dashboard.php index 9981c25858..f40a2e3b08 100644 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -235,6 +235,7 @@ function maybe_clear_es_info_cache() { if ( ! empty( $_GET['ep-retry'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification wp_safe_redirect( remove_query_arg( 'ep-retry' ) ); + exit(); } } diff --git a/includes/partials/settings-page.php b/includes/partials/settings-page.php index 088a7ee0a6..f59e708a90 100644 --- a/includes/partials/settings-page.php +++ b/includes/partials/settings-page.php @@ -37,7 +37,7 @@