Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 14355f1

Browse files
mikejolleynerrad
authored andcommitted
Remove CURRENT_TIMESTAMP default on the stock table (#2590)
* Remove the default timestamp value which requires mysql 5.6.5 * Change REPLACE INTO with INSERT INTO .. ON DUPLICATE KEY UPDATE This will allow us to set the timestamp value on first insert only.
1 parent c5f2d49 commit 14355f1

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Installer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public function maybe_create_tables() {
5858
`order_id` bigint(20) NOT NULL,
5959
`product_id` bigint(20) NOT NULL,
6060
`stock_quantity` double NOT NULL DEFAULT 0,
61-
`timestamp` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
62-
`expires` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
61+
`timestamp` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
62+
`expires` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
6363
PRIMARY KEY (`order_id`, `product_id`)
6464
) $collate;
6565
"

src/StoreApi/Utilities/ReserveStock.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,10 @@ private function reserve_stock_for_product( $product_id, $stock_quantity, \WC_Or
162162
$result = $wpdb->query(
163163
$wpdb->prepare(
164164
"
165-
REPLACE INTO {$wpdb->wc_reserved_stock} ( order_id, product_id, stock_quantity, expires )
166-
SELECT %d, %d, %d, ( NOW() + INTERVAL %d MINUTE ) from DUAL
165+
INSERT INTO {$wpdb->wc_reserved_stock} ( `order_id`, `product_id`, `stock_quantity`, `timestamp`, `expires` )
166+
SELECT %d, %d, %d, NOW(), ( NOW() + INTERVAL %d MINUTE ) FROM DUAL
167167
WHERE ( $query_for_stock FOR UPDATE ) - ( $query_for_reserved_stock FOR UPDATE ) >= %d
168+
ON DUPLICATE KEY UPDATE `expires` = VALUES( `expires` )
168169
",
169170
$order->get_id(),
170171
$product_id,

0 commit comments

Comments
 (0)