fix: map deprecated platform types in read endpoints for backwards compatibility

Old platform types stored in the database (e.g. flutter-web, apple-ios,
react-native-android) are now mapped to the new consolidated types (web,
apple, android, windows, linux) before being sent in API responses. This
ensures the response models' $conditions correctly select the right model
for each platform document.

Adds Platform::mapDeprecatedType() as a reusable static method and applies
the mapping in both Get and XList platform endpoints.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Damodar Lohani
2026-04-09 07:47:42 +00:00
co-authored by Claude Opus 4.6
parent 7f82484436
commit 196c76ac70
3 changed files with 37 additions and 1 deletions
+30
View File
@@ -47,6 +47,36 @@ class Platform
self::SCHEME_TAURI => 'Web (Tauri)',
];
/**
* Map deprecated platform types to their new consolidated types.
*
* The 1.9.x refactor consolidated ~15 platform types into 5 new ones.
* Existing platforms in the database may still have old type values.
*
* @param string $type
* @return string The mapped type, or the original if not deprecated.
*/
public static function mapDeprecatedType(string $type): string
{
$mapping = [
'flutter-web' => self::TYPE_WEB,
'unity' => self::TYPE_WEB,
'flutter-ios' => self::TYPE_APPLE,
'flutter-macos' => self::TYPE_APPLE,
'apple-ios' => self::TYPE_APPLE,
'apple-macos' => self::TYPE_APPLE,
'apple-watchos' => self::TYPE_APPLE,
'apple-tvos' => self::TYPE_APPLE,
'react-native-ios' => self::TYPE_APPLE,
'flutter-android' => self::TYPE_ANDROID,
'react-native-android' => self::TYPE_ANDROID,
'flutter-windows' => self::TYPE_WINDOWS,
'flutter-linux' => self::TYPE_LINUX,
];
return $mapping[$type] ?? $type;
}
/**
* Get user-friendly platform name from a scheme.
*
@@ -75,7 +75,8 @@ class Get extends Action
throw new Exception(Exception::PLATFORM_NOT_FOUND);
}
$type = $platform->getAttribute('type');
$type = Platform::mapDeprecatedType($platform->getAttribute('type'));
$platform->setAttribute('type', $type);
$model = match($type) {
Platform::TYPE_WEB => Response::MODEL_PLATFORM_WEB,
@@ -3,6 +3,7 @@
namespace Appwrite\Platform\Modules\Project\Http\Project\Platforms;
use Appwrite\Extend\Exception;
use Appwrite\Network\Platform;
use Appwrite\SDK\AuthType;
use Appwrite\SDK\Method;
use Appwrite\SDK\Response as SDKResponse;
@@ -117,6 +118,10 @@ class XList extends Action
throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null.");
}
foreach ($platforms as $platform) {
$platform->setAttribute('type', Platform::mapDeprecatedType($platform->getAttribute('type')));
}
$response->dynamic(new Document([
'platforms' => $platforms,
'total' => $total,