Completed
Push — master ( fa42ea...62b94a )
by Naveen
01:08
created
src/wordlift/vocabulary/class-analysis-background-service.php 2 patches
Indentation   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -6,136 +6,136 @@
 block discarded – undo
6 6
 class Analysis_Background_Service {
7 7
 
8 8
 
9
-	const ANALYSIS_DONE_FLAG = '_wl_cmkg_analysis_complete_for_term_options_cache';
10
-	const TERMS_COUNT_TRANSIENT = '_wl_cmkg_analysis_background_service_terms_count';
11
-	const ENTITIES_PRESENT_FOR_TERM = '_wl_cmkg_analysis_entities_present_for_term_options_cache';
12
-
13
-	/**
14
-	 * @var Analysis_Service
15
-	 */
16
-	private $analysis_service;
17
-	/**
18
-	 * @var Analysis_Background_Process
19
-	 */
20
-	private $analysis_background_process;
21
-
22
-	/**
23
-	 * @var \Wordlift_Log_Service
24
-	 */
25
-	private $log;
26
-
27
-
28
-	public function __construct( $analysis_service ) {
29
-
30
-		$this->analysis_service = $analysis_service;
31
-
32
-		$this->analysis_background_process = new Analysis_Background_Process( $this );
33
-
34
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
35
-	}
36
-
37
-	public function start() {
38
-		$this->analysis_background_process->start();
39
-	}
9
+    const ANALYSIS_DONE_FLAG = '_wl_cmkg_analysis_complete_for_term_options_cache';
10
+    const TERMS_COUNT_TRANSIENT = '_wl_cmkg_analysis_background_service_terms_count';
11
+    const ENTITIES_PRESENT_FOR_TERM = '_wl_cmkg_analysis_entities_present_for_term_options_cache';
12
+
13
+    /**
14
+     * @var Analysis_Service
15
+     */
16
+    private $analysis_service;
17
+    /**
18
+     * @var Analysis_Background_Process
19
+     */
20
+    private $analysis_background_process;
21
+
22
+    /**
23
+     * @var \Wordlift_Log_Service
24
+     */
25
+    private $log;
26
+
27
+
28
+    public function __construct( $analysis_service ) {
29
+
30
+        $this->analysis_service = $analysis_service;
31
+
32
+        $this->analysis_background_process = new Analysis_Background_Process( $this );
33
+
34
+        $this->log = \Wordlift_Log_Service::get_logger( get_class() );
35
+    }
36
+
37
+    public function start() {
38
+        $this->analysis_background_process->start();
39
+    }
40 40
 
41
-	public function cancel() {
42
-		$this->analysis_background_process->cancel();
43
-	}
41
+    public function cancel() {
42
+        $this->analysis_background_process->cancel();
43
+    }
44 44
 
45
-	public function stop() {
46
-		$this->analysis_background_process->cancel();
47
-		$this->analysis_background_process->request_cancel();
48
-	}
45
+    public function stop() {
46
+        $this->analysis_background_process->cancel();
47
+        $this->analysis_background_process->request_cancel();
48
+    }
49 49
 
50
-	/**
51
-	 * A list of term ids.
52
-	 * @return int|\WP_Error|\WP_Term[]
53
-	 */
54
-	public function next() {
50
+    /**
51
+     * A list of term ids.
52
+     * @return int|\WP_Error|\WP_Term[]
53
+     */
54
+    public function next() {
55 55
 
56
-		$state = $this->info();
56
+        $state = $this->info();
57 57
 
58
-		return Terms_Compat::get_terms( Terms_Compat::get_public_taxonomies(), array(
59
-			'fields'     => 'ids',
60
-			'hide_empty' => false,
61
-			'number'     => $this->get_batch_size(),
62
-			'offset'     => $state->index,
63
-			'meta_query' => array(
64
-				array(
65
-					'key'     => self::ANALYSIS_DONE_FLAG,
66
-					'compare' => 'NOT EXISTS'
67
-				)
68
-			),
69
-		) );
70
-	}
58
+        return Terms_Compat::get_terms( Terms_Compat::get_public_taxonomies(), array(
59
+            'fields'     => 'ids',
60
+            'hide_empty' => false,
61
+            'number'     => $this->get_batch_size(),
62
+            'offset'     => $state->index,
63
+            'meta_query' => array(
64
+                array(
65
+                    'key'     => self::ANALYSIS_DONE_FLAG,
66
+                    'compare' => 'NOT EXISTS'
67
+                )
68
+            ),
69
+        ) );
70
+    }
71 71
 
72
-	public function count() {
72
+    public function count() {
73 73
 
74
-		$count = count( Terms_Compat::get_terms(
75
-			Terms_Compat::get_public_taxonomies(),
76
-			array(
77
-			'fields'     => 'ids',
78
-			'hide_empty' => false,
79
-			// return all terms, we cant pass -1 here.
80
-			'number'     => 0,
81
-			'meta_query' => array(
82
-				array(
83
-					'key'     => self::ANALYSIS_DONE_FLAG,
84
-					'compare' => 'NOT EXISTS'
85
-				)
86
-			),
87
-		) ) );
74
+        $count = count( Terms_Compat::get_terms(
75
+            Terms_Compat::get_public_taxonomies(),
76
+            array(
77
+            'fields'     => 'ids',
78
+            'hide_empty' => false,
79
+            // return all terms, we cant pass -1 here.
80
+            'number'     => 0,
81
+            'meta_query' => array(
82
+                array(
83
+                    'key'     => self::ANALYSIS_DONE_FLAG,
84
+                    'compare' => 'NOT EXISTS'
85
+                )
86
+            ),
87
+        ) ) );
88 88
 
89
-		$this->log->debug( "Count returned as $count" );
89
+        $this->log->debug( "Count returned as $count" );
90 90
 
91 91
 
92
-		return $count;
93
-	}
92
+        return $count;
93
+    }
94 94
 
95
-	public function get_batch_size() {
96
-		return 10;
97
-	}
95
+    public function get_batch_size() {
96
+        return 10;
97
+    }
98 98
 
99
-	public function info() {
100
-		return Analysis_Background_Process::get_state();
101
-	}
99
+    public function info() {
100
+        return Analysis_Background_Process::get_state();
101
+    }
102 102
 
103
-	/**
104
-	 * @param $term_ids
105
-	 *
106
-	 * @return bool
107
-	 */
108
-	public function perform_analysis_for_terms( $term_ids ) {
103
+    /**
104
+     * @param $term_ids
105
+     *
106
+     * @return bool
107
+     */
108
+    public function perform_analysis_for_terms( $term_ids ) {
109 109
 
110
-		foreach ( $term_ids as $term_id ) {
110
+        foreach ( $term_ids as $term_id ) {
111 111
 
112
-			$tag = get_term( $term_id );
112
+            $tag = get_term( $term_id );
113 113
 
114
-			// This adds the entities to ttl cache
115
-			$result = $this->analysis_service->get_entities( $tag );
114
+            // This adds the entities to ttl cache
115
+            $result = $this->analysis_service->get_entities( $tag );
116 116
 
117
-			$this->log->debug( "Received result " . var_export( $result ) . " for ${term_id}" );
117
+            $this->log->debug( "Received result " . var_export( $result ) . " for ${term_id}" );
118 118
 
119
-			// then set the analysis complete flag.
120
-			update_term_meta( $term_id, self::ANALYSIS_DONE_FLAG, 1 );
119
+            // then set the analysis complete flag.
120
+            update_term_meta( $term_id, self::ANALYSIS_DONE_FLAG, 1 );
121 121
 
122
-			if ( $result !== false ) {
123
-				if ( count( $result ) > 0 ) {
124
-					update_term_meta( $term_id, self::ENTITIES_PRESENT_FOR_TERM, 1 );
125
-				}
126
-			}
122
+            if ( $result !== false ) {
123
+                if ( count( $result ) > 0 ) {
124
+                    update_term_meta( $term_id, self::ENTITIES_PRESENT_FOR_TERM, 1 );
125
+                }
126
+            }
127 127
 
128
-		}
128
+        }
129 129
 
130
-		/**
131
-		 * This action fires when the analysis is complete for the current batch
132
-		 * @since 3.30.0
133
-		 */
134
-		do_action( 'wordlift_vocabulary_analysis_complete_for_terms_batch' );
135
-
136
-		return true;
137
-
138
-
139
-	}
130
+        /**
131
+         * This action fires when the analysis is complete for the current batch
132
+         * @since 3.30.0
133
+         */
134
+        do_action( 'wordlift_vocabulary_analysis_complete_for_terms_batch' );
135
+
136
+        return true;
137
+
138
+
139
+    }
140 140
 
141 141
 }
