From 0fe809529437d5d8f04731034f1d4d599c035d16 Mon Sep 17 00:00:00 2001 From: Luke Cavanagh Date: Tue, 12 Dec 2017 13:12:23 -0700 Subject: [PATCH 1/5] Delete class-wc-custom-order-table-install.php Remove table install class, first steps to move the table install back into the main plugin file. --- .../class-wc-custom-order-table-install.php | 90 ------------------- 1 file changed, 90 deletions(-) delete mode 100644 includes/class-wc-custom-order-table-install.php diff --git a/includes/class-wc-custom-order-table-install.php b/includes/class-wc-custom-order-table-install.php deleted file mode 100644 index 3404f53..0000000 --- a/includes/class-wc-custom-order-table-install.php +++ /dev/null @@ -1,90 +0,0 @@ -maybe_install_tables(); - } - - public function get_latest_table_version() { - return absint( $this->table_version ); - } - - public function get_installed_table_version() { - return absint( get_option( 'wc_orders_table_version' ) ); - } - - protected function maybe_install_tables() { - if( $this->get_installed_table_version() < $this->get_latest_table_version() ) { - $this->install_tables(); - } - } - - protected function install_tables() { - global $wpdb; - - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); - - $collate = ''; - - if ( $wpdb->has_cap( 'collation' ) ) { - $collate = $wpdb->get_charset_collate(); - } - - $table = wc_custom_order_table()->get_table_name(); - - $tables = " - CREATE TABLE {$table} ( - order_id BIGINT UNSIGNED NOT NULL, - order_key varchar(100) NOT NULL, - customer_id BIGINT UNSIGNED NOT NULL, - billing_first_name varchar(100) NOT NULL, - billing_last_name varchar(100) NOT NULL, - billing_company varchar(100) NOT NULL, - billing_address_1 varchar(200) NOT NULL, - billing_address_2 varchar(200) NOT NULL, - billing_city varchar(100) NOT NULL, - billing_state varchar(100) NOT NULL, - billing_postcode varchar(100) NOT NULL, - billing_country varchar(100) NOT NULL, - billing_email varchar(200) NOT NULL, - billing_phone varchar(200) NOT NULL, - shipping_first_name varchar(100) NOT NULL, - shipping_last_name varchar(100) NOT NULL, - shipping_company varchar(100) NOT NULL, - shipping_address_1 varchar(200) NOT NULL, - shipping_address_2 varchar(200) NOT NULL, - shipping_city varchar(100) NOT NULL, - shipping_state varchar(100) NOT NULL, - shipping_postcode varchar(100) NOT NULL, - shipping_country varchar(100) NOT NULL, - payment_method varchar(100) NOT NULL, - payment_method_title varchar(100) NOT NULL, - - discount_total float NOT NULL DEFAULT 0, - discount_tax float NOT NULL DEFAULT 0, - shipping_total float NOT NULL DEFAULT 0, - shipping_tax float NOT NULL DEFAULT 0, - cart_tax float NOT NULL DEFAULT 0, - total float NOT NULL DEFAULT 0, - version varchar(16) NOT NULL, - currency varchar(3) NOT NULL, - prices_include_tax tinyint(1) NOT NULL, - - transaction_id varchar(200) NOT NULL, - customer_ip_address varchar(40) NOT NULL, - customer_user_agent varchar(200) NOT NULL, - created_via varchar(200) NOT NULL, - date_completed datetime DEFAULT NULL, - date_paid datetime DEFAULT NULL, - cart_hash varchar(32) NOT NULL, - - PRIMARY KEY (order_id) - ) $collate; - "; - - dbDelta( $tables ); - update_option('wc_orders_table_version', $this->get_latest_table_version() ); - } -} \ No newline at end of file From abd4f0783307e37ad1a5a2a3c421960f0841da26 Mon Sep 17 00:00:00 2001 From: Luke Cavanagh Date: Tue, 12 Dec 2017 13:48:59 -0700 Subject: [PATCH 2/5] Update wc-custom-order-table.php Revert register_activation_hook within a register_activation_hook and move the install table class back into the main plugin file. --- wc-custom-order-table.php | 78 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 5 deletions(-) diff --git a/wc-custom-order-table.php b/wc-custom-order-table.php index 196763b..1bbdce3 100644 --- a/wc-custom-order-table.php +++ b/wc-custom-order-table.php @@ -23,12 +23,80 @@ require( WC_CUSTOM_ORDER_TABLE_PATH . 'vendor/autoload_52.php' ); } -function wc_custom_order_table_install() { - $installer = new WC_Custom_Order_Table_Install(); - register_activation_hook( __FILE__, array( $installer, 'activate' ) ); -} +register_activation_hook( __FILE__, array( $this, 'activate' ) ); -register_activation_hook( __FILE__, 'wc_custom_order_table_install' ); +public function activate() { + $this->maybe_install_tables(); + } + public function get_latest_table_version() { + return absint( $this->table_version ); + } + public function get_installed_table_version() { + return absint( get_option( 'wc_orders_table_version' ) ); + } + protected function maybe_install_tables() { + if( $this->get_installed_table_version() < $this->get_latest_table_version() ) { + $this->install_tables(); + } + } + protected function install_tables() { + global $wpdb; + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); + $collate = ''; + if ( $wpdb->has_cap( 'collation' ) ) { + $collate = $wpdb->get_charset_collate(); + } + $table = $this->get_table_name(); + $tables = " + CREATE TABLE {$table} ( + order_id BIGINT UNSIGNED NOT NULL, + order_key varchar(100) NOT NULL, + customer_id BIGINT UNSIGNED NOT NULL, + billing_first_name varchar(100) NOT NULL, + billing_last_name varchar(100) NOT NULL, + billing_company varchar(100) NOT NULL, + billing_address_1 varchar(200) NOT NULL, + billing_address_2 varchar(200) NOT NULL, + billing_city varchar(100) NOT NULL, + billing_state varchar(100) NOT NULL, + billing_postcode varchar(100) NOT NULL, + billing_country varchar(100) NOT NULL, + billing_email varchar(200) NOT NULL, + billing_phone varchar(200) NOT NULL, + shipping_first_name varchar(100) NOT NULL, + shipping_last_name varchar(100) NOT NULL, + shipping_company varchar(100) NOT NULL, + shipping_address_1 varchar(200) NOT NULL, + shipping_address_2 varchar(200) NOT NULL, + shipping_city varchar(100) NOT NULL, + shipping_state varchar(100) NOT NULL, + shipping_postcode varchar(100) NOT NULL, + shipping_country varchar(100) NOT NULL, + payment_method varchar(100) NOT NULL, + payment_method_title varchar(100) NOT NULL, + discount_total float NOT NULL DEFAULT 0, + discount_tax float NOT NULL DEFAULT 0, + shipping_total float NOT NULL DEFAULT 0, + shipping_tax float NOT NULL DEFAULT 0, + cart_tax float NOT NULL DEFAULT 0, + total float NOT NULL DEFAULT 0, + version varchar(16) NOT NULL, + currency varchar(3) NOT NULL, + prices_include_tax tinyint(1) NOT NULL, + transaction_id varchar(200) NOT NULL, + customer_ip_address varchar(40) NOT NULL, + customer_user_agent varchar(200) NOT NULL, + created_via varchar(200) NOT NULL, + date_completed datetime DEFAULT NULL, + date_paid datetime DEFAULT NULL, + cart_hash varchar(32) NOT NULL, + PRIMARY KEY (order_id) + ) $collate; + "; + dbDelta( $tables ); + update_option('wc_orders_table_version', $this->get_latest_table_version() ); + } +} /** * @return WC_Custom_Order_Table From a8e2c2a2951273f6db2d7cf0048f6655fd81c0a1 Mon Sep 17 00:00:00 2001 From: Luke Cavanagh Date: Wed, 13 Dec 2017 14:09:28 -0700 Subject: [PATCH 3/5] Make spaces and tabs consistent Fix spaces and tabs on the code taken from `class-wc-custom-order-table-install.php`. --- wc-custom-order-table.php | 151 +++++++++++++++++++++----------------- 1 file changed, 82 insertions(+), 69 deletions(-) diff --git a/wc-custom-order-table.php b/wc-custom-order-table.php index 1bbdce3..1ffa384 100644 --- a/wc-custom-order-table.php +++ b/wc-custom-order-table.php @@ -26,75 +26,88 @@ register_activation_hook( __FILE__, array( $this, 'activate' ) ); public function activate() { - $this->maybe_install_tables(); - } - public function get_latest_table_version() { - return absint( $this->table_version ); - } - public function get_installed_table_version() { - return absint( get_option( 'wc_orders_table_version' ) ); - } - protected function maybe_install_tables() { - if( $this->get_installed_table_version() < $this->get_latest_table_version() ) { - $this->install_tables(); - } - } - protected function install_tables() { - global $wpdb; - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); - $collate = ''; - if ( $wpdb->has_cap( 'collation' ) ) { - $collate = $wpdb->get_charset_collate(); - } - $table = $this->get_table_name(); - $tables = " - CREATE TABLE {$table} ( - order_id BIGINT UNSIGNED NOT NULL, - order_key varchar(100) NOT NULL, - customer_id BIGINT UNSIGNED NOT NULL, - billing_first_name varchar(100) NOT NULL, - billing_last_name varchar(100) NOT NULL, - billing_company varchar(100) NOT NULL, - billing_address_1 varchar(200) NOT NULL, - billing_address_2 varchar(200) NOT NULL, - billing_city varchar(100) NOT NULL, - billing_state varchar(100) NOT NULL, - billing_postcode varchar(100) NOT NULL, - billing_country varchar(100) NOT NULL, - billing_email varchar(200) NOT NULL, - billing_phone varchar(200) NOT NULL, - shipping_first_name varchar(100) NOT NULL, - shipping_last_name varchar(100) NOT NULL, - shipping_company varchar(100) NOT NULL, - shipping_address_1 varchar(200) NOT NULL, - shipping_address_2 varchar(200) NOT NULL, - shipping_city varchar(100) NOT NULL, - shipping_state varchar(100) NOT NULL, - shipping_postcode varchar(100) NOT NULL, - shipping_country varchar(100) NOT NULL, - payment_method varchar(100) NOT NULL, - payment_method_title varchar(100) NOT NULL, - discount_total float NOT NULL DEFAULT 0, - discount_tax float NOT NULL DEFAULT 0, - shipping_total float NOT NULL DEFAULT 0, - shipping_tax float NOT NULL DEFAULT 0, - cart_tax float NOT NULL DEFAULT 0, - total float NOT NULL DEFAULT 0, - version varchar(16) NOT NULL, - currency varchar(3) NOT NULL, - prices_include_tax tinyint(1) NOT NULL, - transaction_id varchar(200) NOT NULL, - customer_ip_address varchar(40) NOT NULL, - customer_user_agent varchar(200) NOT NULL, - created_via varchar(200) NOT NULL, - date_completed datetime DEFAULT NULL, - date_paid datetime DEFAULT NULL, - cart_hash varchar(32) NOT NULL, - PRIMARY KEY (order_id) - ) $collate; - "; - dbDelta( $tables ); - update_option('wc_orders_table_version', $this->get_latest_table_version() ); + $this->maybe_install_tables(); +} + +public function get_latest_table_version() { + return absint( $this->table_version ); +} + +public function get_installed_table_version() { + return absint( get_option( 'wc_orders_table_version' ) ); +} + +protected function maybe_install_tables() { + if( $this->get_installed_table_version() < $this->get_latest_table_version() ) { + $this->install_tables(); + } +} + +protected function install_tables() { + global $wpdb; + + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); + + $collate = ''; + + if ( $wpdb->has_cap( 'collation' ) ) { + $collate = $wpdb->get_charset_collate(); + } + + $table = $this->get_table_name(); + + $tables = " + CREATE TABLE {$table} ( + order_id BIGINT UNSIGNED NOT NULL, + order_key varchar(100) NOT NULL, + customer_id BIGINT UNSIGNED NOT NULL, + billing_first_name varchar(100) NOT NULL, + billing_last_name varchar(100) NOT NULL, + billing_company varchar(100) NOT NULL, + billing_address_1 varchar(200) NOT NULL, + billing_address_2 varchar(200) NOT NULL, + billing_city varchar(100) NOT NULL, + billing_state varchar(100) NOT NULL, + billing_postcode varchar(100) NOT NULL, + billing_country varchar(100) NOT NULL, + billing_email varchar(200) NOT NULL, + billing_phone varchar(200) NOT NULL, + shipping_first_name varchar(100) NOT NULL, + shipping_last_name varchar(100) NOT NULL, + shipping_company varchar(100) NOT NULL, + shipping_address_1 varchar(200) NOT NULL, + shipping_address_2 varchar(200) NOT NULL, + shipping_city varchar(100) NOT NULL, + shipping_state varchar(100) NOT NULL, + shipping_postcode varchar(100) NOT NULL, + shipping_country varchar(100) NOT NULL, + payment_method varchar(100) NOT NULL, + payment_method_title varchar(100) NOT NULL, + + discount_total float NOT NULL DEFAULT 0, + discount_tax float NOT NULL DEFAULT 0, + shipping_total float NOT NULL DEFAULT 0, + shipping_tax float NOT NULL DEFAULT 0, + cart_tax float NOT NULL DEFAULT 0, + total float NOT NULL DEFAULT 0, + version varchar(16) NOT NULL, + currency varchar(3) NOT NULL, + prices_include_tax tinyint(1) NOT NULL, + + transaction_id varchar(200) NOT NULL, + customer_ip_address varchar(40) NOT NULL, + customer_user_agent varchar(200) NOT NULL, + created_via varchar(200) NOT NULL, + date_completed datetime DEFAULT NULL, + date_paid datetime DEFAULT NULL, + cart_hash varchar(32) NOT NULL, + + PRIMARY KEY (order_id) + ) $collate; + "; + + dbDelta( $tables ); + update_option('wc_orders_table_version', $this->get_latest_table_version() ); } } From 4b28e89dad4b1ab57e3323eefe473c170fc56d74 Mon Sep 17 00:00:00 2001 From: Luke Cavanagh Date: Wed, 13 Dec 2017 20:26:33 -0700 Subject: [PATCH 4/5] Restore class for order table install Revert first of the previous changes made. --- .../class-wc-custom-order-table-install.php | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 includes/class-wc-custom-order-table-install.php diff --git a/includes/class-wc-custom-order-table-install.php b/includes/class-wc-custom-order-table-install.php new file mode 100644 index 0000000..3404f53 --- /dev/null +++ b/includes/class-wc-custom-order-table-install.php @@ -0,0 +1,90 @@ +maybe_install_tables(); + } + + public function get_latest_table_version() { + return absint( $this->table_version ); + } + + public function get_installed_table_version() { + return absint( get_option( 'wc_orders_table_version' ) ); + } + + protected function maybe_install_tables() { + if( $this->get_installed_table_version() < $this->get_latest_table_version() ) { + $this->install_tables(); + } + } + + protected function install_tables() { + global $wpdb; + + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); + + $collate = ''; + + if ( $wpdb->has_cap( 'collation' ) ) { + $collate = $wpdb->get_charset_collate(); + } + + $table = wc_custom_order_table()->get_table_name(); + + $tables = " + CREATE TABLE {$table} ( + order_id BIGINT UNSIGNED NOT NULL, + order_key varchar(100) NOT NULL, + customer_id BIGINT UNSIGNED NOT NULL, + billing_first_name varchar(100) NOT NULL, + billing_last_name varchar(100) NOT NULL, + billing_company varchar(100) NOT NULL, + billing_address_1 varchar(200) NOT NULL, + billing_address_2 varchar(200) NOT NULL, + billing_city varchar(100) NOT NULL, + billing_state varchar(100) NOT NULL, + billing_postcode varchar(100) NOT NULL, + billing_country varchar(100) NOT NULL, + billing_email varchar(200) NOT NULL, + billing_phone varchar(200) NOT NULL, + shipping_first_name varchar(100) NOT NULL, + shipping_last_name varchar(100) NOT NULL, + shipping_company varchar(100) NOT NULL, + shipping_address_1 varchar(200) NOT NULL, + shipping_address_2 varchar(200) NOT NULL, + shipping_city varchar(100) NOT NULL, + shipping_state varchar(100) NOT NULL, + shipping_postcode varchar(100) NOT NULL, + shipping_country varchar(100) NOT NULL, + payment_method varchar(100) NOT NULL, + payment_method_title varchar(100) NOT NULL, + + discount_total float NOT NULL DEFAULT 0, + discount_tax float NOT NULL DEFAULT 0, + shipping_total float NOT NULL DEFAULT 0, + shipping_tax float NOT NULL DEFAULT 0, + cart_tax float NOT NULL DEFAULT 0, + total float NOT NULL DEFAULT 0, + version varchar(16) NOT NULL, + currency varchar(3) NOT NULL, + prices_include_tax tinyint(1) NOT NULL, + + transaction_id varchar(200) NOT NULL, + customer_ip_address varchar(40) NOT NULL, + customer_user_agent varchar(200) NOT NULL, + created_via varchar(200) NOT NULL, + date_completed datetime DEFAULT NULL, + date_paid datetime DEFAULT NULL, + cart_hash varchar(32) NOT NULL, + + PRIMARY KEY (order_id) + ) $collate; + "; + + dbDelta( $tables ); + update_option('wc_orders_table_version', $this->get_latest_table_version() ); + } +} \ No newline at end of file From a6507ea0cec7c6f2ae9cf2432b9dc2a011fa5b43 Mon Sep 17 00:00:00 2001 From: Luke Cavanagh Date: Wed, 13 Dec 2017 20:28:24 -0700 Subject: [PATCH 5/5] Revert changes made to the main plugin file Remove order table install code from the main plugin file and restore register_activation_hook. --- wc-custom-order-table.php | 89 ++------------------------------------- 1 file changed, 4 insertions(+), 85 deletions(-) diff --git a/wc-custom-order-table.php b/wc-custom-order-table.php index 1ffa384..196763b 100644 --- a/wc-custom-order-table.php +++ b/wc-custom-order-table.php @@ -23,93 +23,12 @@ require( WC_CUSTOM_ORDER_TABLE_PATH . 'vendor/autoload_52.php' ); } -register_activation_hook( __FILE__, array( $this, 'activate' ) ); - -public function activate() { - $this->maybe_install_tables(); -} - -public function get_latest_table_version() { - return absint( $this->table_version ); -} - -public function get_installed_table_version() { - return absint( get_option( 'wc_orders_table_version' ) ); +function wc_custom_order_table_install() { + $installer = new WC_Custom_Order_Table_Install(); + register_activation_hook( __FILE__, array( $installer, 'activate' ) ); } -protected function maybe_install_tables() { - if( $this->get_installed_table_version() < $this->get_latest_table_version() ) { - $this->install_tables(); - } -} - -protected function install_tables() { - global $wpdb; - - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); - - $collate = ''; - - if ( $wpdb->has_cap( 'collation' ) ) { - $collate = $wpdb->get_charset_collate(); - } - - $table = $this->get_table_name(); - - $tables = " - CREATE TABLE {$table} ( - order_id BIGINT UNSIGNED NOT NULL, - order_key varchar(100) NOT NULL, - customer_id BIGINT UNSIGNED NOT NULL, - billing_first_name varchar(100) NOT NULL, - billing_last_name varchar(100) NOT NULL, - billing_company varchar(100) NOT NULL, - billing_address_1 varchar(200) NOT NULL, - billing_address_2 varchar(200) NOT NULL, - billing_city varchar(100) NOT NULL, - billing_state varchar(100) NOT NULL, - billing_postcode varchar(100) NOT NULL, - billing_country varchar(100) NOT NULL, - billing_email varchar(200) NOT NULL, - billing_phone varchar(200) NOT NULL, - shipping_first_name varchar(100) NOT NULL, - shipping_last_name varchar(100) NOT NULL, - shipping_company varchar(100) NOT NULL, - shipping_address_1 varchar(200) NOT NULL, - shipping_address_2 varchar(200) NOT NULL, - shipping_city varchar(100) NOT NULL, - shipping_state varchar(100) NOT NULL, - shipping_postcode varchar(100) NOT NULL, - shipping_country varchar(100) NOT NULL, - payment_method varchar(100) NOT NULL, - payment_method_title varchar(100) NOT NULL, - - discount_total float NOT NULL DEFAULT 0, - discount_tax float NOT NULL DEFAULT 0, - shipping_total float NOT NULL DEFAULT 0, - shipping_tax float NOT NULL DEFAULT 0, - cart_tax float NOT NULL DEFAULT 0, - total float NOT NULL DEFAULT 0, - version varchar(16) NOT NULL, - currency varchar(3) NOT NULL, - prices_include_tax tinyint(1) NOT NULL, - - transaction_id varchar(200) NOT NULL, - customer_ip_address varchar(40) NOT NULL, - customer_user_agent varchar(200) NOT NULL, - created_via varchar(200) NOT NULL, - date_completed datetime DEFAULT NULL, - date_paid datetime DEFAULT NULL, - cart_hash varchar(32) NOT NULL, - - PRIMARY KEY (order_id) - ) $collate; - "; - - dbDelta( $tables ); - update_option('wc_orders_table_version', $this->get_latest_table_version() ); - } -} +register_activation_hook( __FILE__, 'wc_custom_order_table_install' ); /** * @return WC_Custom_Order_Table