'CatalogRelay Safe Importer for WooCommerce', 'php' => '7.4', 'wp' => '7.0', 'woo' => '10.0', 'woo_required' => true, ); } /** * Requirements checked while the plugin file loads: WooCommerce may load after this plugin, so its presence is checked * at plugins_loaded instead (see boot()), and only the PHP and WordPress versions are checked here. * * @return array */ public static function loadRequirements(): array { $req = self::requirements(); unset( $req['woo_required'], $req['woo'] ); return $req; } /** * Whether WooCommerce is active in a supported version (the importer's hooks are registered only then). * * @return bool */ public static function wooReady(): bool { return class_exists( 'WooCommerce' ) && defined( 'WC_VERSION' ) && version_compare( (string) WC_VERSION, self::requirements()['woo'], '>=' ); } /** * Product descriptor for the library (built once). * * @return ProductDescriptor */ public static function descriptor(): ProductDescriptor { if ( null === self::$descriptor ) { $d = new ProductDescriptor( array( 'id' => 'catalogrelay', 'name' => 'CatalogRelay', 'prefix' => 'catalogrelay_', 'slug' => Page::SLUG . '-settings', // The library's settings page; Page::SLUG is the import app. 'textDomain' => 'catalogrelay', 'file' => self::$file, 'version' => self::VERSION, 'capability' => 'manage_woocommerce', 'modules' => array( 'settings', 'log', 'jobs', 'plans', 'ledger', 'notify', 'compat', 'lifecycle' ), 'uninstallDefault' => 'delete', 'uninstallKey' => 'uninstall_delete', 'jobRetentionDays' => 90, 'ledgerRetentionDays' => 7, 'uninstall' => array( 'tables' => array( 'job_rows' ), 'options_like' => array( 'catalogrelay_' ), 'meta' => array( 'post' => array( '_catalogrelay_row_key', '_catalogrelay_source', '_catalogrelay_url_sha1', '_catalogrelay_stock_applied' ), ), 'cron' => array( Cleanup::CRON, Cleanup::CRON_CONTINUE ), 'as_groups' => array( 'catalogrelay', 'catalogrelay_jobs' ), 'dirs_always' => array( 'catalogrelay' ), 'dirs_on_delete' => array(), ), 'menuItems' => Page::menuItems(), 'healthTests' => SiteHealthTests::tests(), 'requirements' => self::requirements(), 'compat' => array( 'hpos' => true, 'blocks' => true, ), 'appSchema' => 2, 'migrations' => array( 1 => static function () { Schema::install(); }, 2 => static function () { Schema::install(); Schema::upgradeTo2(); }, ), ) ); $d->settings = SettingsDeclaration::declaration( $d ); self::$descriptor = $d; } return self::$descriptor; } /** * Activation: tables and schedule. * * @param bool $network_wide Network activation. * @return void */ public static function activate( bool $network_wide ): void { Bootstrap::activate( self::descriptor(), $network_wide ); Cleanup::schedule(); } /** * Deactivation: the library clears its schedule and ours (declared in the uninstall manifest), on every site for a * network deactivation. Data stays. Our own Action Scheduler actions (current site) would fail while no callback * exists: waiting downloads end with their warning, the recurring actions of scheduled imports are removed and waiting * repairs are set aside; the self-heal in boot() registers both again once the plugin runs. * * @param bool $network_wide Network deactivation. * @return void */ public static function deactivate( bool $network_wide = false ): void { ImageQueue::abandonPending(); ScheduledImport::unschedule(); Finalizer::park(); Bootstrap::deactivate( self::descriptor(), $network_wide ); } /** * Request-time wiring (plugins_loaded, priority 11, after the library booted at 10). * * @return void */ public static function boot(): void { Cleanup::hook(); // Also without WooCommerce: uploaded files and failed-rows CSVs still expire (NFR-012). if ( ! self::wooReady() ) { add_action( 'admin_notices', static function () { if ( current_user_can( 'activate_plugins' ) ) { echo '

' . esc_html__( 'CatalogRelay Safe Importer needs WooCommerce 10.0 or newer to be installed and active.', 'catalogrelay' ) . '

'; } } ); return; } JobEngine::registerType( new ImportJobType() ); JobEngine::registerType( new RetryJobType() ); JobEngine::registerType( new DryRunJobType() ); Ledger::registerAdapter( new PriceAdapter() ); Ledger::registerAdapter( new StockAdapter() ); Ledger::registerAdapter( new StatusAdapter() ); Ledger::registerAdapter( new CreatedAdapter() ); add_action( 'catalogrelay_core_job_item_failed', static function ( $job, $type, $key, $payload, $code ) { AbstractFileJob::engineFailed( (int) $job, (string) $type, (array) $payload, (string) $code, (string) $key ); }, 10, 5 ); add_action( 'catalogrelay_core_job_chunk_end', static function () { if ( BulkMode::active() ) { BulkMode::leave(); // Wrap-up at the end of the chunk (P09-FR-013): the worker may go on with other work. } TermResolver::reset(); // Term ids are cached for one chunk: terms may be deleted or merged between chunks. } ); add_action( ImageQueue::HOOK, static function ( $job, $row, $offset, $product, $slot, $url, $attempt = 1 ) { ImageAction::run( (int) $job, (int) $row, (int) $offset, (int) $product, (int) $slot, (string) $url, (int) $attempt ); }, 10, 7 ); // A download whose process died ends with its warning instead of staying open. add_action( 'action_scheduler_unexpected_shutdown', array( ImageAction::class, 'abandoned' ), 10, 1 ); add_action( 'action_scheduler_failed_action', array( ImageAction::class, 'abandoned' ), 10, 1 ); add_action( Finalizer::HOOK, static function ( $job ) { Finalizer::run( (int) $job ); } ); ScheduledImport::hook(); // Self-heal of our own Action Scheduler actions, in the requests where the library heals its cron events. $heal = static function () { ScheduledImport::heal(); Finalizer::requeueParked(); }; if ( is_admin() ) { add_action( 'admin_init', $heal ); } elseif ( wp_doing_cron() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { add_action( 'init', $heal ); } Routes::hook(); if ( is_admin() ) { Page::hook(); } } }