142 142
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -25,13 +25,13 @@  discard block
 block discarded – undo
25 25
 	private $log;
26 26
 
27 27
 
28
-	public function __construct( $analysis_service ) {
28
+	public function __construct($analysis_service) {
29 29
 
30 30
 		$this->analysis_service = $analysis_service;
31 31
 
32
-		$this->analysis_background_process = new Analysis_Background_Process( $this );
32
+		$this->analysis_background_process = new Analysis_Background_Process($this);
33 33
 
34
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
34
+		$this->log = \Wordlift_Log_Service::get_logger(get_class());
35 35
 	}
36 36
 
37 37
 	public function start() {
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 
56 56
 		$state = $this->info();
57 57
 
58
-		return Terms_Compat::get_terms( Terms_Compat::get_public_taxonomies(), array(
58
+		return Terms_Compat::get_terms(Terms_Compat::get_public_taxonomies(), array(
59 59
 			'fields'     => 'ids',
60 60
 			'hide_empty' => false,
61 61
 			'number'     => $this->get_batch_size(),
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 					'compare' => 'NOT EXISTS'
67 67
 				)
68 68
 			),
69
-		) );
69
+		));
70 70
 	}
71 71
 
72 72
 	public function count() {
73 73
 
74
-		$count = count( Terms_Compat::get_terms(
74
+		$count = count(Terms_Compat::get_terms(
75 75
 			Terms_Compat::get_public_taxonomies(),
76 76
 			array(
77 77
 			'fields'     => 'ids',
@@ -84,9 +84,9 @@  discard block
 block discarded – undo
84 84
 					'compare' => 'NOT EXISTS'
85 85
 				)
86 86
 			),
87
-		) ) );
87
+		) ));
88 88
 
