job_repository = $job_repository; } /** * Update Jobs that need to be run per version. * * @var array */ private $updates = [ '1.0.1' => [ CleanupProductTargetCountriesJob::class, UpdateAllProducts::class, ], '1.12.6' => [ UpdateAllProducts::class, ], ]; /** * Run installation logic for this class. * * @param string $old_version Previous version before updating. * @param string $new_version Current version after updating. */ public function install( string $old_version, string $new_version ): void { foreach ( $this->updates as $version => $jobs ) { if ( version_compare( $old_version, $version, '<' ) ) { $this->schedule_jobs( $jobs ); } } } /** * Schedules a list of jobs. * * @param array $jobs List of jobs */ protected function schedule_jobs( array $jobs ): void { foreach ( $jobs as $job ) { try { $this->job_repository->get( $job )->schedule(); } catch ( JobException $e ) { do_action( 'woocommerce_gla_exception', $e, __METHOD__ ); } } } }