diff --git a/inc/Config/ArraySerializable.php b/inc/Config/ArraySerializable.php index 94f39dd4..1efaaa64 100644 --- a/inc/Config/ArraySerializable.php +++ b/inc/Config/ArraySerializable.php @@ -91,4 +91,15 @@ protected static function get_implementor( array $config ): ?string { * @inheritDoc */ abstract public static function get_config_schema(): array; + + /** + * Migrates the config to the current schema version. + * Can be overridden by child classes to perform custom migrations. + * + * @param array $config The config to migrate. + * @return array The migrated config. + */ + protected static function migrate_config( array $config ): array|WP_Error { + return $config; + } } diff --git a/inc/Config/DataSource/HttpDataSource.php b/inc/Config/DataSource/HttpDataSource.php index 06f10c84..b3ea7723 100644 --- a/inc/Config/DataSource/HttpDataSource.php +++ b/inc/Config/DataSource/HttpDataSource.php @@ -44,7 +44,7 @@ final public function get_service_name(): string { * define their own validation schema. */ public static function preprocess_config( array $config ): array|WP_Error { - $config = static::perform_migration( $config ); + $config = static::migrate_config( $config ); $service_config = $config['service_config'] ?? []; $validator = new Validator( static::get_service_config_schema() ); @@ -65,31 +65,6 @@ public static function preprocess_config( array $config ): array|WP_Error { ); } - /** - * Performs a migration if the config is out of date. - */ - private static function perform_migration( array $config ): array { - // By default, we want to have an active data source. - if ( ! isset( $config['active'] ) ) { - $config['active'] = true; - } - - if ( static::SERVICE_SCHEMA_VERSION === $config['service_config']['__version'] ) { - return $config; - } - - $migrated_config = static::migrate_config( $config ); - - if ( is_wp_error( $migrated_config ) ) { - $config['active'] = false; - } else { - $config['service_config']['__version'] = static::SERVICE_SCHEMA_VERSION; - $config['active'] = true; - } - - return $config; - } - public static function from_uuid( string $uuid ): DataSourceInterface|WP_Error { $config = DataSourceCrud::get_config_by_uuid( $uuid ); @@ -134,10 +109,10 @@ protected static function map_service_config( array $service_config ): array { } /** - * Migrates the config to the current schema version. - * Can be overridden by child classes to perform custom migrations. + * @inheritDoc */ - protected static function migrate_config( array $config ): array { - return $config; + protected static function migrate_config( array $config ): array|WP_Error { + return static::migrate_config( $config ); } + }