From 8cf0f2f228e2d8c197febe17a92187c28bde22dd Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Wed, 26 Sep 2018 11:44:36 +0200 Subject: [PATCH 01/28] Replace autoloader implementation The current autoloader implementation uses `set_include_path()`, which should be avoided. Since PHP 5.3, there's no valid reason to use `set_include_path()` in application code anymore, as: - it adds processing overhead and additional filesystem checks to _all_ `include`/`require` statements that follow it; - following from that, it slows down _all_ other autoloaders as well; - it can break in environments where the include path is set at the server level and cannot be changed due to security restrictions; - `spl_autoload_register()` can be fed a callback that does the `include` directly, avoiding any further processing. This alternative autoloader implementation uses a direct `include` in the callback that avoids the above drawbacks and is closer to the generally accepted approach that is now used by the PHP community (usually in the form of an autoloader generated by Composer). --- woocommerce-custom-orders-table.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/woocommerce-custom-orders-table.php b/woocommerce-custom-orders-table.php index d068d1d..06ae9cc 100644 --- a/woocommerce-custom-orders-table.php +++ b/woocommerce-custom-orders-table.php @@ -20,10 +20,6 @@ define( 'WC_CUSTOM_ORDER_TABLE_URL', plugin_dir_url( __FILE__ ) ); define( 'WC_CUSTOM_ORDER_TABLE_PATH', plugin_dir_path( __FILE__ ) ); -// phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_set_include_path -set_include_path( get_include_path() . PATH_SEPARATOR . WC_CUSTOM_ORDER_TABLE_PATH . '/includes/' ); -// phpcs:enable WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_set_include_path - /** * Autoloader for plugin files. * @@ -31,11 +27,25 @@ * conventions, where a class of 'Foo_Bar' would be named 'class-foo-bar.php'. * * @param string $class The class name to autoload. + * + * @return void */ function wc_custom_order_table_autoload( $class ) { - $class = 'class-' . str_replace( '_', '-', $class ); + // Bail early if the class/trait/interface is not in the root namespace. + if ( strpos( $class, '\\' ) !== false ) { + return; + } + + // Assemble file path and name according to WordPress code style. + $filename = strtolower( 'class-' . str_replace( '_', '-', $class ) . '.php' ); + $filepath = WC_CUSTOM_ORDER_TABLE_PATH . 'includes/' . $filename; + + // Bail if the file name we generated does not exist. + if ( ! is_readable( $filepath ) ) { + return; + } - return spl_autoload( $class ); + include $filepath; } spl_autoload_register( 'wc_custom_order_table_autoload' ); From 03c0266b40c5d47bd75dc171110b88ae3b2e52cb Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Sat, 6 Oct 2018 19:45:43 +0000 Subject: [PATCH 02/28] Update Composer dependencies --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index 16b24cb..ca5b992 100644 --- a/composer.lock +++ b/composer.lock @@ -1951,12 +1951,12 @@ "source": { "type": "git", "url": "https://github.com/woocommerce/woocommerce.git", - "reference": "b4242135546674e055701b9c017fff1d4d71bbcd" + "reference": "c12bb2dac52badd4b46146380a3054ddfbf41253" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/woocommerce/woocommerce/zipball/b4242135546674e055701b9c017fff1d4d71bbcd", - "reference": "b4242135546674e055701b9c017fff1d4d71bbcd", + "url": "https://api.github.com/repos/woocommerce/woocommerce/zipball/c12bb2dac52badd4b46146380a3054ddfbf41253", + "reference": "c12bb2dac52badd4b46146380a3054ddfbf41253", "shasum": "" }, "require": { @@ -1987,7 +1987,7 @@ ], "description": "An eCommerce toolkit that helps you sell anything. Beautifully.", "homepage": "https://woocommerce.com/", - "time": "2018-09-24T20:03:20+00:00" + "time": "2018-10-05T17:50:56+00:00" }, { "name": "woocommerce/woocommerce-git-hooks", From 4edf6022b9ecfe21c8e85b37f4928173ab1e05c4 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Sat, 6 Oct 2018 19:48:52 +0000 Subject: [PATCH 03/28] Borrow a note from WooCommerce core and try phpdbg for coverage --- .travis.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0934f55..3778df4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,9 +43,7 @@ before_script: wget https://github.com/php-coveralls/php-coveralls/releases/download/v1.0.0/coveralls.phar chmod +x coveralls.phar mkdir -p build/logs - else - phpenv config-rm xdebug.ini - fi + - phpenv config-rm xdebug.ini - | if [[ ${GITHUB_AUTH_TOKEN} != '' ]]; then composer config -g github-oauth.github.com $GITHUB_AUTH_TOKEN @@ -57,7 +55,7 @@ before_script: script: - | if [[ ${RUN_CODE_COVERAGE} ]]; then - ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml + phpdbg -qrr -d memory_limit=-1 ./vendor/bin/phpunit -c phpunit.xml --coverage-clover=build/logs/clover.xml --exclude-group=timeout else ./vendor/bin/phpunit fi From b6c6f94888d7ddb6b4672ea632c57257a92cfc9b Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Sat, 6 Oct 2018 19:56:55 +0000 Subject: [PATCH 04/28] Whoops, missed a closing 'fi' --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 3778df4..3e0726d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,6 +43,7 @@ before_script: wget https://github.com/php-coveralls/php-coveralls/releases/download/v1.0.0/coveralls.phar chmod +x coveralls.phar mkdir -p build/logs + fi - phpenv config-rm xdebug.ini - | if [[ ${GITHUB_AUTH_TOKEN} != '' ]]; then From 493d65f484b7c91adc1bf18068d565ea169b4261 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Sat, 6 Oct 2018 20:14:29 +0000 Subject: [PATCH 05/28] It helps when you specify the right PHPUnit configuration file --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3e0726d..df74612 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,7 +56,7 @@ before_script: script: - | if [[ ${RUN_CODE_COVERAGE} ]]; then - phpdbg -qrr -d memory_limit=-1 ./vendor/bin/phpunit -c phpunit.xml --coverage-clover=build/logs/clover.xml --exclude-group=timeout + phpdbg -qrr -d memory_limit=-1 ./vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover=build/logs/clover.xml --exclude-group=timeout else ./vendor/bin/phpunit fi From d38de1599bf47f83d99b98a33daac47c465e5ec4 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Mon, 8 Oct 2018 17:43:17 +0000 Subject: [PATCH 06/28] Ensure the Coveralls badge is based on develop The code coverage badge in the README should reflect coverage on `develop`, not `feature/code-coverage`. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0e5f42e..0675ef0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # WooCommerce Custom Orders Table [![Build Status](https://travis-ci.org/liquidweb/woocommerce-custom-orders-table.svg?branch=develop)](https://travis-ci.org/liquidweb/woocommerce-custom-orders-table) -[![Coverage Status](https://coveralls.io/repos/github/liquidweb/woocommerce-custom-orders-table/badge.svg?branch=feature%2Fcode-coverage)](https://coveralls.io/github/liquidweb/woocommerce-custom-orders-table?branch=feature%2Fcode-coverage) +[![Coverage Status](https://coveralls.io/repos/github/liquidweb/woocommerce-custom-orders-table/badge.svg?branch=develop)](https://coveralls.io/github/liquidweb/woocommerce-custom-orders-table?branch=develop) This plugin improves WooCommerce performance by introducing a custom table to hold all of the most common order information in a single, properly-indexed location. From b99a9e2b06d70aa7021fdc696612de904f1cf862 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Tue, 23 Oct 2018 15:30:57 +0000 Subject: [PATCH 07/28] Remove unused instance of the $wpdb global --- tests/test-installation.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/test-installation.php b/tests/test-installation.php index c745389..dc35ca9 100644 --- a/tests/test-installation.php +++ b/tests/test-installation.php @@ -147,8 +147,6 @@ public function test_database_indexes( $non_unique, $key_name, $column_name ) { * @link https://github.com/liquidweb/woocommerce-custom-orders-table/issues/48 */ public function test_char_length( $column, $length ) { - global $wpdb; - $this->assert_column_has_type( $column, sprintf( 'char(%d)', $length ), @@ -159,8 +157,6 @@ public function test_char_length( $column, $length ) { /** * Test the lengths of VARCHAR fields. * - * @global $wpdb - * * @testWith ["order_key", 100] * ["billing_index", 255] * ["billing_first_name", 100] @@ -204,8 +200,6 @@ public function test_char_length( $column, $length ) { * @link https://github.com/liquidweb/woocommerce-custom-orders-table/issues/48 */ public function test_varchar_length( $column, $length ) { - global $wpdb; - $this->assert_column_has_type( $column, sprintf( 'varchar(%d)', $length ), From 5ad79f83909ab0c0919243b5a1cc95bfd68f8afd Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Tue, 23 Oct 2018 15:38:02 +0000 Subject: [PATCH 08/28] Convert the customer_user_agent column from varchar(200) to text --- .../class-woocommerce-custom-orders-table-install.php | 2 +- tests/test-installation.php | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/includes/class-woocommerce-custom-orders-table-install.php b/includes/class-woocommerce-custom-orders-table-install.php index d552f5b..7d96b37 100644 --- a/includes/class-woocommerce-custom-orders-table-install.php +++ b/includes/class-woocommerce-custom-orders-table-install.php @@ -92,7 +92,7 @@ protected static function install_tables() { prices_include_tax varchar(3) NOT NULL COMMENT 'Did the prices include tax during checkout?', transaction_id varchar(200) NOT NULL COMMENT 'Unique transaction ID', customer_ip_address varchar(40) DEFAULT NULL COMMENT 'The customer\'s IP address', - customer_user_agent varchar(200) DEFAULT NULL COMMENT 'The customer\'s User-Agent string', + customer_user_agent text DEFAULT NULL COMMENT 'The customer\'s User-Agent string', created_via varchar(200) NOT NULL COMMENT 'Order creation method', date_completed varchar(20) DEFAULT NULL COMMENT 'Date the order was completed', date_paid varchar(20) DEFAULT NULL COMMENT 'Date the order was paid', diff --git a/tests/test-installation.php b/tests/test-installation.php index dc35ca9..afb7875 100644 --- a/tests/test-installation.php +++ b/tests/test-installation.php @@ -190,7 +190,6 @@ public function test_char_length( $column, $length ) { * ["prices_include_tax", 3] * ["transaction_id", 200] * ["customer_ip_address", 40] - * ["customer_user_agent", 200] * ["created_via", 200] * ["date_completed", 20] * ["date_paid", 20] @@ -207,6 +206,13 @@ public function test_varchar_length( $column, $length ) { ); } + /** + * @ticket https://github.com/liquidweb/woocommerce-custom-orders-table/issues/89 + */ + public function test_user_agent_is_stored_in_text_column() { + $this->assert_column_has_type( 'customer_user_agent', 'text' ); + } + /** * Assert the type of a given column matches expectations. * From 470ac825eec013f569e2f69c73bc15f819eb305a Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Wed, 24 Oct 2018 19:02:02 +0000 Subject: [PATCH 09/28] Add PHP version to the bug report template --- .github/ISSUE_TEMPLATE/Bug_report.md | 59 ++++++++++++++-------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md index ea7ec60..f1ea9fd 100644 --- a/.github/ISSUE_TEMPLATE/Bug_report.md +++ b/.github/ISSUE_TEMPLATE/Bug_report.md @@ -1,29 +1,30 @@ ---- -name: Bug report -about: Create a report to help us improve - ---- - -**Describe the bug** -A clear and concise description of what the bug is. - -**To Reproduce** -Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error - -**Expected behavior** -A clear and concise description of what you expected to happen. - -**Screenshots** -If applicable, add screenshots to help explain your problem. - -**Versions** -- WordPress version -- WooCommerce version -- Plugin version [e.g. "1.0.0 (Beta 3)" or "develop @ 027c6aa"] - -**Additional context** -Add any other context about the problem here. +--- +name: Bug report +about: Create a report to help us improve + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Versions** +- WordPress version +- WooCommerce version +- Plugin version [e.g. "1.0.0 (Beta 3)" or "develop @ 027c6aa"] +- PHP version + +**Additional context** +Add any other context about the problem here. From 245334da79c7f3485afef5703a0c43a1277e3ae9 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Wed, 24 Oct 2018 19:17:17 +0000 Subject: [PATCH 10/28] =?UTF-8?q?Update=20Composer=20dependencies=20and=20?= =?UTF-8?q?restructure=20the=20PHP=5FCodeSniffer=20config=20to=20rely=20on?= =?UTF-8?q?=20the=20WooCommerce=20Core=20=E2=80=94=C2=A0not=20what's=20=5F?= =?UTF-8?q?in=5F=20WooCommerce=20=E2=80=94=C2=A0as=20a=20base?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 8 ++-- composer.lock | 116 ++++++++++++++++++++++++++----------------------- phpcs.xml.dist | 9 +++- 3 files changed, 73 insertions(+), 60 deletions(-) diff --git a/composer.json b/composer.json index ace8c16..2aecae2 100644 --- a/composer.json +++ b/composer.json @@ -6,13 +6,13 @@ "require-dev": { "php": "^7.0", "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4", - "phpunit/phpunit": "6.2.3", - "wimg/php-compatibility": "^8.1", + "phpunit/phpunit": "^6.5", + "wimg/php-compatibility": "^9.0", "woocommerce/woocommerce": "dev-master", "woocommerce/woocommerce-git-hooks": "*", - "woocommerce/woocommerce-sniffs": "^0.0.1", + "woocommerce/woocommerce-sniffs": "^0.0.2", "wp-cli/wp-cli": "^2.0", - "wp-coding-standards/wpcs": "^0.14" + "wp-coding-standards/wpcs": "^1.1" }, "autoload-dev": { "classmap": [ diff --git a/composer.lock b/composer.lock index ca5b992..cf9115c 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": "5c7399037a53639b7a6d968b002d095d", + "content-hash": "76870c85fcb157ea6f0d20337614ada4", "packages": [], "packages-dev": [ { @@ -908,16 +908,16 @@ }, { "name": "phpunit/phpunit", - "version": "6.2.3", + "version": "6.5.13", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "fa5711d0559fc4b64deba0702be52d41434cbcb7" + "reference": "0973426fb012359b2f18d3bd1e90ef1172839693" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fa5711d0559fc4b64deba0702be52d41434cbcb7", - "reference": "fa5711d0559fc4b64deba0702be52d41434cbcb7", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/0973426fb012359b2f18d3bd1e90ef1172839693", + "reference": "0973426fb012359b2f18d3bd1e90ef1172839693", "shasum": "" }, "require": { @@ -926,24 +926,24 @@ "ext-libxml": "*", "ext-mbstring": "*", "ext-xml": "*", - "myclabs/deep-copy": "^1.3", + "myclabs/deep-copy": "^1.6.1", "phar-io/manifest": "^1.0.1", "phar-io/version": "^1.0", "php": "^7.0", "phpspec/prophecy": "^1.7", - "phpunit/php-code-coverage": "^5.2", - "phpunit/php-file-iterator": "^1.4", - "phpunit/php-text-template": "^1.2", - "phpunit/php-timer": "^1.0.6", - "phpunit/phpunit-mock-objects": "^4.0", - "sebastian/comparator": "^2.0", - "sebastian/diff": "^1.4.3 || ^2.0", - "sebastian/environment": "^3.0.2", + "phpunit/php-code-coverage": "^5.3", + "phpunit/php-file-iterator": "^1.4.3", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-timer": "^1.0.9", + "phpunit/phpunit-mock-objects": "^5.0.9", + "sebastian/comparator": "^2.1", + "sebastian/diff": "^2.0", + "sebastian/environment": "^3.1", "sebastian/exporter": "^3.1", - "sebastian/global-state": "^1.1 || ^2.0", - "sebastian/object-enumerator": "^3.0.2", + "sebastian/global-state": "^2.0", + "sebastian/object-enumerator": "^3.0.3", "sebastian/resource-operations": "^1.0", - "sebastian/version": "^2.0" + "sebastian/version": "^2.0.1" }, "conflict": { "phpdocumentor/reflection-docblock": "3.0.2", @@ -962,7 +962,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "6.2.x-dev" + "dev-master": "6.5.x-dev" } }, "autoload": { @@ -988,33 +988,33 @@ "testing", "xunit" ], - "time": "2017-07-03T15:54:24+00:00" + "time": "2018-09-08T15:10:43+00:00" }, { "name": "phpunit/phpunit-mock-objects", - "version": "4.0.4", + "version": "5.0.10", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "2f789b59ab89669015ad984afa350c4ec577ade0" + "reference": "cd1cf05c553ecfec36b170070573e540b67d3f1f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/2f789b59ab89669015ad984afa350c4ec577ade0", - "reference": "2f789b59ab89669015ad984afa350c4ec577ade0", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/cd1cf05c553ecfec36b170070573e540b67d3f1f", + "reference": "cd1cf05c553ecfec36b170070573e540b67d3f1f", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.5", "php": "^7.0", "phpunit/php-text-template": "^1.2.1", - "sebastian/exporter": "^3.0" + "sebastian/exporter": "^3.1" }, "conflict": { "phpunit/phpunit": "<6.0" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^6.5.11" }, "suggest": { "ext-soap": "*" @@ -1022,7 +1022,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0.x-dev" + "dev-master": "5.0.x-dev" } }, "autoload": { @@ -1037,7 +1037,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -1047,7 +1047,7 @@ "mock", "xunit" ], - "time": "2017-08-03T14:08:16+00:00" + "time": "2018-08-09T05:50:03+00:00" }, { "name": "ramsey/array_column", @@ -1894,16 +1894,16 @@ }, { "name": "wimg/php-compatibility", - "version": "8.2.0", + "version": "9.0.0", "source": { "type": "git", "url": "https://github.com/PHPCompatibility/PHPCompatibility.git", - "reference": "eaf613c1a8265bcfd7b0ab690783f2aef519f78a" + "reference": "e9f4047e5edf53c88f36f1dafc0d49454ce13e25" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibility/zipball/eaf613c1a8265bcfd7b0ab690783f2aef519f78a", - "reference": "eaf613c1a8265bcfd7b0ab690783f2aef519f78a", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibility/zipball/e9f4047e5edf53c88f36f1dafc0d49454ce13e25", + "reference": "e9f4047e5edf53c88f36f1dafc0d49454ce13e25", "shasum": "" }, "require": { @@ -1921,29 +1921,34 @@ "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." }, "type": "phpcodesniffer-standard", - "autoload": { - "psr-4": { - "PHPCompatibility\\": "PHPCompatibility/" - } - }, "notification-url": "https://packagist.org/downloads/", "license": [ "LGPL-3.0-or-later" ], "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/PHPCompatibility/PHPCompatibility/graphs/contributors" + }, { "name": "Wim Godden", + "homepage": "https://github.com/wimg", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", "role": "lead" } ], - "description": "A set of sniffs for PHP_CodeSniffer that checks for PHP version compatibility.", + "description": "A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.", "homepage": "http://techblog.wimgodden.be/tag/codesniffer/", "keywords": [ "compatibility", "phpcs", "standards" ], - "time": "2018-07-17T13:42:26+00:00" + "time": "2018-10-07T17:38:02+00:00" }, { "name": "woocommerce/woocommerce", @@ -1951,12 +1956,12 @@ "source": { "type": "git", "url": "https://github.com/woocommerce/woocommerce.git", - "reference": "c12bb2dac52badd4b46146380a3054ddfbf41253" + "reference": "4ad0fbd5217e8fc7ecb454fbed049b6092b28464" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/woocommerce/woocommerce/zipball/c12bb2dac52badd4b46146380a3054ddfbf41253", - "reference": "c12bb2dac52badd4b46146380a3054ddfbf41253", + "url": "https://api.github.com/repos/woocommerce/woocommerce/zipball/4ad0fbd5217e8fc7ecb454fbed049b6092b28464", + "reference": "4ad0fbd5217e8fc7ecb454fbed049b6092b28464", "shasum": "" }, "require": { @@ -1987,7 +1992,7 @@ ], "description": "An eCommerce toolkit that helps you sell anything. Beautifully.", "homepage": "https://woocommerce.com/", - "time": "2018-10-05T17:50:56+00:00" + "time": "2018-10-23T21:41:08+00:00" }, { "name": "woocommerce/woocommerce-git-hooks", @@ -2024,16 +2029,16 @@ }, { "name": "woocommerce/woocommerce-sniffs", - "version": "0.0.1", + "version": "0.0.2", "source": { "type": "git", "url": "https://github.com/woocommerce/woocommerce-sniffs.git", - "reference": "383d5b361c1d7532ae1ca6156fd7619fd37bbc05" + "reference": "2890fd5d98b318f62acb42f2b5cd6d02627cfd82" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/woocommerce/woocommerce-sniffs/zipball/383d5b361c1d7532ae1ca6156fd7619fd37bbc05", - "reference": "383d5b361c1d7532ae1ca6156fd7619fd37bbc05", + "url": "https://api.github.com/repos/woocommerce/woocommerce-sniffs/zipball/2890fd5d98b318f62acb42f2b5cd6d02627cfd82", + "reference": "2890fd5d98b318f62acb42f2b5cd6d02627cfd82", "shasum": "" }, "require": { @@ -2061,7 +2066,7 @@ "woocommerce", "wordpress" ], - "time": "2017-12-21T22:52:52+00:00" + "time": "2018-03-22T18:39:19+00:00" }, { "name": "wp-cli/mustangostang-spyc", @@ -2221,24 +2226,27 @@ }, { "name": "wp-coding-standards/wpcs", - "version": "0.14.1", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git", - "reference": "cf6b310caad735816caef7573295f8a534374706" + "reference": "46d42828ce7355d8b3776e3171f2bda892d179b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/zipball/cf6b310caad735816caef7573295f8a534374706", - "reference": "cf6b310caad735816caef7573295f8a534374706", + "url": "https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/zipball/46d42828ce7355d8b3776e3171f2bda892d179b4", + "reference": "46d42828ce7355d8b3776e3171f2bda892d179b4", "shasum": "" }, "require": { "php": ">=5.3", "squizlabs/php_codesniffer": "^2.9.0 || ^3.0.2" }, + "require-dev": { + "phpcompatibility/php-compatibility": "*" + }, "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3" + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." }, "type": "phpcodesniffer-standard", "notification-url": "https://packagist.org/downloads/", @@ -2257,7 +2265,7 @@ "standards", "wordpress" ], - "time": "2018-02-16T01:57:48+00:00" + "time": "2018-09-10T17:04:05+00:00" } ], "aliases": [], diff --git a/phpcs.xml.dist b/phpcs.xml.dist index c33b03c..fef28dc 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -2,7 +2,10 @@ Generally-applicable sniffs for WordPress plugins - + + + + @@ -21,7 +24,9 @@ - . + ./includes + ./tests + woocommerce-custom-orders-table.php From 5395341e3ccc10da1f03a9fadb0c1b05adf059b1 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Wed, 24 Oct 2018 19:25:52 +0000 Subject: [PATCH 11/28] Don't rely on `empty()` to verify that the results of `array_diff()` are empty, as this breaks on PHP < 5.5. Instead, rely on implicit type juggling within the conditional (at least until we and/or WooCommerce and/or WordPress can safely drop old versions of PHP). --- includes/class-woocommerce-custom-orders-table-cli.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-woocommerce-custom-orders-table-cli.php b/includes/class-woocommerce-custom-orders-table-cli.php index 0390845..ab9791b 100644 --- a/includes/class-woocommerce-custom-orders-table-cli.php +++ b/includes/class-woocommerce-custom-orders-table-cli.php @@ -117,7 +117,7 @@ public function migrate( $args = array(), $assoc_args = array() ) { $order_data = $wpdb->get_col( $order_query ); // WPCS: Unprepared SQL ok, DB call ok. $batch_count = 1; - while ( ! empty( array_diff( $order_data, $this->skipped_ids ) ) ) { + while ( array_diff( $order_data, $this->skipped_ids ) ) { WP_CLI::debug( sprintf( /* Translators: %1$d is the batch number, %2$d is the batch size. */ __( 'Beginning batch #%1$d (%2$d orders/batch).', 'woocommerce-custom-orders-table' ), From a32c101855ad4cb109cc5a65a1941d6224895892 Mon Sep 17 00:00:00 2001 From: Caleb Stauffer <> Date: Thu, 8 Nov 2018 23:08:07 -0500 Subject: [PATCH 12/28] store order key as null if empty --- includes/class-wc-order-data-store-custom-table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-wc-order-data-store-custom-table.php b/includes/class-wc-order-data-store-custom-table.php index 3dbdab3..4c60a34 100644 --- a/includes/class-wc-order-data-store-custom-table.php +++ b/includes/class-wc-order-data-store-custom-table.php @@ -126,7 +126,7 @@ protected function update_post_meta( &$order ) { $changes = array(); $order_data = array( 'order_id' => $order->get_id( 'edit' ), - 'order_key' => $order->get_order_key( 'edit' ), + 'order_key' => $order->get_order_key( 'edit' ) ?: null, 'customer_id' => $order->get_customer_id( 'edit' ), 'payment_method' => $order->get_payment_method( 'edit' ), 'payment_method_title' => $order->get_payment_method_title( 'edit' ), From 0d47f6151bda49a9378c8bde47c4d73c7584ff33 Mon Sep 17 00:00:00 2001 From: Caleb Stauffer Date: Fri, 9 Nov 2018 09:51:56 -0500 Subject: [PATCH 13/28] support PHP 5.2 --- includes/class-wc-order-data-store-custom-table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-wc-order-data-store-custom-table.php b/includes/class-wc-order-data-store-custom-table.php index 4c60a34..2365f1d 100644 --- a/includes/class-wc-order-data-store-custom-table.php +++ b/includes/class-wc-order-data-store-custom-table.php @@ -126,7 +126,7 @@ protected function update_post_meta( &$order ) { $changes = array(); $order_data = array( 'order_id' => $order->get_id( 'edit' ), - 'order_key' => $order->get_order_key( 'edit' ) ?: null, + 'order_key' => $order->get_order_key( 'edit' ) ? $order->get_order_key( 'edit' ) : null, 'customer_id' => $order->get_customer_id( 'edit' ), 'payment_method' => $order->get_payment_method( 'edit' ), 'payment_method_title' => $order->get_payment_method_title( 'edit' ), From 391713e2a1bff253aa9a337432063251484da994 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Fri, 14 Dec 2018 15:08:24 +0000 Subject: [PATCH 14/28] Instead of calling get_order_key() twice, call it once and cache it in a variable --- includes/class-wc-order-data-store-custom-table.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/class-wc-order-data-store-custom-table.php b/includes/class-wc-order-data-store-custom-table.php index 2365f1d..761468a 100644 --- a/includes/class-wc-order-data-store-custom-table.php +++ b/includes/class-wc-order-data-store-custom-table.php @@ -124,9 +124,10 @@ protected function update_post_meta( &$order ) { $table = wc_custom_order_table()->get_table_name(); $changes = array(); + $order_key = $order->get_order_key( 'edit' ); $order_data = array( 'order_id' => $order->get_id( 'edit' ), - 'order_key' => $order->get_order_key( 'edit' ) ? $order->get_order_key( 'edit' ) : null, + 'order_key' => $order_key ? $order_key : null, 'customer_id' => $order->get_customer_id( 'edit' ), 'payment_method' => $order->get_payment_method( 'edit' ), 'payment_method_title' => $order->get_payment_method_title( 'edit' ), From 3bdc01eb625238c5becb0c6689e28a72213be045 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Fri, 14 Dec 2018 15:11:01 +0000 Subject: [PATCH 15/28] Adjust the logic in tests around duplicate order keys. Two tests, `DataStoreTest::test_populate_from_meta_handles_errors()` and `CLITest::test_migrate_skips_on_database_error()`, were explicitly setting order keys to empty strings, which is being fixed in #97. This commit changes the tests to use generic (but still identical) order key values. --- tests/test-cli.php | 6 +++--- tests/test-order-data-store.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test-cli.php b/tests/test-cli.php index c7e12f8..d773685 100644 --- a/tests/test-cli.php +++ b/tests/test-cli.php @@ -119,16 +119,16 @@ public function test_migrate_skips_on_database_error() { $this->toggle_use_custom_table( false ); $order1 = WC_Helper_Order::create_order(); - $order1->set_order_key( '' ); + $order1->set_order_key( 'some-key' ); $order1->save(); $order2 = WC_Helper_Order::create_order(); - $order2->set_order_key( '' ); + $order2->set_order_key( 'some-key' ); $order2->save(); $this->toggle_use_custom_table( true ); $this->cli->migrate(); - $this->cli->assertReceivedMessageContaining( "Duplicate entry '' for key 'order_key'", 'warning' ); + $this->cli->assertReceivedMessageContaining( "Duplicate entry 'some-key' for key 'order_key'", 'warning' ); } public function test_migrate_catches_infinite_loops() { diff --git a/tests/test-order-data-store.php b/tests/test-order-data-store.php index 21bb012..f9d6132 100644 --- a/tests/test-order-data-store.php +++ b/tests/test-order-data-store.php @@ -268,10 +268,10 @@ public function test_populate_from_meta_handles_errors() { $this->toggle_use_custom_table( false ); $order1 = WC_Helper_Order::create_order(); - $order1->set_order_key( '' ); + $order1->set_order_key( 'some-key' ); $order1->save(); $order2 = WC_Helper_Order::create_order(); - $order2->set_order_key( '' ); + $order2->set_order_key( 'some-key' ); $order2->save(); $this->toggle_use_custom_table( true ); From ae34d1eb01a8af2ce5880497093c3f62cb876574 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Fri, 14 Dec 2018 15:26:18 +0000 Subject: [PATCH 16/28] Add a test explicitly verifying that this addresses both #69 and #96 --- tests/test-cli.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/test-cli.php b/tests/test-cli.php index d773685..88e1d7d 100644 --- a/tests/test-cli.php +++ b/tests/test-cli.php @@ -234,6 +234,29 @@ public function test_migrate_with_duplicate_ids() { $this->assertEquals( 1, $this->count_orders_in_table_with_ids( array( $order_id ) ) ); } + /** + * @ticket https://github.com/liquidweb/woocommerce-custom-orders-table/issues/69 + * @ticket https://github.com/liquidweb/woocommerce-custom-orders-table/issues/96 + */ + public function test_migrate_with_duplicate_null_order_ids() { + $this->toggle_use_custom_table( false ); + $order1 = WC_Helper_Order::create_order(); + $order1->set_order_key( '' ); + $order1->save(); + $order2 = WC_Helper_Order::create_order(); + $order2->set_order_key( '' ); + $order2->save(); + $this->toggle_use_custom_table( true ); + + $this->cli->migrate(); + + $this->assertSame( + 2, + $this->count_orders_in_table_with_ids( array( $order1->get_id(), $order2->get_id() ) ), + 'Two distinct orders can share a NULL order_key.' + ); + } + public function test_migrate_aborts_if_no_orders_require_migration() { $this->assertSame( 0, $this->cli->count(), 'Expected to start with 0 orders.' ); From c98dc68a8128d3d7a4adffc15e058f63b9d48a5e Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Fri, 14 Dec 2018 15:36:59 +0000 Subject: [PATCH 17/28] Keep .DS_Store files out of the repository --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 22fa3f5..a9bcc48 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ tests/coverage vendor +*.DS_Store From a13b422c92efbb1a9787aee44685975e85c5499a Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Fri, 14 Dec 2018 15:40:23 +0000 Subject: [PATCH 18/28] Raise the assumed PHP version to 7.2 and update Composer dependencies --- composer.json | 2 +- composer.lock | 80 +++++++++++++++++++++++++-------------------------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/composer.json b/composer.json index 2aecae2..2b12b56 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,7 @@ "config": { "sort-packages": true, "platform": { - "php": "7.0" + "php": "7.2" } }, "extra": { diff --git a/composer.lock b/composer.lock index cf9115c..5dd93c8 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": "76870c85fcb157ea6f0d20337614ada4", + "content-hash": "e95ba793159ad2671042b2de7ab36f77", "packages": [], "packages-dev": [ { @@ -197,32 +197,32 @@ }, { "name": "doctrine/instantiator", - "version": "1.0.5", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" + "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", - "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", + "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", "shasum": "" }, "require": { - "php": ">=5.3,<8.0-DEV" + "php": "^7.1" }, "require-dev": { "athletic/athletic": "~0.1.8", "ext-pdo": "*", "ext-phar": "*", - "phpunit/phpunit": "~4.0", - "squizlabs/php_codesniffer": "~2.0" + "phpunit/phpunit": "^6.2.3", + "squizlabs/php_codesniffer": "^3.0.2" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.2.x-dev" } }, "autoload": { @@ -247,7 +247,7 @@ "constructor", "instantiate" ], - "time": "2015-06-14T21:17:01+00:00" + "time": "2017-07-22T11:58:36+00:00" }, { "name": "mustache/mustache", @@ -297,25 +297,28 @@ }, { "name": "myclabs/deep-copy", - "version": "1.7.0", + "version": "1.8.1", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e" + "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", - "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", + "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0" + "php": "^7.1" + }, + "replace": { + "myclabs/deep-copy": "self.version" }, "require-dev": { "doctrine/collections": "^1.0", "doctrine/common": "^2.6", - "phpunit/phpunit": "^4.1" + "phpunit/phpunit": "^7.1" }, "type": "library", "autoload": { @@ -338,7 +341,7 @@ "object", "object graph" ], - "time": "2017-10-19T19:58:43+00:00" + "time": "2018-06-11T23:09:50+00:00" }, { "name": "phar-io/manifest", @@ -1755,25 +1758,25 @@ }, { "name": "symfony/finder", - "version": "v3.3.6", + "version": "v4.2.1", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "baea7f66d30854ad32988c11a09d7ffd485810c4" + "reference": "e53d477d7b5c4982d0e1bfd2298dbee63d01441d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/baea7f66d30854ad32988c11a09d7ffd485810c4", - "reference": "baea7f66d30854ad32988c11a09d7ffd485810c4", + "url": "https://api.github.com/repos/symfony/finder/zipball/e53d477d7b5c4982d0e1bfd2298dbee63d01441d", + "reference": "e53d477d7b5c4982d0e1bfd2298dbee63d01441d", "shasum": "" }, "require": { - "php": ">=5.5.9" + "php": "^7.1.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.3-dev" + "dev-master": "4.2-dev" } }, "autoload": { @@ -1800,7 +1803,7 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2017-06-01T21:01:25+00:00" + "time": "2018-11-11T19:52:12+00:00" }, { "name": "theseer/tokenizer", @@ -1948,6 +1951,7 @@ "phpcs", "standards" ], + "abandoned": "phpcompatibility/php-compatibility", "time": "2018-10-07T17:38:02+00:00" }, { @@ -1956,12 +1960,12 @@ "source": { "type": "git", "url": "https://github.com/woocommerce/woocommerce.git", - "reference": "4ad0fbd5217e8fc7ecb454fbed049b6092b28464" + "reference": "f13a0bc9eb49dad87b93e5b3ac019838e43b1404" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/woocommerce/woocommerce/zipball/4ad0fbd5217e8fc7ecb454fbed049b6092b28464", - "reference": "4ad0fbd5217e8fc7ecb454fbed049b6092b28464", + "url": "https://api.github.com/repos/woocommerce/woocommerce/zipball/f13a0bc9eb49dad87b93e5b3ac019838e43b1404", + "reference": "f13a0bc9eb49dad87b93e5b3ac019838e43b1404", "shasum": "" }, "require": { @@ -1969,14 +1973,10 @@ }, "require-dev": { "apigen/apigen": "^4", - "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3", "nette/utils": "~2.3.0", "phpunit/phpunit": "6.*", - "squizlabs/php_codesniffer": "*", - "wimg/php-compatibility": "^8.0", "woocommerce/woocommerce-git-hooks": "*", - "woocommerce/woocommerce-sniffs": "*", - "wp-coding-standards/wpcs": "^0.14" + "woocommerce/woocommerce-sniffs": "^0.0.5" }, "type": "wordpress-plugin", "extra": { @@ -1992,7 +1992,7 @@ ], "description": "An eCommerce toolkit that helps you sell anything. Beautifully.", "homepage": "https://woocommerce.com/", - "time": "2018-10-23T21:41:08+00:00" + "time": "2018-12-13T19:15:14+00:00" }, { "name": "woocommerce/woocommerce-git-hooks", @@ -2226,16 +2226,16 @@ }, { "name": "wp-coding-standards/wpcs", - "version": "1.1.0", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git", - "reference": "46d42828ce7355d8b3776e3171f2bda892d179b4" + "reference": "7aa217ab38156c5cb4eae0f04ae376027c407a9b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/zipball/46d42828ce7355d8b3776e3171f2bda892d179b4", - "reference": "46d42828ce7355d8b3776e3171f2bda892d179b4", + "url": "https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/zipball/7aa217ab38156c5cb4eae0f04ae376027c407a9b", + "reference": "7aa217ab38156c5cb4eae0f04ae376027c407a9b", "shasum": "" }, "require": { @@ -2243,7 +2243,7 @@ "squizlabs/php_codesniffer": "^2.9.0 || ^3.0.2" }, "require-dev": { - "phpcompatibility/php-compatibility": "*" + "phpcompatibility/php-compatibility": "^9.0" }, "suggest": { "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." @@ -2265,7 +2265,7 @@ "standards", "wordpress" ], - "time": "2018-09-10T17:04:05+00:00" + "time": "2018-11-12T10:13:12+00:00" } ], "aliases": [], @@ -2280,6 +2280,6 @@ "php": "^7.0" }, "platform-overrides": { - "php": "7.0" + "php": "7.2" } } From cf06f59c72ccc2fafa2505de2cd041bf242ac623 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Fri, 14 Dec 2018 15:47:29 +0000 Subject: [PATCH 19/28] Add PHP 7.3 and WooCommerce 3.5.2 to the testing matrix, as well as a new 'Bleeding Edge' case --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index df74612..b65c96a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,12 +10,14 @@ cache: - $HOME/.composer/cache php: + - 7.3 - 7.2 - 7.1 - 7.0 env: - WP_VERSION=latest WC_VERSION=latest + - WP_VERSION=latest WC_VERSION=3.5.2 - WP_VERSION=latest WC_VERSION=3.4.5 - WP_VERSION=latest WC_VERSION=3.3.5 - WP_VERSION=latest WC_VERSION=3.2.6 @@ -26,10 +28,13 @@ matrix: - name: Coding Standards php: 7.2 env: WP_VERSION=trunk WC_VERSION=latest RUN_PHPCS=1 - # Generate code coverage from PHP 7.1. + # Generate code coverage from PHP 7.2. - name: Code Coverage php: 7.2 env: WP_VERSION=latest WP_MULTISITE=0 WC_VERSION=latest RUN_CODE_COVERAGE=1 + - name: Bleeding Edge + php: 7.3 + env: WP_VERSION=trunk WP_MULTISITE=0 WC_VERSION=latest allow_failures: - name: Code Coverage From f5520f706ad0283864e2524c6d540b9c94c4ea2e Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Fri, 14 Dec 2018 11:04:51 -0500 Subject: [PATCH 20/28] Raise the 'WC tested up to' version to 3.5.2 --- woocommerce-custom-orders-table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/woocommerce-custom-orders-table.php b/woocommerce-custom-orders-table.php index 06ae9cc..8fc1fc9 100644 --- a/woocommerce-custom-orders-table.php +++ b/woocommerce-custom-orders-table.php @@ -10,7 +10,7 @@ * License URI: https://www.gnu.org/licenses/gpl-2.0.html * * WC requires at least: 3.2.6 - * WC tested up to: 3.5.0 + * WC tested up to: 3.5.2 * * @package WooCommerce_Custom_Orders_Table * @author Liquid Web From 08e1fe4612ab2244708ced8891eacaaaa6e5296d Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Fri, 14 Dec 2018 11:21:42 -0500 Subject: [PATCH 21/28] Add a description for 'composer test-coverage' --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index 2b12b56..f85fbc2 100644 --- a/composer.json +++ b/composer.json @@ -40,6 +40,9 @@ "phpunit --testsuite=plugin --coverage-html=tests/coverage" ] }, + "scripts-descriptions": { + "test-coverage": "Generate test coverage for the plugin" + }, "config": { "sort-packages": true, "platform": { From 7097ed5c08b2f3518287a720674ffab69cd8f433 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Fri, 14 Dec 2018 12:37:00 -0500 Subject: [PATCH 22/28] Update the Travis testing matrix, using the following criteria: - The "WC Requires At Least" is 3.2.6, so that's the lowest we need to go - WordPress < 5.0 doesn't officially support PHP 7.3. - WordPress 5.0 requires at least WooCommerce 3.5.1 --- .travis.yml | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index b65c96a..60cbbd9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,25 +17,37 @@ php: env: - WP_VERSION=latest WC_VERSION=latest - - WP_VERSION=latest WC_VERSION=3.5.2 - - WP_VERSION=latest WC_VERSION=3.4.5 - - WP_VERSION=latest WC_VERSION=3.3.5 - - WP_VERSION=latest WC_VERSION=3.2.6 + - WP_VERSION=4.9.9 WC_VERSION=latest + - WP_VERSION=4.9.9 WC_VERSION=3.4.7 + - WP_VERSION=4.9.9 WC_VERSION=3.3.5 + - WP_VERSION=4.9.9 WC_VERSION=3.2.6 +# Considerations for the test matrix: +# +# - The "WC Requires At Least" is 3.2.6, so that's the lowest we need to go +# - WordPress < 5.0 doesn't officially support PHP 7.3. +# - WordPress 5.0 requires at least WooCommerce 3.5.1 matrix: fast_finish: true include: - name: Coding Standards php: 7.2 - env: WP_VERSION=trunk WC_VERSION=latest RUN_PHPCS=1 - # Generate code coverage from PHP 7.2. + env: WP_VERSION=latest WC_VERSION=latest RUN_PHPCS=1 - name: Code Coverage php: 7.2 - env: WP_VERSION=latest WP_MULTISITE=0 WC_VERSION=latest RUN_CODE_COVERAGE=1 + env: WP_VERSION=latest WC_VERSION=latest RUN_CODE_COVERAGE=1 - name: Bleeding Edge php: 7.3 - env: WP_VERSION=trunk WP_MULTISITE=0 WC_VERSION=latest - + env: WP_VERSION=trunk WC_VERSION=latest + exclude: + - php: 7.3 + env: WP_VERSION=4.9.9 WC_VERSION=latest + - php: 7.3 + env: WP_VERSION=4.9.9 WC_VERSION=3.4.7 + - php: 7.3 + env: WP_VERSION=4.9.9 WC_VERSION=3.3.5 + - php: 7.3 + env: WP_VERSION=4.9.9 WC_VERSION=3.2.6 allow_failures: - name: Code Coverage php: 7.2 From 4af6c949c2c0e225da5602eacdd5ff5533906d4d Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Fri, 14 Dec 2018 17:47:53 +0000 Subject: [PATCH 23/28] Don't let Travis die if Xdebug isn't available to remove --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 60cbbd9..33c9999 100644 --- a/.travis.yml +++ b/.travis.yml @@ -61,7 +61,7 @@ before_script: chmod +x coveralls.phar mkdir -p build/logs fi - - phpenv config-rm xdebug.ini + - phpenv config-rm xdebug.ini || true - | if [[ ${GITHUB_AUTH_TOKEN} != '' ]]; then composer config -g github-oauth.github.com $GITHUB_AUTH_TOKEN From c284f5cdc4040d33839c277a05da5e913acdc605 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Fri, 14 Dec 2018 19:50:15 +0000 Subject: [PATCH 24/28] Don't let existing, invalid emails break migrations When setting the billing email address for an order via `$order->set_billing_email()`, WooCommerce verifies that the value evaluates as an email address. Since that value rarely (if ever) changes, users are only discovering that they have invalid emails in their databases when migrating into the custom orders table. This commit will use Reflection to force the value *as it exists today* into the custom orders table. Additionally, other tests that relied on invalid emails triggering a `WC_Data_Exception` have been updated. Fixes #98. --- .../class-woocommerce-custom-orders-table.php | 18 ++++++++++++++++++ tests/test-cli.php | 6 +++--- tests/test-core.php | 18 ++++++++++++++++++ tests/test-order-data-store.php | 16 +++++++++++++--- 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/includes/class-woocommerce-custom-orders-table.php b/includes/class-woocommerce-custom-orders-table.php index fff5aa7..f1b934f 100644 --- a/includes/class-woocommerce-custom-orders-table.php +++ b/includes/class-woocommerce-custom-orders-table.php @@ -160,6 +160,24 @@ public static function populate_order_from_post_meta( $order ) { case 'shipping_index': break; + /* + * Migration isn't the time to validate (and potentially throw exceptions); + * if it was accepted into WooCommerce core, let it persist. + * + * If we're unable to set an email address due to $order->set_billing_email(), + * try to circumvent the check by using reflection to call the protected + * $order->set_address_prop() method. + */ + case 'billing_email': + try { + $order->set_billing_email( $meta ); + } catch ( WC_Data_Exception $e ) { + $method = new ReflectionMethod( $order, 'set_address_prop' ); + $method->setAccessible( true ); + $method->invoke( $order, 'email', 'billing', $meta ); + } + break; + case 'prices_include_tax': $order->set_prices_include_tax( 'yes' === $meta ); break; diff --git a/tests/test-cli.php b/tests/test-cli.php index 88e1d7d..9acef21 100644 --- a/tests/test-cli.php +++ b/tests/test-cli.php @@ -204,8 +204,8 @@ public function test_migrate_handles_exceptions() { $order_ids = $this->generate_orders( 3 ); $this->toggle_use_custom_table( true ); - // Break the billing email on the first item. - update_post_meta( $order_ids[0], '_billing_email', 'this is not an email address' ); + // Set a duplicate order key for the middle order. + update_post_meta( $order_ids[1], '_order_key', get_post_meta( $order_ids[0], '_order_key' ) ); $this->cli->migrate(); @@ -215,7 +215,7 @@ public function test_migrate_handles_exceptions() { 'Expected to only see two orders in the custom table.' ); - $this->assertContains( $order_ids[0], $this->get_skipped_ids() ); + $this->assertContains( $order_ids[1], $this->get_skipped_ids() ); } public function test_migrate_with_duplicate_ids() { diff --git a/tests/test-core.php b/tests/test-core.php index aa7e7a1..b3bc9aa 100644 --- a/tests/test-core.php +++ b/tests/test-core.php @@ -15,6 +15,24 @@ public function test_order_row_exists() { $this->assertFalse( wc_custom_order_table()->row_exists( $order->get_id() + 1 ) ); } + /** + * @ticket https://github.com/liquidweb/woocommerce-custom-orders-table/issues/98 + */ + public function test_populate_order_from_post_meta_handles_invalid_billing_emails() { + $this->toggle_use_custom_table( false ); + $order = WC_Helper_Order::create_order(); + update_post_meta( $order->get_id(), '_billing_email', 'this is an invalid email address' ); + $this->toggle_use_custom_table( true ); + + WooCommerce_Custom_Orders_Table::populate_order_from_post_meta( $order ); + + $this->assertSame( + 'this is an invalid email address', + $order->get_billing_email(), + 'Don\'t let an invalid email address cause a migration failure.' + ); + } + public function test_migrate_to_post_meta() { $order = WC_Helper_Order::create_order(); $row = $this->get_order_row( $order->get_id() ); diff --git a/tests/test-order-data-store.php b/tests/test-order-data-store.php index f9d6132..7b6a888 100644 --- a/tests/test-order-data-store.php +++ b/tests/test-order-data-store.php @@ -287,13 +287,23 @@ public function test_populate_from_meta_handles_wc_data_exceptions() { $order = WC_Helper_Order::create_order(); $this->toggle_use_custom_table( true ); - // Give an invalid billing email. - update_post_meta( $order->get_id(), '_billing_email', 'this is not an email address' ); - // Refresh the instance. $order = wc_get_order( $order->get_id() ); + add_action( 'woocommerce_order_object_updated_props', array( $this, 'throw_wc_data_exception' ) ); + $this->assertInstanceOf( 'WP_Error', $order->get_data_store()->populate_from_meta( $order ) ); + + remove_action( 'woocommerce_order_object_updated_props', array( $this, 'throw_wc_data_exception' ) ); + } + + /** + * Hooked method that simply throws a WC_Data_Exception exception. + * + * @throws WC_Data_Exception + */ + public function throw_wc_data_exception() { + throw new WC_Data_Exception( 'test-data-exception', 'A sample WC_Data_Exception' ); } /** From cd688057d1dcdd704b7b2000a1676328c393b1c6 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Fri, 14 Dec 2018 19:56:53 +0000 Subject: [PATCH 25/28] Permit the bleeding edge tests to fail, as there will occasionally be bugs in WordPress trunk --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 33c9999..f62f61c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,6 +52,9 @@ matrix: - name: Code Coverage php: 7.2 env: WP_VERSION=latest WP_MULTISITE=0 WC_VERSION=latest RUN_CODE_COVERAGE=1 + - name: Bleeding Edge + php: 7.3 + env: WP_VERSION=trunk WC_VERSION=latest before_script: - export PATH="$HOME/.composer/vendor/bin:$PATH" From e88effdbd24672dda7c5d276575474b5f8541e15 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Fri, 14 Dec 2018 21:36:17 +0000 Subject: [PATCH 26/28] Ensure that the 'Code Coverage' job matches in allow_failures --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f62f61c..2545513 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,7 +51,7 @@ matrix: allow_failures: - name: Code Coverage php: 7.2 - env: WP_VERSION=latest WP_MULTISITE=0 WC_VERSION=latest RUN_CODE_COVERAGE=1 + env: WP_VERSION=latest WC_VERSION=latest RUN_CODE_COVERAGE=1 - name: Bleeding Edge php: 7.3 env: WP_VERSION=trunk WC_VERSION=latest From bd2ab0005ac66c97fa7392f2690d9087e766d8ac Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Fri, 14 Dec 2018 21:40:04 +0000 Subject: [PATCH 27/28] Update the changelog for version 1.0.0-rc2 --- CHANGELOG.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e39a47c..dffc45e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [Version 1.0.0 (Release Candidate 2)] - 2018-12-14 + +* Reduced overhead of PHP autoloader ([#86], props @schlessera). +* Converted the `customer_user_agent` column from `varchar(200)` to `text` ([#91]). +* Fixed an issue where `empty()` was being called on a non-variable, which causes a fatal error in PHP < 5.5 ([#94]). +* Prevented empty strings from being saved to the `order_key` column, which causes issues with the column's uniqueness constraint ([#101], props @crstauf). +* Fixed an issue where *existing* invalid emails in the system were causing migration errors as they were re-saved ([#104]). +* Updated Travis CI testing matrix to include WordPress 5.0 ([#103]). +* Repaired the generation of code coverage reports for Coveralls ([#87], [#88]). + ## [Version 1.0.0 (Release Candidate)] - 2018-09-25 * Major refactoring of the WP-CLI migration commands ([#61], [#79], [#81]). @@ -48,6 +58,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. [Unreleased]: https://github.com/liquidweb/woocommerce-order-tables/compare/master...develop +[Version 1.0.0 (Release Candidate 2)]: https://github.com/liquidweb/woocommerce-order-tables/releases/tag/v1.0.0-rc2 [Version 1.0.0 (Release Candidate)]: https://github.com/liquidweb/woocommerce-order-tables/releases/tag/v1.0.0-rc1 [Version 1.0.0 (Beta 3)]: https://github.com/liquidweb/woocommerce-order-tables/releases/tag/v1.0.0-beta.3 [Version 1.0.0 (Beta 2)]: https://github.com/liquidweb/woocommerce-order-tables/releases/tag/v1.0.0-beta.2 @@ -80,3 +91,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. [#81]: https://github.com/liquidweb/woocommerce-order-tables/pull/81 [#82]: https://github.com/liquidweb/woocommerce-order-tables/pull/82 [#84]: https://github.com/liquidweb/woocommerce-order-tables/pull/84 +[#86]: https://github.com/liquidweb/woocommerce-order-tables/pull/86 +[#87]: https://github.com/liquidweb/woocommerce-order-tables/pull/87 +[#88]: https://github.com/liquidweb/woocommerce-order-tables/pull/88 +[#91]: https://github.com/liquidweb/woocommerce-order-tables/pull/91 +[#94]: https://github.com/liquidweb/woocommerce-order-tables/pull/94 +[#101]: https://github.com/liquidweb/woocommerce-order-tables/pull/101 +[#103]: https://github.com/liquidweb/woocommerce-order-tables/pull/103 +[#104]: https://github.com/liquidweb/woocommerce-order-tables/pull/104 From ae34fa1708f8f7759dca5b9e2480f72639265a64 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Fri, 14 Dec 2018 21:41:20 +0000 Subject: [PATCH 28/28] Version bump to v1.0.0-rc2 --- woocommerce-custom-orders-table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/woocommerce-custom-orders-table.php b/woocommerce-custom-orders-table.php index 8fc1fc9..7aa68a5 100644 --- a/woocommerce-custom-orders-table.php +++ b/woocommerce-custom-orders-table.php @@ -3,7 +3,7 @@ * Plugin Name: WooCommerce - Custom Orders Table * Plugin URI: https://github.com/liquidweb/woocommerce-custom-orders-tables * Description: Store WooCommerce order data in a custom table for improved performance. - * Version: 1.0.0-rc1 + * Version: 1.0.0-rc2 * Author: Liquid Web * Author URI: https://www.liquidweb.com * License: GPL2