Skip to content

Commit 47ec96e

Browse files
committed
make pagination optional
1 parent 6873436 commit 47ec96e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

php/traits/trait-cli.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function sync( $args, $assoc_args ) {
104104

105105
// Get assets that need to be synced.
106106
$query = new \WP_Query( $query_args );
107-
$this->do_process( $query, 'sync' );
107+
$this->do_process( $query, 'sync', false );
108108
if ( ! $query->have_posts() ) {
109109
\WP_CLI::log( \WP_CLI::colorize( '%gAll assets synced.%n' ) );
110110
delete_option( '_cld_cli_analyzed' );
@@ -142,10 +142,11 @@ public function analyze() {
142142
*
143143
* @since 2.5.1
144144
*
145-
* @param \WP_Query $query The initial query object.
146-
* @param string $process The process to do.
145+
* @param \WP_Query $query The initial query object.
146+
* @param string $process The process to do.
147+
* @param bool $paginate Flag to paginate.
147148
*/
148-
protected function do_process( &$query, $process ) {
149+
protected function do_process( &$query, $process, $paginate = true ) {
149150
$this->do_intro();
150151

151152
// Bail early.
@@ -165,9 +166,14 @@ protected function do_process( &$query, $process ) {
165166
// Free up memory.
166167
$this->stop_the_insanity();
167168

169+
// Sleep for a catchup.
170+
sleep( 1 );
171+
168172
// Paginate.
169173
$query_args = $query->query_vars;
170-
$query_args['paged'] ++;
174+
if ( true === $paginate ) {
175+
$query_args['paged'] ++;
176+
}
171177
$query = new \WP_Query( $query_args );
172178
} while ( $query->have_posts() );
173179
}
@@ -191,7 +197,7 @@ protected function process_sync( $posts, $total ) {
191197
$done ++; // Set $done early to not show 0 of x.
192198
$file = get_attached_file( $asset );
193199
$filename = self::pad_name( basename( $file ), 20, ' ', '*' );
194-
$bar->tick( 0, 'Syncing (' . ( $done ) . ' of ' . $total . ') : ' . $filename );
200+
$bar->tick( 1, 'Syncing (' . ( $done ) . ' of ' . $total . ') : ' . $filename );
195201
if ( ! $this->plugin->get_component( 'sync' )->is_synced( $asset ) ) {
196202
$this->plugin->get_component( 'sync' )->managers['push']->process_assets( $asset, $bar );
197203
}

0 commit comments

Comments
 (0)