| 1 |
<?php |
| 2 |
/** |
| 3 |
* Order post-date touch for meta-only CPT saves. |
| 4 |
* |
| 5 |
* @package WCPOS\WooCommercePOS\Sync |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WCPOS\WooCommercePOS\Sync; |
| 9 |
|
| 10 |
use Automattic\WooCommerce\Utilities\OrderUtil; |
| 11 |
|
| 12 |
/** |
| 13 |
* Advance stale CPT order post dates after meta-only saves. |
| 14 |
* HPOS already advances its own date_updated_gmt on persistence. |
| 15 |
*/ |
| 16 |
class Order_Modified_Date { |
| 17 |
/** |
| 18 |
* Advance an order's post_modified(_gmt) beyond its previous value. |
| 19 |
* |
| 20 |
* @param int $order_id The order post ID. |
| 21 |
*/ |
| 22 |
public static function touch( int $order_id ): void { |
| 23 |
if ( class_exists( OrderUtil::class ) && OrderUtil::custom_orders_table_usage_is_enabled() ) { |
| 24 |
return; |
| 25 |
} |
| 26 |
global $wpdb; |
| 27 |
|
| 28 |
$previous_gmt = (string) get_post_field( 'post_modified_gmt', $order_id ); |
| 29 |
$modified_gmt = gmdate( |
| 30 |
'Y-m-d H:i:s', |
| 31 |
max( time(), strtotime( $previous_gmt . ' UTC' ) + 1 ) |
| 32 |
); |
| 33 |
|
| 34 |
$wpdb->update( |
| 35 |
$wpdb->posts, |
| 36 |
array( |
| 37 |
'post_modified' => get_date_from_gmt( $modified_gmt ), |
| 38 |
'post_modified_gmt' => $modified_gmt, |
| 39 |
), |
| 40 |
array( 'ID' => $order_id ), |
| 41 |
array( '%s', '%s' ), |
| 42 |
array( '%d' ) |
| 43 |
); |
| 44 |
|
| 45 |
clean_post_cache( $order_id ); |
| 46 |
} |
| 47 |
} |
| 48 |
|