89
-		$this->log->debug( "Count returned as $count" );
89
+		$this->log->debug("Count returned as $count");
90 90
 
91 91
 
92 92
 		return $count;
@@ -105,23 +105,23 @@  discard block
 block discarded – undo
105 105
 	 *
106 106
 	 * @return bool
107 107
 	 */
108
-	public function perform_analysis_for_terms( $term_ids ) {
108
+	public function perform_analysis_for_terms($term_ids) {
109 109
 
110
-		foreach ( $term_ids as $term_id ) {
110
+		foreach ($term_ids as $term_id) {
111 111
 
112
-			$tag = get_term( $term_id );
112
+			$tag = get_term($term_id);
113 113
 
114 114
 			// This adds the entities to ttl cache
115
-			$result = $this->analysis_service->get_entities( $tag );
115
+			$result = $this->analysis_service->get_entities($tag);
116 116
 
117
-			$this->log->debug( "Received result " . var_export( $result ) . " for ${term_id}" );
117
+			$this->log->debug("Received result ".var_export($result)." for ${term_id}");
118 118
 
119 119
 			// then set the analysis complete flag.
120
-			update_term_meta( $term_id, self::ANALYSIS_DONE_FLAG, 1 );
120
+			update_term_meta($term_id, self::ANALYSIS_DONE_FLAG, 1);
121 121
 
122
-			if ( $result !== false ) {
123
-				if ( count( $result ) > 0 ) {
124
-					update_term_meta( $term_id, self::ENTITIES_PRESENT_FOR_TERM, 1 );
122
+			if ($result !== false) {
123
+				if (count($result) > 0) {
124
+					update_term_meta($term_id, self::ENTITIES_PRESENT_FOR_TERM, 1);
125 125
 				}
126 126
 			}
127 127
 
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 		 * This action fires when the analysis is complete for the current batch
132 132
 		 * @since 3.30.0
133 133
 		 */
134
-		do_action( 'wordlift_vocabulary_analysis_complete_for_terms_batch' );
134
+		do_action('wordlift_vocabulary_analysis_complete_for_terms_batch');
135 135
 
136 136
 		return true;
137 137
 
Please login to merge, or discard this patch.