acquire_lock() ) { return false; } try { return $this->migrate_site( $network_wide ); } catch ( \Throwable $exception ) { $this->log_failure( $exception ); return false; } finally { $this->release_lock(); } } public function migrate_site( $network_wide = false ) { $current = (int) get_option( self::VERSION_OPTION, 0 ); if ( $current < SettingsSchema::VERSION ) { Lifecycle::install_site_defaults(); do_action( 'artbees_qv/lifecycle/migrate', $current, SettingsSchema::VERSION, $network_wide ); update_option( self::VERSION_OPTION, SettingsSchema::VERSION, true ); } else { do_action( 'artbees_qv/lifecycle/migrate', $current, $current, $network_wide ); } return (int) get_option( self::VERSION_OPTION, 0 ) === SettingsSchema::VERSION; } private function acquire_lock() { $lock = get_option( self::LOCK, array() ); if ( is_array( $lock ) && ! empty( $lock['started'] ) && ( time() - (int) $lock['started'] ) < 600 ) { return false; } return update_option( self::LOCK, array( 'token' => wp_generate_uuid4(), 'started' => time() ), false ) || empty( $lock ); } private function release_lock() { delete_option( self::LOCK ); } private function log_failure( \Throwable $exception ) { do_action( 'artbees_qv/lifecycle/migration_failed', sanitize_text_field( $exception->getMessage() ) ); } }