Test Failed
Push — master ( dc11f8...b6268a )
by Stiofan
54s
created

GeoDir_Privacy_Background_Process   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B task() 0 23 6
1
<?php
2
/**
3
 * GeoDirectory data cleanup background process.
4
 *
5
 * @package GeoDirectory
6
 * @since   1.2.26
7
 */
8
9
defined( 'ABSPATH' ) || exit;
10
11
if ( ! class_exists( 'GeoDir_Background_Process', false ) ) {
12
	include_once( 'class-geodir-background-process.php' );
13
}
14
15
/**
16
 * GeoDir_Privacy_Background_Process class.
17
 */
18
class GeoDir_Privacy_Background_Process extends GeoDir_Background_Process {
19
20
	/**
21
	 * Initiate new background process.
22
	 */
23
	public function __construct() {
24
		// Uses unique prefix per blog so each blog has separate queue.
25
		$this->prefix = 'wp_' . get_current_blog_id();
26
		$this->action = 'geodir_privacy_cleanup';
27
		parent::__construct();
28
	}
29
30
	/**
31
	 * Code to execute for each item in the queue
32
	 *
33
	 * @param string $item Queue item to iterate over.
34
	 * @return bool
35
	 */
36
	protected function task( $item ) {
37
		if ( ! $item || empty( $item['task'] ) ) {
38
			return false;
39
		}
40
41
		$process_count = 0;
42
		$process_limit = 20;
43
44
		switch ( $item['task'] ) {
45
			case 'trash_pending_posts':
46
				$process_count = GeoDir_Privacy::trash_pending_posts( $process_limit );
47
				break;
48
			case 'anonymize_published_posts':
49
				$process_count = GeoDir_Privacy::anonymize_published_posts( $process_limit );
50
				break;
51
		}
52
53
		if ( $process_limit === $process_count ) {
54
			return $item;
55
		}
56
57
		return false;
58
	}
59
}
60