Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Migration/Transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,15 @@ public function getStatusCounters(): array
foreach ($this->cache->getAll() as $resourceType => $resources) {
foreach ($resources as $k => $resource) {
if (($resourceType === Resource::TYPE_ROW || $resourceType === Resource::TYPE_DOCUMENT) && is_string($resource)) {
// Only report status for resource types that were requested,
// mirroring the isset() guard below. Row/document counts can be
// aggregated into the cache for an unrequested type, which would
// otherwise read an unseeded 'pending' key and leave a phantom,
// non-empty counter.
if (!isset($status[$resourceType])) {
continue;
}

$resource = intval($resource);

$status[$resourceType][$k] = $resource;
Expand Down
27 changes: 27 additions & 0 deletions tests/Migration/Unit/General/TransferTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use PHPUnit\Framework\TestCase;
use Utopia\Migration\Resource;
use Utopia\Migration\Resources\Database\Database;
use Utopia\Migration\Resources\Database\Row;
use Utopia\Migration\Resources\Database\Table;
use Utopia\Migration\Transfer;
use Utopia\Tests\Unit\Adapters\MockDestination;
use Utopia\Tests\Unit\Adapters\MockSource;
Expand Down Expand Up @@ -64,4 +66,29 @@ function () {
$this->assertSame('test', $database->getDatabaseName());
$this->assertSame('test', $database->getId());
}

/**
* Row and document counts are aggregated into the cache by status. When such
* a count exists for a resource type that was not part of the migration
* request, getStatusCounters() must ignore it, exactly as it already does for
* non-row resources via the isset() guard. Otherwise it reads an unseeded
* 'pending' key (triggering an "Undefined array key" warning) and reports a
* phantom, non-empty counter for a type the caller never asked to migrate.
*/
public function testStatusCountersIgnoreUnrequestedRowCounts(): void
{
// No resource types were requested, so 'row'/'document' are unrequested.
// A row count still leaks into the cache: the destination tallies row and
// document counts by status as it imports them.
$table = new Table(new Database('db', 'db'), 'table', 'table');
$row = new Row('row-1', $table);
$row->setStatus(Resource::STATUS_SUCCESS);

$this->transfer->getCache()->add($row);

$counters = $this->transfer->getStatusCounters();

$this->assertArrayNotHasKey(Resource::TYPE_ROW, $counters);
$this->assertSame([], $counters);
}
}
Loading