forked from woocommerce/woocommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass-wc-privacy-background-process.php
70 lines (61 loc) · 1.67 KB
/
class-wc-privacy-background-process.php
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
67
68
69
70
<?php
/**
* Order cleanup background process.
*
* @package WooCommerce/Classes
* @version 3.4.0
* @since 3.4.0
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'WC_Background_Process', false ) ) {
include_once dirname( __FILE__ ) . '/abstracts/class-wc-background-process.php';
}
/**
* WC_Privacy_Background_Process class.
*/
class WC_Privacy_Background_Process extends WC_Background_Process {
/**
* Initiate new background process.
*/
public function __construct() {
// Uses unique prefix per blog so each blog has separate queue.
$this->prefix = 'wp_' . get_current_blog_id();
$this->action = 'wc_privacy_cleanup';
parent::__construct();
}
/**
* Code to execute for each item in the queue
*
* @param string $item Queue item to iterate over.
* @return bool
*/
protected function task( $item ) {
if ( ! $item || empty( $item['task'] ) ) {
return false;
}
$process_count = 0;
$process_limit = 20;
switch ( $item['task'] ) {
case 'trash_pending_orders':
$process_count = WC_Privacy::trash_pending_orders( $process_limit );
break;
case 'trash_failed_orders':
$process_count = WC_Privacy::trash_failed_orders( $process_limit );
break;
case 'trash_cancelled_orders':
$process_count = WC_Privacy::trash_cancelled_orders( $process_limit );
break;
case 'anonymize_completed_orders':
$process_count = WC_Privacy::anonymize_completed_orders( $process_limit );
break;
case 'delete_inactive_accounts':
$process_count = WC_Privacy::delete_inactive_accounts( $process_limit );
break;
}
if ( $process_limit === $process_count ) {
// Needs to run again.
return $item;
}
return false;
}
}