1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
<?php
/** * Update to 3.6.0 * * Migrates single workflow unsubscribe data to unsubscribe to all workflows system. */
namespace AutomateWoo\DatabaseUpdates;
use AutomateWoo\Customer_Factory;
if ( ! defined( 'ABSPATH' ) ) { exit; }
/** * Class Database_Update_3_6_0 * * @package AutomateWoo\DatabaseUpdates */ class Database_Update_3_6_0 extends AbstractDatabaseUpdate {
/** @var string */ protected $version = '3.6.0';
/** * @return bool */ protected function process() { global $wpdb;
$table = $wpdb->prefix . 'automatewoo_unsubscribes'; $sql = "SELECT * FROM `{$table}` GROUP BY `{$table}`.id LIMIT 15"; // phpcs:disable WordPress.DB.PreparedSQL $results = $wpdb->get_results( $sql, ARRAY_A ); // phpcs:enable
if ( empty( $results ) ) { return true; // no more items to process, return complete }
foreach ( $results as $unsubscribe ) {
$customer = Customer_Factory::get( $unsubscribe['customer_id'] );
if ( $customer ) { // customer might have been deleted
if ( ! $customer->get_is_unsubscribed() ) { // set new unsub prop if not already set $customer->set_is_unsubscribed( true ); $customer->set_date_unsubscribed( $unsubscribe['date'] ); $customer->save(); } }
$wpdb->delete( $table, [ 'id' => $unsubscribe['id'] ] );
++$this->items_processed; }
return false; } }
return new Database_Update_3_6_0();
|