Completed
Push — add/sync-rest-2 ( ae2fc3...dfd2b5 )
by
unknown
137:46 queued 127:52
created

Jetpack_Sync_Full::start()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * This class does a full resync of the database by 
5
 * enqueuing an outbound action for every single object
6
 * that we care about
7
 */
8
9
class Jetpack_Sync_Full {
10
	static $array_chunk_size = 5;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $array_chunk_size.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
11
12
	function start() {
13
		// TODO
0 ignored issues
show
Coding Style introduced by
Comment refers to a TODO task

This check looks TODO comments that have been left in the code.

``TODO``s show that something is left unfinished and should be attended to.

Loading history...
14
		$this->enqueue_all_posts();
15
	}
16
17
	private function enqueue_all_posts() {
18
		global $wpdb;
19
20
		// I hope this is never bigger than RAM...
21
		$post_ids = $wpdb->get_col( "SELECT id FROM $wpdb->posts");
22
23
		// Request posts in groups of N for efficiency
24
		$chunked_post_ids = array_chunk( $post_ids, self::$array_chunk_size );
25
26
		foreach ( $chunked_post_ids as $chunk ) {
27
			$posts = get_posts( array( 'post__in' => $chunk, 'post_status' => 'any' ) );
28
			foreach ( $posts as $post ) {
29
				do_action( 'jp_full_sync_post', $post );
30
			}
31
		}
32
	}
33
	
34
}