@@ -72,14 +72,23 @@ trait CLI_Trait {
7272
7373 /**
7474 * Is debug mode on.
75- * Either verbose or export flags.git
75+ * Either verbose or export flags.
7676 *
7777 * @since 3.0.3
7878 *
7979 * @var bool
8080 */
8181 protected $ is_debug_enabled = false ;
8282
83+ /**
84+ * Clean up flag.
85+ *
86+ * @since 3.2.0
87+ *
88+ * @var bool
89+ */
90+ protected $ clean_up = false ;
91+
8392 /**
8493 * CLI Cloudinary Setup.
8594 *
@@ -114,6 +123,16 @@ protected function do_intro() {
114123 *
115124 * wp cloudinary sync
116125 *
126+ * ## OPTIONS
127+ * [--verbose]
128+ * : Whether to show extra information on unsynced and errored attachments.
129+ *
130+ * [--export]
131+ * : Whether to export CSV files with unsynced and errored attachments.
132+ *
133+ * [--clean-up]
134+ * : Whether to clean up all the error flags.
135+ *
117136 * @when after_wp_load
118137 * @since 2.5.1
119138 *
@@ -133,6 +152,7 @@ public function sync( $args, $assoc_args ) {
133152 $ this ->is_verbose = ! empty ( $ assoc_args ['verbose ' ] );
134153 $ this ->is_export = ! empty ( $ assoc_args ['export ' ] );
135154 $ this ->is_debug_enabled = empty ( $ args ) && ( $ this ->is_verbose || $ this ->is_export );
155+ $ this ->clean_up = ! empty ( $ assoc_args ['clean-up ' ] );
136156
137157 // Initial Query.
138158 $ query_args = $ this ->base_query_args ;
@@ -152,7 +172,6 @@ public function sync( $args, $assoc_args ) {
152172 \WP_CLI ::log ( \WP_CLI ::colorize ( '%gAll assets synced.%n ' ) );
153173 delete_option ( '_cld_cli_analyzed ' );
154174 }
155-
156175 }
157176
158177 /**
@@ -165,6 +184,9 @@ public function sync( $args, $assoc_args ) {
165184 * [--export]
166185 * : Whether to export CSV files with unsynced and errored attachments.
167186 *
187+ * [--clean-up]
188+ * : Whether to clean up all the error flags.
189+ *
168190 * ## EXAMPLES
169191 *
170192 * wp cloudinary analyze
@@ -179,11 +201,14 @@ public function sync( $args, $assoc_args ) {
179201 */
180202 public function analyze ( $ args = null , $ assoc_args = null ) {
181203
204+ static $ did_cleanup = false ;
205+
182206 // Warmup flags if called as command.
183207 if ( ! is_null ( $ args ) && ! is_null ( $ assoc_args ) ) {
184208 $ this ->is_verbose = ! empty ( $ assoc_args ['verbose ' ] );
185209 $ this ->is_export = ! empty ( $ assoc_args ['export ' ] );
186210 $ this ->is_debug_enabled = empty ( $ args ) && ( $ this ->is_verbose || $ this ->is_export );
211+ $ this ->clean_up = ! empty ( $ assoc_args ['clean-up ' ] );
187212 }
188213
189214 // Initial query.
@@ -196,6 +221,14 @@ public function analyze( $args = null, $assoc_args = null ) {
196221
197222 // Do process.
198223 $ this ->do_process ( $ query , 'analyze ' );
224+
225+ // Clean up all the error flags.
226+ if ( $ this ->clean_up && ! $ did_cleanup ) {
227+ $ did_cleanup = true ;
228+
229+ \WP_CLI ::log ( \WP_CLI ::colorize ( '%gCleaning up the error flags.%n ' ) );
230+ delete_post_meta_by_key ( Sync::META_KEYS ['sync_error ' ] );
231+ }
199232 }
200233
201234 /**
@@ -239,7 +272,7 @@ protected function do_process( &$query, $process, $paginate = true ) {
239272 // Paginate.
240273 $ query_args = $ query ->query_vars ;
241274 if ( true === $ paginate ) {
242- $ query_args ['paged ' ] ++ ;
275+ ++ $ query_args ['paged ' ];
243276 }
244277 $ query = new \WP_Query ( $ query_args );
245278 } while ( $ query ->have_posts () );
@@ -261,7 +294,7 @@ protected function process_sync( $posts, $total ) {
261294 $ done = 0 ;
262295 }
263296 foreach ( $ posts as $ index => $ asset ) {
264- $ done ++ ; // Set $done early to not show 0 of x.
297+ ++ $ done ; // Set $done early to not show 0 of x.
265298 $ file = get_attached_file ( $ asset );
266299 $ filename = self ::pad_name ( wp_basename ( $ file ), 20 , ' ' , '* ' );
267300 $ bar ->tick ( 1 , 'Syncing ( ' . ( $ done ) . ' of ' . $ total . ') : ' . $ filename );
@@ -312,7 +345,7 @@ protected function process_analyze( $posts, $total ) {
312345 $ errored_attachments = array ();
313346
314347 foreach ( $ posts as $ asset ) {
315- $ done ++ ;
348+ ++ $ done ;
316349 $ key = '_cld_unsupported ' ;
317350 if (
318351 $ this ->plugin ->get_component ( 'media ' )->is_uploadable_media ( $ asset )
@@ -345,7 +378,7 @@ protected function process_analyze( $posts, $total ) {
345378 }
346379 }
347380 }
348- $ info [ $ key ] ++ ;
381+ ++ $ info [ $ key ];
349382 $ bar ->tick ( 1 , $ done . ' of ' . $ total . ' | ' );
350383 }
351384 // Done message.
0 commit comments