From 68299a5a6153fb0dbb3c75be17e9072317b86fee Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Sat, 18 Jul 2026 09:25:49 +1200 Subject: [PATCH] fix(migrations): normalize empty resource selectors --- src/Appwrite/Platform/Workers/Migrations.php | 6 ++- .../unit/Platform/Workers/MigrationsTest.php | 40 ++++++++++++++++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 0d186fbeb3..3be60e67b7 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -541,6 +541,10 @@ class Migrations extends Action $this->updateMigrationDocument($migration, $project, $queueForRealtime); [$rootResourceId, $rootResourceChildId] = $this->resolveResourceIds($migration); + $rootResourceType = (string) ( + $migration->getAttribute('parentResourceType') + ?: $migration->getAttribute('resourceType') + ); $transfer->runWithResourceSelector( $migration->getAttribute('resources'), function ($resources) use ($migration, $transfer, $project, $queueForRealtime, &$aggregatedResources) { @@ -580,7 +584,7 @@ class Migrations extends Action $this->updateMigrationDocument($migration, $project, $queueForRealtime); }, $rootResourceId, - $migration->getAttribute('parentResourceType') ?: $migration->getAttribute('resourceType'), + $rootResourceType, $rootResourceChildId, ); diff --git a/tests/unit/Platform/Workers/MigrationsTest.php b/tests/unit/Platform/Workers/MigrationsTest.php index c42144add3..af75e2922b 100644 --- a/tests/unit/Platform/Workers/MigrationsTest.php +++ b/tests/unit/Platform/Workers/MigrationsTest.php @@ -108,6 +108,42 @@ final class MigrationsTest extends TestCase $this->assertNotContains('persist:completed:finished', $events); } + public function testNullResourceTypeUsesEmptyResourceSelector(): void + { + $events = []; + $source = $this->createSourceMock(); + $destination = $this->createDestinationMock(); + + $destination + ->expects($this->once()) + ->method('success') + ->willReturnCallback(static function () use (&$events): void { + $events[] = 'destination:success'; + }); + $source + ->expects($this->once()) + ->method('success') + ->willReturnCallback(static function () use (&$events): void { + $events[] = 'source:success'; + }); + $source->expects($this->never())->method('error'); + $destination->expects($this->never())->method('error'); + + $migration = $this->createMigration(null); + $processor = $this->createProcessor($source, $destination, $events); + + $this->process($processor, $migration); + + $this->assertSame('completed', $migration->getAttribute('status')); + $this->assertSame([ + 'persist:processing:processing', + 'persist:processing:migrating', + 'destination:success', + 'source:success', + 'persist:completed:finished', + ], $events); + } + private function createSourceMock(): Source&MockObject { $target = $this->createMock(Source::class); @@ -128,7 +164,7 @@ final class MigrationsTest extends TestCase return $target; } - private function createMigration(): Document + private function createMigration(?string $resourceType = ''): Document { return new Document([ '$id' => 'migration', @@ -137,7 +173,7 @@ final class MigrationsTest extends TestCase 'destination' => 'TestDestination', 'options' => [], 'resourceId' => '', - 'resourceType' => '', + 'resourceType' => $resourceType, 'resources' => [], 'source' => 'TestSource', 'stage' => 'pending',