From 9e2e1388fffd06813562d227513c97e235f69e10 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Tue, 23 Jan 2018 17:59:21 +0000 Subject: [PATCH 01/17] Normalize @package tags and i18n text-domains --- includes/class-wc-custom-order-table-cli.php | 16 ++++++++-------- includes/class-wc-custom-order-table-install.php | 4 ++-- includes/class-wc-custom-order-table.php | 2 +- ...class-wc-customer-data-store-custom-table.php | 2 +- .../class-wc-order-data-store-custom-table.php | 2 +- tests/bootstrap.php | 6 +++--- tests/test-bootstrap.php | 2 +- tests/test-cli.php | 2 +- tests/test-data-store.php | 2 +- tests/test-installation.php | 2 +- tests/test-sample.php | 4 ++-- tests/testcase.php | 2 +- wc-custom-order-table.php | 6 +++--- 13 files changed, 26 insertions(+), 26 deletions(-) diff --git a/includes/class-wc-custom-order-table-cli.php b/includes/class-wc-custom-order-table-cli.php index 9ff0367..e34bc2c 100644 --- a/includes/class-wc-custom-order-table-cli.php +++ b/includes/class-wc-custom-order-table-cli.php @@ -2,7 +2,7 @@ /** * CLI Tool for migrating order data to/from custom table. * - * @package WooCommerce_Custom_Order_Tables + * @package WooCommerce_Custom_Orders_Table * @author Liquid Web */ @@ -36,7 +36,7 @@ public function count() { WP_CLI::log( sprintf( /* Translators: %1$d is the number of orders to be migrated. */ - _n( 'There is %1$d order to be migrated.', 'There are %1$d orders to be migrated.', $order_count, 'wc-custom-order-table' ), + _n( 'There is %1$d order to be migrated.', 'There are %1$d orders to be migrated.', $order_count, 'woocommerce-custom-orders-table' ), $order_count ) ); @@ -70,7 +70,7 @@ public function migrate( $args = array(), $assoc_args = array() ) { $order_count = $this->count(); if ( ! $order_count ) { - return WP_CLI::warning( __( 'There are no orders to migrate, aborting.', 'wc-custom-order-table' ) ); + return WP_CLI::warning( __( 'There are no orders to migrate, aborting.', 'woocommerce-custom-orders-table' ) ); } $assoc_args = wp_parse_args( $assoc_args, array( @@ -116,12 +116,12 @@ public function migrate( $args = array(), $assoc_args = array() ) { // Issue a warning if no orders were migrated. if ( ! $processed ) { - return WP_CLI::warning( __( 'No orders were migrated.', 'wc-custom-order-table' ) ); + return WP_CLI::warning( __( 'No orders were migrated.', 'woocommerce-custom-orders-table' ) ); } WP_CLI::success( sprintf( /* Translators: %1$d is the number of migrated orders. */ - _n( '%1$d order was migrated.', '%1$d orders were migrated.', $processed, 'wc-custom-order-table' ), + _n( '%1$d order was migrated.', '%1$d orders were migrated.', $processed, 'woocommerce-custom-orders-table' ), $processed ) ); } @@ -162,7 +162,7 @@ public function backfill( $args = array(), $assoc_args = array() ) { $order_count = $wpdb->get_var( 'SELECT COUNT(order_id) FROM ' . esc_sql( $order_table ) ); // WPCS: DB call ok. if ( ! $order_count ) { - return WP_CLI::warning( __( 'There are no orders to migrate, aborting.', 'wc-custom-order-table' ) ); + return WP_CLI::warning( __( 'There are no orders to migrate, aborting.', 'woocommerce-custom-orders-table' ) ); } $assoc_args = wp_parse_args( $assoc_args, array( @@ -195,12 +195,12 @@ public function backfill( $args = array(), $assoc_args = array() ) { // Issue a warning if no orders were migrated. if ( ! $processed ) { - return WP_CLI::warning( __( 'No orders were migrated.', 'wc-custom-order-table' ) ); + return WP_CLI::warning( __( 'No orders were migrated.', 'woocommerce-custom-orders-table' ) ); } WP_CLI::success( sprintf( /* Translators: %1$d is the number of migrated orders. */ - _n( '%1$d order was migrated.', '%1$d orders were migrated.', $processed, 'wc-custom-order-table' ), + _n( '%1$d order was migrated.', '%1$d orders were migrated.', $processed, 'woocommerce-custom-orders-table' ), $processed ) ); } diff --git a/includes/class-wc-custom-order-table-install.php b/includes/class-wc-custom-order-table-install.php index 03d37c9..e81b080 100644 --- a/includes/class-wc-custom-order-table-install.php +++ b/includes/class-wc-custom-order-table-install.php @@ -2,12 +2,12 @@ /** * Table installation procedure. * - * @package WooCommerce_Custom_Order_Tables + * @package WooCommerce_Custom_Orders_Table * @author Liquid Web */ /** - * Installer for WooCommerce Custom Order Tables. + * Installer for WooCommerce Custom Orders Table. * * Usage: * diff --git a/includes/class-wc-custom-order-table.php b/includes/class-wc-custom-order-table.php index ebb2812..d07ba58 100644 --- a/includes/class-wc-custom-order-table.php +++ b/includes/class-wc-custom-order-table.php @@ -2,7 +2,7 @@ /** * Core plugin functionality. * - * @package WooCommerce_Custom_Order_Tables + * @package WooCommerce_Custom_Orders_Table * @author Liquid Web */ diff --git a/includes/class-wc-customer-data-store-custom-table.php b/includes/class-wc-customer-data-store-custom-table.php index e322934..0762727 100644 --- a/includes/class-wc-customer-data-store-custom-table.php +++ b/includes/class-wc-customer-data-store-custom-table.php @@ -2,7 +2,7 @@ /** * WooCommerce customer data store. * - * @package WooCommerce_Custom_Order_Tables + * @package WooCommerce_Custom_Orders_Table * @author Liquid Web */ diff --git a/includes/class-wc-order-data-store-custom-table.php b/includes/class-wc-order-data-store-custom-table.php index f2124c3..f9d945a 100644 --- a/includes/class-wc-order-data-store-custom-table.php +++ b/includes/class-wc-order-data-store-custom-table.php @@ -2,7 +2,7 @@ /** * WooCommerce order data store. * - * @package WooCommerce_Custom_Order_Tables + * @package WooCommerce_Custom_Orders_Table * @author Liquid Web */ diff --git a/tests/bootstrap.php b/tests/bootstrap.php index e86d855..80beb89 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,10 +2,10 @@ /** * Bootstrap the PHPUnit test suite(s). * - * Since WooCommerce Custom Order Tables is meant to integrate seamlessly with WooCommerce itself, + * Since WooCommerce Custom Orders Table is meant to integrate seamlessly with WooCommerce itself, * the bootstrap relies heavily on the WooCommerce core test suite. * - * @package Woocommerce_Order_Tables + * @package WooCommerce_Custom_Orders_Table */ $_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib'; @@ -30,7 +30,7 @@ function _manually_load_plugin() { echo esc_html( sprintf( /* Translators: %1$s is the WooCommerce release being loaded. */ - __( 'Using WooCommerce %1$s.', 'wc-custom-order-table' ), + __( 'Using WooCommerce %1$s.', 'woocommerce-custom-orders-table' ), WC_VERSION ) ) . PHP_EOL; diff --git a/tests/test-bootstrap.php b/tests/test-bootstrap.php index f7ec170..48d369e 100644 --- a/tests/test-bootstrap.php +++ b/tests/test-bootstrap.php @@ -2,7 +2,7 @@ /** * Tests for the plugin bootstrapping. * - * @package Woocommerce_Order_Tables + * @package WooCommerce_Custom_Orders_Table * @author Liquid Web */ diff --git a/tests/test-cli.php b/tests/test-cli.php index f2d3eff..5da68f6 100644 --- a/tests/test-cli.php +++ b/tests/test-cli.php @@ -2,7 +2,7 @@ /** * Tests for the WP-CLI commands. * - * @package Woocommerce_Order_Tables + * @package WooCommerce_Custom_Orders_Table * @author Liquid Web */ diff --git a/tests/test-data-store.php b/tests/test-data-store.php index 701860b..54c8076 100644 --- a/tests/test-data-store.php +++ b/tests/test-data-store.php @@ -2,7 +2,7 @@ /** * Tests for the WC_Order_Data_Store_Custom_Table class. * - * @package Woocommerce_Order_Tables + * @package WooCommerce_Custom_Orders_Table * @author Liquid Web */ diff --git a/tests/test-installation.php b/tests/test-installation.php index 9e26787..84c0f27 100644 --- a/tests/test-installation.php +++ b/tests/test-installation.php @@ -2,7 +2,7 @@ /** * Tests for the plugin installation. * - * @package Woocommerce_Order_Tables + * @package WooCommerce_Custom_Orders_Table * @author Liquid Web */ diff --git a/tests/test-sample.php b/tests/test-sample.php index 7eba8e2..519f4c8 100644 --- a/tests/test-sample.php +++ b/tests/test-sample.php @@ -1,8 +1,8 @@ Date: Tue, 23 Jan 2018 18:05:38 +0000 Subject: [PATCH 02/17] Normalize the plugin name, and try to ensure that 'orders table' is used consistently (as opposed to 'order table', 'order tables', or 'orders tables') --- CONTRIBUTING.md | 8 ++++---- README.md | 8 ++++---- includes/class-wc-custom-order-table-cli.php | 8 ++++---- includes/class-wc-custom-order-table.php | 6 +++--- includes/class-wc-customer-data-store-custom-table.php | 2 +- includes/class-wc-order-data-store-custom-table.php | 2 +- tests/testcase.php | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cc9a576..a76b07e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ -# Contributing to WooCommerce Custom Order Tables +# Contributing to WooCommerce Custom Orders Table -Thank you for your interest in WooCommerce Custom Order Tables! +Thank you for your interest in WooCommerce Custom Orders Table! ## Reporting bugs and/or suggesting new features @@ -44,9 +44,9 @@ Once master has been updated, the release should be tagged, then `master` should ### Unit testing -WooCommerce Custom Order Tables uses [the WordPress core testing suite](https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/) to provide automated tests for its functionality. +WooCommerce Custom Orders Table uses [the WordPress core testing suite](https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/) to provide automated tests for its functionality. -When submitting pull requests, please include relevant tests for your new features and bugfixes. This helps prevent regressions in future iterations of the plugin, and helps instill confidence in store owners using this to enhance their WooCommerce stores. +When submitting pull requests, please include relevant tests for your new features and bug-fixes. This helps prevent regressions in future iterations of the plugin, and helps instill confidence in store owners using this to enhance their WooCommerce stores. #### Test coverage diff --git a/README.md b/README.md index 85a282a..8219759 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# WooCommerce Order Tables +# WooCommerce Custom Orders Table [![Build Status](https://travis-ci.org/liquidweb/woocommerce-order-tables.svg?branch=fix%2Ftravis-config)](https://travis-ci.org/liquidweb/woocommerce-order-tables) @@ -10,7 +10,7 @@ WooCommerce even with CRUD classes in core, still uses a custom post type for or ### Here's how WooCommerce saves more than 40 custom fields per order— including those from plugins— inside the wp_postmeta table. If your store gets ~40 per day, that's 1600 rows (40 * 40) added to the postmeta table in a day. -In one month that number can be 48,000 new rows (1600 * 30) added to your postmeta table. The more rows in a table the longer it will take for a query to execute. WooCommerce Order Tables creates a new table for WooCommerce orders which would cut that number tremendously by making each custom field into a column so that 1 order = 1 row. +In one month that number can be 48,000 new rows (1600 * 30) added to your postmeta table. The more rows in a table the longer it will take for a query to execute. WooCommerce Custom Orders Table creates a new table for WooCommerce orders which would cut that number tremendously by making each custom field into a column so that 1 order = 1 row. ## Installation This plugin uses a Composer autoloader. If you are working with code from the `master` branch in a development environment, the autoloader needs to be generated in order for the plugin to work. After cloning this repository, run `composer install` in the root directory of the plugin. @@ -25,7 +25,7 @@ The easiest way to accomplish this is via [WP-CLI](http://wp-cli.org/), and the ### Counting the orders to be migrated -If you'd like to see the number of orders that have yet to be moved into the order table, you can quickly retrieve this value with the `count` command: +If you'd like to see the number of orders that have yet to be moved into the orders table, you can quickly retrieve this value with the `count` command: ``` $ wp wc-order-table count @@ -51,7 +51,7 @@ Orders are queried in batches (determined via the `--batch-size` option) in orde ### Copying data from the orders table into post meta -If you require the post meta fields to be present (or are removing the custom order table plugin), you may rollback the migration at any time with the `backfill` command. +If you require the post meta fields to be present (or are removing the custom orders table plugin), you may rollback the migration at any time with the `backfill` command. ``` $ wp wc-order-table backfill diff --git a/includes/class-wc-custom-order-table-cli.php b/includes/class-wc-custom-order-table-cli.php index e34bc2c..1ab5fa6 100644 --- a/includes/class-wc-custom-order-table-cli.php +++ b/includes/class-wc-custom-order-table-cli.php @@ -7,12 +7,12 @@ */ /** - * Manages the contents of the WooCommerce order table. + * Manages the contents of the WooCommerce orders table. */ class WC_Custom_Order_Table_CLI extends WP_CLI_Command { /** - * Count how many orders have yet to be migrated into the custom order table. + * Count how many orders have yet to be migrated into the custom orders table. * * ## EXAMPLES * @@ -44,7 +44,7 @@ public function count() { } /** - * Migrate order data to the custom order table. + * Migrate order data to the custom orders table. * * ## OPTIONS * @@ -130,7 +130,7 @@ public function migrate( $args = array(), $assoc_args = array() ) { * Copy order data into the postmeta table. * * Note that this could dramatically increase the size of your postmeta table, but is recommended - * if you wish to stop using the custom order table plugin. + * if you wish to stop using the custom orders table plugin. * * ## OPTIONS * diff --git a/includes/class-wc-custom-order-table.php b/includes/class-wc-custom-order-table.php index d07ba58..eb047ca 100644 --- a/includes/class-wc-custom-order-table.php +++ b/includes/class-wc-custom-order-table.php @@ -7,7 +7,7 @@ */ /** - * Core functionality for WooCommerce Custom Order Tables. + * Core functionality for WooCommerce Custom Orders Table. */ class WC_Custom_Order_Table { @@ -39,13 +39,13 @@ public function setup() { } /** - * Retrieve the WooCommerce order table name. + * Retrieve the WooCommerce orders table name. * * @return string The database table name. */ public function get_table_name() { /** - * Filter the WooCommerce order table name. + * Filter the WooCommerce orders table name. * * @param string $table The WooCommerce orders table name. */ diff --git a/includes/class-wc-customer-data-store-custom-table.php b/includes/class-wc-customer-data-store-custom-table.php index 0762727..7bc8a8f 100644 --- a/includes/class-wc-customer-data-store-custom-table.php +++ b/includes/class-wc-customer-data-store-custom-table.php @@ -8,7 +8,7 @@ /** * Extend the WC_Order_Data_Store_CPT class in order to overload methods that directly query the - * postmeta tables. + * postmeta table. */ class WC_Customer_Data_Store_Custom_Table extends WC_Customer_Data_Store { diff --git a/includes/class-wc-order-data-store-custom-table.php b/includes/class-wc-order-data-store-custom-table.php index f9d945a..a6063a8 100644 --- a/includes/class-wc-order-data-store-custom-table.php +++ b/includes/class-wc-order-data-store-custom-table.php @@ -694,7 +694,7 @@ public static function filter_order_report_query( $query ) { /** * When the add_order_indexes system status tool is run, populate missing address indexes in - * the order table. + * the orders table. * * @global $wpdb * diff --git a/tests/testcase.php b/tests/testcase.php index b4fbe39..9f3b3db 100644 --- a/tests/testcase.php +++ b/tests/testcase.php @@ -1,6 +1,6 @@ Date: Tue, 23 Jan 2018 18:16:14 +0000 Subject: [PATCH 03/17] Rename 'wc-custom-order-table.php' to 'wc-custom-orders-table.php' for consistency with WordPress conventions --- tests/bootstrap.php | 2 +- tests/testcase.php | 2 +- ...ustom-order-table.php => woocommerce-custom-orders-table.php | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename wc-custom-order-table.php => woocommerce-custom-orders-table.php (100%) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 80beb89..97124fb 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -26,7 +26,7 @@ // Manually load the plugin on muplugins_loaded. function _manually_load_plugin() { - require dirname( dirname( __FILE__ ) ) . '/wc-custom-order-table.php'; + require dirname( dirname( __FILE__ ) ) . '/woocommerce-custom-orders-table.php'; echo esc_html( sprintf( /* Translators: %1$s is the WooCommerce release being loaded. */ diff --git a/tests/testcase.php b/tests/testcase.php index 9f3b3db..3c316be 100644 --- a/tests/testcase.php +++ b/tests/testcase.php @@ -124,7 +124,7 @@ protected static function drop_orders_table() { * Emulate deactivating, then subsequently reactivating the plugin. */ protected static function reactivate_plugin() { - $plugin = plugin_basename( dirname( __DIR__ ) . '/wc-custom-order-table.php' ); + $plugin = plugin_basename( dirname( __DIR__ ) . '/woocommerce-custom-orders-table.php' ); do_action( 'deactivate_' . $plugin, false ); do_action( 'activate_' . $plugin, false ); diff --git a/wc-custom-order-table.php b/woocommerce-custom-orders-table.php similarity index 100% rename from wc-custom-order-table.php rename to woocommerce-custom-orders-table.php From 141d3f88a205038d7fd259f80742a971355b3c5f Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Tue, 23 Jan 2018 18:26:02 +0000 Subject: [PATCH 04/17] Track down any remaining instances of {$wpdb->prefix}woocommerce_orders and ensure we're always using wc_custom_order_table()->get_table_name() --- .../class-wc-order-data-store-custom-table.php | 11 ++++++----- tests/testcase.php | 14 +++++++------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/includes/class-wc-order-data-store-custom-table.php b/includes/class-wc-order-data-store-custom-table.php index a6063a8..037a25f 100644 --- a/includes/class-wc-order-data-store-custom-table.php +++ b/includes/class-wc-order-data-store-custom-table.php @@ -123,10 +123,9 @@ public function delete( &$order, $args = array() ) { // Delete the database row if force_delete is true. if ( isset( $args['force_delete'] ) && $args['force_delete'] ) { - $wpdb->delete( - "{$wpdb->prefix}woocommerce_orders", - array( 'order_id' => $order_id ) - ); // WPCS: DB call OK. + $wpdb->delete( wc_custom_order_table()->get_table_name(), array( + 'order_id' => $order_id, + ) ); // WPCS: DB call OK. } } @@ -318,8 +317,10 @@ protected function update_post_meta( &$order ) { public function get_order_id_by_order_key( $order_key ) { global $wpdb; + $table = wc_custom_order_table()->get_table_name(); + return $wpdb->get_var( $wpdb->prepare( - "SELECT order_id FROM {$wpdb->prefix}woocommerce_orders WHERE order_key = %s", + 'SELECT order_id FROM ' . esc_sql( $table ) . ' WHERE order_key = %s', $order_key ) ); // WPCS: DB call OK. } diff --git a/tests/testcase.php b/tests/testcase.php index 3c316be..87994d5 100644 --- a/tests/testcase.php +++ b/tests/testcase.php @@ -18,7 +18,7 @@ class TestCase extends WC_Unit_Test_Case { protected function truncate_table() { global $wpdb; - $wpdb->query( "DELETE FROM {$wpdb->prefix}woocommerce_orders" ); + $wpdb->query( 'DELETE FROM ' . esc_sql( wc_custom_order_table()->get_table_name() ) ); } /** @@ -69,9 +69,9 @@ protected function count_orders_in_table_with_ids( $order_ids = array() ) { return 0; } - return (int) $wpdb->get_var( $wpdb->prepare( " - SELECT COUNT(order_id) FROM {$wpdb->prefix}woocommerce_orders - WHERE order_id IN (" . implode( ', ', array_fill( 0, count( $order_ids ), '%d' ) ) . ')', + return (int) $wpdb->get_var( $wpdb->prepare( + 'SELECT COUNT(order_id) FROM ' . esc_sql( wc_custom_order_table()->get_table_name() ) . ' + WHERE order_id IN (' . implode( ', ', array_fill( 0, count( $order_ids ), '%d' ) ) . ')', $order_ids ) ); } @@ -88,7 +88,7 @@ protected function get_order_row( $order_id ) { global $wpdb; return $wpdb->get_row( $wpdb->prepare( - "SELECT * FROM {$wpdb->prefix}woocommerce_orders WHERE order_id = %d", + 'SELECT * FROM ' . esc_sql( wc_custom_order_table()->get_table_name() ) . ' WHERE order_id = %d', $order_id ), ARRAY_A ); } @@ -103,7 +103,7 @@ protected static function orders_table_exists() { return (bool) $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM information_schema.tables WHERE table_name = %s LIMIT 1', - $wpdb->prefix . 'woocommerce_orders' + wc_custom_order_table()->get_table_name() ) ); } @@ -115,7 +115,7 @@ protected static function orders_table_exists() { protected static function drop_orders_table() { global $wpdb; - $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}woocommerce_orders" ); + $wpdb->query( 'DROP TABLE IF EXISTS ' . esc_sql( wc_custom_order_table()->get_table_name() ) ); delete_option( WC_Custom_Order_Table_Install::SCHEMA_VERSION_KEY ); } From b818154db655d2e664e375dbc69e9367cfd0e5a1 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Tue, 23 Jan 2018 18:27:19 +0000 Subject: [PATCH 05/17] Update the repo name + description in the composer.json file --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index bd00b64..c6df0c1 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { - "name": "liquidweb/wc-custom-order-table", - "description": "Store WooCommerce order data in a custom table.", + "name": "liquidweb/woocommerce-custom-orders-table", + "description": "Store WooCommerce order data in a custom table for improved performance", "type": "wordpress-plugin", "license": "GPL-2.0", "repositories": [ From ad22ec77e36d605d21d85830df7fd02092720df9 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Tue, 23 Jan 2018 18:33:06 +0000 Subject: [PATCH 06/17] Add a couple esc_sql() calls to ensure filtered table names are safe --- includes/class-wc-order-data-store-custom-table.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/class-wc-order-data-store-custom-table.php b/includes/class-wc-order-data-store-custom-table.php index 037a25f..3b2e813 100644 --- a/includes/class-wc-order-data-store-custom-table.php +++ b/includes/class-wc-order-data-store-custom-table.php @@ -566,7 +566,7 @@ public static function posts_join( $join, $wp_query ) { $join = preg_replace( $regex, '', $join ); } - $table = wc_custom_order_table()->get_table_name(); + $table = esc_sql( wc_custom_order_table()->get_table_name() ); $join .= " LEFT JOIN {$table} ON ( {$wpdb->posts}.ID = {$table}.order_id ) "; // Don't necessarily apply this to subsequent posts_join filter callbacks. @@ -590,7 +590,7 @@ public static function meta_query_where( $where, $wp_query ) { global $wpdb; $meta_query = $wp_query->get( 'wc_order_meta_query' ); - $table = wc_custom_order_table()->get_table_name(); + $table = esc_sql( wc_custom_order_table()->get_table_name() ); if ( empty( $meta_query ) ) { return $where; @@ -650,7 +650,7 @@ public static function filter_order_report_query( $query ) { 'post_id' => false, 'post_parent' => false, ); - $table = wc_custom_order_table()->get_table_name(); + $table = esc_sql( wc_custom_order_table()->get_table_name() ); $replacements = array(); foreach ( $matches[0] as $key => $value ) { From eb3e0311ca4edd729353896dce197b17e2bb3835 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Tue, 23 Jan 2018 18:35:13 +0000 Subject: [PATCH 07/17] Update the text domain defined for PHP_CodeSniffer --- phpcs.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 4098612..6e2b174 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -10,7 +10,7 @@ - + From 2b5dcbcbfba1568ed4681a3f82ec28b7f08621db Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Tue, 23 Jan 2018 18:35:25 +0000 Subject: [PATCH 08/17] Update the code coverage whitelist to reflect the new filename of the main plugin file --- phpunit.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0ff1fb5..b2470f1 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -33,7 +33,7 @@ includes - wc-custom-order-table.php + woocommerce-custom-orders-table.php From a4fbfd2af66f08db0ab0956162066315b7edf0d5 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Tue, 23 Jan 2018 18:35:59 +0000 Subject: [PATCH 09/17] Normalize the file headers for all test files --- tests/bootstrap.php | 1 + tests/test-tools/class-mock-progress-bar.php | 3 +++ tests/test-tools/class-wp-cli-command.php | 3 +++ tests/test-tools/class-wp-cli.php | 3 +++ 4 files changed, 10 insertions(+) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 97124fb..3600e73 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -6,6 +6,7 @@ * the bootstrap relies heavily on the WooCommerce core test suite. * * @package WooCommerce_Custom_Orders_Table + * @author Liquid Web */ $_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib'; diff --git a/tests/test-tools/class-mock-progress-bar.php b/tests/test-tools/class-mock-progress-bar.php index 0d7d4cd..70fceac 100644 --- a/tests/test-tools/class-mock-progress-bar.php +++ b/tests/test-tools/class-mock-progress-bar.php @@ -1,6 +1,9 @@ Date: Tue, 23 Jan 2018 18:37:13 +0000 Subject: [PATCH 10/17] Update the license identifier in composer.json to be strictly GPL version 2.0 From `composer validate`: > License "GPL-2.0" is a deprecated SPDX license identifier, use "GPL-2.0-only" or "GPL-2.0-or-later" instead --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c6df0c1..067df37 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "liquidweb/woocommerce-custom-orders-table", "description": "Store WooCommerce order data in a custom table for improved performance", "type": "wordpress-plugin", - "license": "GPL-2.0", + "license": "GPL-2.0-only", "repositories": [ { "type": "vcs", From cab8cc04b595049d3140b9385183def7fe7f3999 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Tue, 23 Jan 2018 18:39:16 +0000 Subject: [PATCH 11/17] Without strict Composer dependencies, we don't need an explicit PHP version there --- composer.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/composer.json b/composer.json index 067df37..36e09d9 100644 --- a/composer.json +++ b/composer.json @@ -9,9 +9,6 @@ "url": "https://github.com/liquidweb/woocommerce" } ], - "require": { - "php": ">=5.2" - }, "require-dev": { "php": "^7.0", "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4", From d3887820026f01ad7da008fec46c9bf78552dc5d Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Tue, 23 Jan 2018 18:43:58 +0000 Subject: [PATCH 12/17] Rename the WC_Custom_Order_Table_CLI class to WooCommerce_Custom_Orders_Table_CLI --- includes/class-wc-custom-order-table.php | 2 +- ...-cli.php => class-woocommerce-custom-orders-table-cli.php} | 2 +- tests/test-cli.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) rename includes/{class-wc-custom-order-table-cli.php => class-woocommerce-custom-orders-table-cli.php} (98%) diff --git a/includes/class-wc-custom-order-table.php b/includes/class-wc-custom-order-table.php index eb047ca..63da511 100644 --- a/includes/class-wc-custom-order-table.php +++ b/includes/class-wc-custom-order-table.php @@ -34,7 +34,7 @@ public function setup() { // If we're in a WP-CLI context, load the WP-CLI command. if ( defined( 'WP_CLI' ) && WP_CLI ) { - WP_CLI::add_command( 'wc-order-table', 'WC_Custom_Order_Table_CLI' ); + WP_CLI::add_command( 'wc-order-table', 'WooCommerce_Custom_Orders_Table_CLI' ); } } diff --git a/includes/class-wc-custom-order-table-cli.php b/includes/class-woocommerce-custom-orders-table-cli.php similarity index 98% rename from includes/class-wc-custom-order-table-cli.php rename to includes/class-woocommerce-custom-orders-table-cli.php index 1ab5fa6..3d8ee31 100644 --- a/includes/class-wc-custom-order-table-cli.php +++ b/includes/class-woocommerce-custom-orders-table-cli.php @@ -9,7 +9,7 @@ /** * Manages the contents of the WooCommerce orders table. */ -class WC_Custom_Order_Table_CLI extends WP_CLI_Command { +class WooCommerce_Custom_Orders_Table_CLI extends WP_CLI_Command { /** * Count how many orders have yet to be migrated into the custom orders table. diff --git a/tests/test-cli.php b/tests/test-cli.php index 5da68f6..ef554e6 100644 --- a/tests/test-cli.php +++ b/tests/test-cli.php @@ -11,7 +11,7 @@ class CLITest extends TestCase { /** * Holds a fresh instance of the WP-CLI command class. * - * @var WC_Custom_Order_Table_CLI + * @var WooCommerce_Custom_Orders_Table_CLI */ protected $cli; @@ -19,7 +19,7 @@ class CLITest extends TestCase { * @before */ public function init() { - $this->cli = new WC_Custom_Order_Table_CLI(); + $this->cli = new WooCommerce_Custom_Orders_Table_CLI(); } public function test_count() { From 4dd5c516bcdb57672e611fd18d640978e1547549 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Tue, 23 Jan 2018 18:46:29 +0000 Subject: [PATCH 13/17] Rename WC_Custom_Order_Table_Install to WooCommerce_Custom_Order_Table_Install --- ...ocommerce-custom-orders-table-install.php} | 4 ++-- tests/bootstrap.php | 2 +- tests/test-installation.php | 22 +++++++++---------- tests/testcase.php | 2 +- woocommerce-custom-orders-table.php | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) rename includes/{class-wc-custom-order-table-install.php => class-woocommerce-custom-orders-table-install.php} (96%) diff --git a/includes/class-wc-custom-order-table-install.php b/includes/class-woocommerce-custom-orders-table-install.php similarity index 96% rename from includes/class-wc-custom-order-table-install.php rename to includes/class-woocommerce-custom-orders-table-install.php index e81b080..56c5484 100644 --- a/includes/class-wc-custom-order-table-install.php +++ b/includes/class-woocommerce-custom-orders-table-install.php @@ -11,9 +11,9 @@ * * Usage: * - * WC_Custom_Order_Table_Install::activate(); + * WooCommerce_Custom_Orders_Table_Install::activate(); */ -class WC_Custom_Order_Table_Install { +class WooCommerce_Custom_Orders_Table_Install { /** * The option key that contains the current schema version. diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 3600e73..c22815e 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -35,7 +35,7 @@ function _manually_load_plugin() { WC_VERSION ) ) . PHP_EOL; - WC_Custom_Order_Table_Install::activate(); + WooCommerce_Custom_Orders_Table_Install::activate(); add_filter( 'woocommerce_email_actions', '__return_empty_array' ); } diff --git a/tests/test-installation.php b/tests/test-installation.php index 84c0f27..8a3b27f 100644 --- a/tests/test-installation.php +++ b/tests/test-installation.php @@ -49,42 +49,42 @@ public function test_can_install_table() { 'The wp_woocommerce_orders table should not exist at the beginning of this test.' ); - WC_Custom_Order_Table_Install::activate(); + WooCommerce_Custom_Orders_Table_Install::activate(); $this->assertTrue( self::orders_table_exists(), 'Upon activation, the table should be created.' ); $this->assertNotEmpty( - get_option( WC_Custom_Order_Table_Install::SCHEMA_VERSION_KEY ), + get_option( WooCommerce_Custom_Orders_Table_Install::SCHEMA_VERSION_KEY ), 'The schema version should be stored in the options table.' ); } public function test_returns_early_if_already_on_latest_schema_version() { - WC_Custom_Order_Table_Install::activate(); + WooCommerce_Custom_Orders_Table_Install::activate(); $this->assertFalse( - WC_Custom_Order_Table_Install::activate(), + WooCommerce_Custom_Orders_Table_Install::activate(), 'The activate() method should return false if the schema versions match.' ); } public function test_can_upgrade_table() { - WC_Custom_Order_Table_Install::activate(); + WooCommerce_Custom_Orders_Table_Install::activate(); // Get the current schema version, then increment it. - $property = new ReflectionProperty( 'WC_Custom_Order_Table_Install', 'table_version' ); + $property = new ReflectionProperty( 'WooCommerce_Custom_Orders_Table_Install', 'table_version' ); $property->setAccessible( true ); $version = $property->getValue(); $property->setValue( $version + 1 ); // Run the activation script again. - WC_Custom_Order_Table_Install::activate(); + WooCommerce_Custom_Orders_Table_Install::activate(); $this->assertEquals( $version + 1, - get_option( WC_Custom_Order_Table_Install::SCHEMA_VERSION_KEY ), + get_option( WooCommerce_Custom_Orders_Table_Install::SCHEMA_VERSION_KEY ), 'The schema version should have been incremented.' ); } @@ -92,13 +92,13 @@ public function test_can_upgrade_table() { public function test_current_schema_version_is_not_autoloaded() { global $wpdb; - WC_Custom_Order_Table_Install::activate(); + WooCommerce_Custom_Orders_Table_Install::activate(); $this->assertEquals( 'no', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s LIMIT 1", - WC_Custom_Order_Table_Install::SCHEMA_VERSION_KEY + WooCommerce_Custom_Orders_Table_Install::SCHEMA_VERSION_KEY ) ), 'The schema version should not be autoloaded.' ); @@ -112,7 +112,7 @@ public function test_current_schema_version_is_not_autoloaded() { public function test_database_indexes( $non_unique, $key_name, $column_name ) { global $wpdb; - WC_Custom_Order_Table_Install::activate(); + WooCommerce_Custom_Orders_Table_Install::activate(); $table = wc_custom_order_table()->get_table_name(); $indexes = $wpdb->get_results( "SHOW INDEX FROM $table", ARRAY_A ); diff --git a/tests/testcase.php b/tests/testcase.php index 87994d5..503be7f 100644 --- a/tests/testcase.php +++ b/tests/testcase.php @@ -117,7 +117,7 @@ protected static function drop_orders_table() { $wpdb->query( 'DROP TABLE IF EXISTS ' . esc_sql( wc_custom_order_table()->get_table_name() ) ); - delete_option( WC_Custom_Order_Table_Install::SCHEMA_VERSION_KEY ); + delete_option( WooCommerce_Custom_Orders_Table_Install::SCHEMA_VERSION_KEY ); } /** diff --git a/woocommerce-custom-orders-table.php b/woocommerce-custom-orders-table.php index 8ad485b..55c8471 100644 --- a/woocommerce-custom-orders-table.php +++ b/woocommerce-custom-orders-table.php @@ -42,7 +42,7 @@ function wc_custom_order_table_autoload( $class ) { /** * Install the database tables upon plugin activation. */ -register_activation_hook( __FILE__, array( 'WC_Custom_Order_Table_Install', 'activate' ) ); +register_activation_hook( __FILE__, array( 'WooCommerce_Custom_Orders_Table_Install', 'activate' ) ); /** * Retrieve an instance of the WC_Custom_Order_Table class. From 0261db9b30ad1952fda648d8b9143e5a46ada903 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Tue, 23 Jan 2018 18:49:07 +0000 Subject: [PATCH 14/17] Rename WC_Custom_Order_Table to WooCommerce_Custom_Orders_Table --- ...able.php => class-woocommerce-custom-orders-table.php} | 2 +- tests/test-bootstrap.php | 2 +- tests/testcase.php | 8 ++++---- woocommerce-custom-orders-table.php | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) rename includes/{class-wc-custom-order-table.php => class-woocommerce-custom-orders-table.php} (97%) diff --git a/includes/class-wc-custom-order-table.php b/includes/class-woocommerce-custom-orders-table.php similarity index 97% rename from includes/class-wc-custom-order-table.php rename to includes/class-woocommerce-custom-orders-table.php index 63da511..76316a5 100644 --- a/includes/class-wc-custom-order-table.php +++ b/includes/class-woocommerce-custom-orders-table.php @@ -9,7 +9,7 @@ /** * Core functionality for WooCommerce Custom Orders Table. */ -class WC_Custom_Order_Table { +class WooCommerce_Custom_Orders_Table { /** * The database table name. diff --git a/tests/test-bootstrap.php b/tests/test-bootstrap.php index 48d369e..c39acff 100644 --- a/tests/test-bootstrap.php +++ b/tests/test-bootstrap.php @@ -17,7 +17,7 @@ public function test_plugin_only_loads_after_woocommerce() { do_action( 'woocommerce_init' ); $this->assertInstanceOf( - 'WC_Custom_Order_Table', + 'WooCommerce_Custom_Orders_Table', $wc_custom_order_table, 'The plugin should not be bootstrapped until woocommerce_init.' ); diff --git a/tests/testcase.php b/tests/testcase.php index 503be7f..e18bcae 100644 --- a/tests/testcase.php +++ b/tests/testcase.php @@ -28,11 +28,11 @@ protected function truncate_table() { */ protected function toggle_use_custom_table( $enabled = true ) { if ( $enabled ) { - add_filter( 'woocommerce_customer_data_store', 'WC_Custom_Order_Table::customer_data_store' ); - add_filter( 'woocommerce_order_data_store', 'WC_Custom_Order_Table::order_data_store' ); + add_filter( 'woocommerce_customer_data_store', 'WooCommerce_Custom_Orders_Table::customer_data_store' ); + add_filter( 'woocommerce_order_data_store', 'WooCommerce_Custom_Orders_Table::order_data_store' ); } else { - remove_filter( 'woocommerce_customer_data_store', 'WC_Custom_Order_Table::customer_data_store' ); - remove_filter( 'woocommerce_order_data_store', 'WC_Custom_Order_Table::order_data_store' ); + remove_filter( 'woocommerce_customer_data_store', 'WooCommerce_Custom_Orders_Table::customer_data_store' ); + remove_filter( 'woocommerce_order_data_store', 'WooCommerce_Custom_Orders_Table::order_data_store' ); } } diff --git a/woocommerce-custom-orders-table.php b/woocommerce-custom-orders-table.php index 55c8471..7497714 100644 --- a/woocommerce-custom-orders-table.php +++ b/woocommerce-custom-orders-table.php @@ -45,19 +45,19 @@ function wc_custom_order_table_autoload( $class ) { register_activation_hook( __FILE__, array( 'WooCommerce_Custom_Orders_Table_Install', 'activate' ) ); /** - * Retrieve an instance of the WC_Custom_Order_Table class. + * Retrieve an instance of the WooCommerce_Custom_Orders_Table class. * * If one has not yet been instantiated, it will be created. * * @global $wc_custom_order_table * - * @return WC_Custom_Order_Table The global WC_Custom_Order_Table instance. + * @return WooCommerce_Custom_Orders_Table The global WooCommerce_Custom_Orders_Table instance. */ function wc_custom_order_table() { global $wc_custom_order_table; - if ( ! $wc_custom_order_table instanceof WC_Custom_Order_Table ) { - $wc_custom_order_table = new WC_Custom_Order_Table(); + if ( ! $wc_custom_order_table instanceof WooCommerce_Custom_Orders_Table ) { + $wc_custom_order_table = new WooCommerce_Custom_Orders_Table(); $wc_custom_order_table->setup(); } From 9c3b56b7228e2681addb24f1d3ccf7619f923123 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Tue, 23 Jan 2018 18:49:44 +0000 Subject: [PATCH 15/17] Drop the non-dev 'autoload' node from the composer.json file, since we're no longer depending on a generated autoloader outside of development --- composer.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/composer.json b/composer.json index 36e09d9..4b4dd24 100644 --- a/composer.json +++ b/composer.json @@ -17,11 +17,6 @@ "woocommerce/woocommerce-sniffs": "^0.0.1", "wp-coding-standards/wpcs": "^0.14" }, - "autoload": { - "classmap": [ - "includes" - ] - }, "autoload-dev": { "classmap": [ "tests/test-tools", From f0e0636e42edac40bc007609997348bd67503a96 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Tue, 23 Jan 2018 19:00:16 +0000 Subject: [PATCH 16/17] Update the GitHub URL in the plugin header --- 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 7497714..15c56a4 100644 --- a/woocommerce-custom-orders-table.php +++ b/woocommerce-custom-orders-table.php @@ -1,7 +1,7 @@ Date: Tue, 23 Jan 2018 19:43:00 +0000 Subject: [PATCH 17/17] Update the PHPCS config to reflect the renamed CLI class --- phpcs.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 6e2b174..c33b03c 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -16,7 +16,7 @@ - includes/class-wc-custom-order-table-cli.php + includes/class-woocommerce-custom-orders-table-cli.php