drain( ! WP_CLI\Utils\get_flag_value( $assoc, 'deploy', true ) ); } /** Push the current export folder to the configured target. */ public function deploy() { if ( ! CFSP_Settings::is_configured() ) { WP_CLI::error( 'Destination settings are incomplete.' ); } $result = CFSP_Deployer::deploy_now( array( 'reason' => 'WP-CLI deploy' ) ); if ( is_wp_error( $result ) ) { WP_CLI::error( $result->get_error_message() ); } WP_CLI::success( 'Deployed: ' . ( $result['url'] ?? '' ) ); } /** Cancel the running job. */ public function cancel() { CFSP_Job::cancel(); WP_CLI::success( 'Cancelled.' ); } /** Show the current job. */ public function status() { $job = CFSP_Job::get(); if ( ! $job ) { WP_CLI::log( 'No jobs yet.' ); return; } WP_CLI::log( sprintf( '%s job (%s): %d/%d URLs, %d errors. %s', $job['type'], $job['phase'], $job['processed'], $job['total'], $job['errors'], $job['message'] ) ); } private function drain( $export_only ) { while ( true ) { $job = CFSP_Job::get(); if ( ! $job || ! CFSP_Job::is_active( $job ) ) { break; } if ( $export_only && 'crawl' !== $job['phase'] ) { CFSP_Job::cancel(); WP_CLI::success( 'Export finished in ' . CFSP_Settings::export_dir() ); return; } if ( ! CFSP_Job::run_batch( false ) ) { sleep( 2 ); // Another worker holds the lock. } } $job = CFSP_Job::get(); 'done' === $job['phase'] ? WP_CLI::success( $job['message'] ) : WP_CLI::error( $job['message'] ? $job['message'] : $job['phase'] ); } }