mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
fix(migrations): normalize empty resource selectors
This commit is contained in:
1 parent
be8dea9d8b
commit
68299a5a61
2 files changed
+43
-3
No files matched your search
@@ -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,
|
||||
);
|
||||
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in new issue
Block a user