Completed
Push — add/sync-rest-2 ( dfd2b5...6141a8 )
by
unknown
115:00 queued 105:06
created

Jetpack_Sync_Full::enqueue_all_posts()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 17
rs 9.4285
cc 2
eloc 8
nc 2
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
		$this->enqueue_all_comments();
16
	}
17
18
	private function enqueue_all_posts() {
19
		global $wpdb;
20
21
		// I hope this is never bigger than RAM...
22
		$post_ids = $wpdb->get_col( "SELECT id FROM $wpdb->posts");
23
24
		// Request posts in groups of N for efficiency
25
		$chunked_post_ids = array_chunk( $post_ids, self::$array_chunk_size );
26
27
		foreach ( $chunked_post_ids as $chunk ) {
28
			$posts = get_posts( array( 'post__in' => $chunk, 'post_status' => 'any' ) );
29
30
			error_log(print_r($posts, 1));
31
32
			do_action( 'jp_full_sync_posts', $posts );
33
		}
34
	}
35
36
	private function enqueue_all_comments() {
37
		global $wpdb;
38
39
		$comment_ids = $wpdb->get_col( "SELECT comment_id FROM $wpdb->comments");
40
		$chunked_comment_ids = array_chunk( $comment_ids, self::$array_chunk_size );
41
42
		foreach ( $chunked_comment_ids as $chunk ) {
43
			$comments = get_comments( array( 'comment__in' => $chunk ) );
44
			do_action( 'jp_full_sync_comments', $comments );
45
		}
46
	}
47
	
48
}