Set the orders table exist option if its not set. (#39616)
* Set the orders table exist option if its not set. * Add changelog. * Must use yoda conditions. * Remove unnecessary option set.
This commit is contained in:
parent
75d64ee063
commit
d4141958b2
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: patch
|
||||||
|
Type: fix
|
||||||
|
|
||||||
|
Set the order table exist options value when its not present for smooth upgradation from lower WC versions.
|
|
@ -128,8 +128,26 @@ class DataSynchronizer implements BatchProcessorInterface {
|
||||||
if ( count( $missing_tables ) === 0 ) {
|
if ( count( $missing_tables ) === 0 ) {
|
||||||
update_option( self::ORDERS_TABLE_CREATED, 'yes' );
|
update_option( self::ORDERS_TABLE_CREATED, 'yes' );
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
update_option( self::ORDERS_TABLE_CREATED, 'no' );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of the orders table created option. If it's not set, then it checks the orders table and set it accordingly.
|
||||||
|
*
|
||||||
|
* @return bool Whether orders table exists.
|
||||||
|
*/
|
||||||
|
public function get_table_exists(): bool {
|
||||||
|
$table_exists = get_option( self::ORDERS_TABLE_CREATED );
|
||||||
|
switch ( $table_exists ) {
|
||||||
|
case 'no':
|
||||||
|
case 'yes':
|
||||||
|
return 'yes' === $table_exists;
|
||||||
|
default:
|
||||||
|
return $this->check_orders_table_exists();
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,10 +155,7 @@ class DataSynchronizer implements BatchProcessorInterface {
|
||||||
*/
|
*/
|
||||||
public function create_database_tables() {
|
public function create_database_tables() {
|
||||||
$this->database_util->dbdelta( $this->data_store->get_database_schema() );
|
$this->database_util->dbdelta( $this->data_store->get_database_schema() );
|
||||||
if ( ! $this->check_orders_table_exists() ) {
|
$this->check_orders_table_exists();
|
||||||
return;
|
|
||||||
}
|
|
||||||
update_option( self::ORDERS_TABLE_CREATED, 'yes' );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -223,7 +238,7 @@ class DataSynchronizer implements BatchProcessorInterface {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 'yes' !== get_option( self::ORDERS_TABLE_CREATED ) ) {
|
if ( ! $this->get_table_exists() ) {
|
||||||
$count = $wpdb->get_var(
|
$count = $wpdb->get_var(
|
||||||
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- $order_post_type_placeholder is prepared.
|
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- $order_post_type_placeholder is prepared.
|
||||||
$wpdb->prepare(
|
$wpdb->prepare(
|
||||||
|
@ -652,12 +667,10 @@ ORDER BY orders.id ASC
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 'yes' !== get_option( self::ORDERS_TABLE_CREATED ) ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $this->data_sync_is_enabled() ) {
|
if ( $this->data_sync_is_enabled() ) {
|
||||||
$this->data_store->delete_order_data_from_custom_order_tables( $postid );
|
if ( $this->get_table_exists() ) {
|
||||||
|
$this->data_store->delete_order_data_from_custom_order_tables( $postid );
|
||||||
|
}
|
||||||
} elseif ( $this->custom_orders_table_is_authoritative() ) {
|
} elseif ( $this->custom_orders_table_is_authoritative() ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue