PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.17
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.17
1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 All 163 releases
woocommerce-pos / includes / updates / update-1.8.12.php

update-1.8.12.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.17, at includes/updates/update-1.8.12.php

63 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Update to 1.8.12
4 *
5 * Remove duplicate postmeta rows on POS-touched posts.
6 *
7 * Since v1.4.0, the REST API response hooks called save_meta_data() on every
8 * read request. On non-HPOS sites this triggered wp_update_post(), which fired
9 * save_post — giving third-party plugins (Jetpack, Astra, Xero, etc.) an
10 * opportunity to add duplicate meta rows via add_post_meta(). Over 2+ years
11 * this accumulated thousands of junk rows per post on some stores.
12 *
13 * This migration keeps the most recent row (highest meta_id) for each
14 * (post_id, meta_key) pair that has more than 20 identical entries, and
15 * deletes the rest. Scoped to posts with _woocommerce_pos_uuid meta.
16 *
17 * @author Paul Kilmurray <paul@kilbot.com>
18 *
19 * @see http://wcpos.com
20 * @package WCPOS\WooCommercePOS
21 */
22
23 namespace WCPOS\WooCommercePOS;
24
25 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery
26 // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching
27 // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Update script with file-scoped variables.
28
29 global $wpdb;
30
31 $wcpos_deleted = $wpdb->query(
32 "DELETE pm FROM {$wpdb->postmeta} pm
33 INNER JOIN (
34 SELECT post_id, meta_key, MAX(meta_id) AS keep_id
35 FROM {$wpdb->postmeta}
36 WHERE post_id IN (
37 SELECT DISTINCT post_id FROM {$wpdb->postmeta}
38 WHERE meta_key = '_woocommerce_pos_uuid'
39 )
40 GROUP BY post_id, meta_key
41 HAVING COUNT(*) > 20
42 ) dups ON pm.post_id = dups.post_id
43 AND pm.meta_key = dups.meta_key
44 AND pm.meta_id != dups.keep_id"
45 );
46
47 if ( \function_exists( 'wc_get_logger' ) ) {
48 $wcpos_logger = wc_get_logger();
49 if ( false === $wcpos_deleted ) {
50 $wcpos_logger->error(
51 'WCPOS 1.8.12 migration: database query failed when removing duplicate meta rows.',
52 array( 'source' => 'woocommerce-pos' )
53 );
54 } else {
55 $wcpos_logger->info(
56 sprintf( 'WCPOS 1.8.12 migration: removed %d duplicate meta rows from POS-touched posts.', (int) $wcpos_deleted ),
57 array( 'source' => 'woocommerce-pos' )
58 );
59 }
60 }
61
62 // phpcs:enable
63