*/ final class Commands { /** @var OmnibusImporter */ private $importer; public function __construct( OmnibusImporter $importer ) { $this->importer = $importer; } public static function register( OmnibusImporter $importer ): void { $command = array( new self( $importer ), 'import_omnibus' ); \WP_CLI::add_command( 'strikewise import-omnibus', $command ); // The name of version 1.0.0, kept for scripts that already use it. \WP_CLI::add_command( 'priceproof import-omnibus', $command ); } /** * Imports the price history of the "Omnibus — show the lowest price" plugin. * * Products that were already imported are skipped. The Omnibus data is only read. * * ## EXAMPLES * * wp strikewise import-omnibus * * @param string[] $args * @param array $assoc_args */ public function import_omnibus( $args, $assoc_args ): void { delete_transient( OmnibusImporter::TRANSIENT ); if ( ! $this->importer->has_data() ) { \WP_CLI::success( 'No Omnibus data found.' ); return; } $this->importer->start( false ); do { $processed = $this->importer->run_batch( false ); $state = OmnibusImporter::state(); \WP_CLI::log( sprintf( 'Up to product #%d: %d products, %d price periods imported.', $state['last_id'], $state['products'], $state['intervals'] ) ); } while ( OmnibusImporter::STATUS_RUNNING === $state['status'] && $processed > 0 ); \WP_CLI::success( sprintf( '%d products with %d price periods imported.', $state['products'], $state['intervals'] ) ); } }