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
16 changes: 16 additions & 0 deletions src/Manifest/ManifestManager/Options/OutTable/ManifestOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class ManifestOptions

private ?array $tableMetadata = null;

private ?array $legacyPrimaryKeys = null;

private static function getLegacySerializer(): Serializer
{
$normalizer = new ObjectNormalizer(
Expand Down Expand Up @@ -78,6 +80,9 @@ private static function getNewNativeTypesSerializer(): Serializer
public function toArray(bool $legacy = true): array
{
$serializer = $legacy ? self::getLegacySerializer() : self::getNewNativeTypesSerializer();
if ($this->getLegacyPrimaryKeys() !== null) {
$serializer = self::getLegacySerializer();
}

return (array) $serializer->normalize($this, null, [AbstractObjectNormalizer::SKIP_NULL_VALUES => true]);
}
Expand Down Expand Up @@ -381,4 +386,15 @@ public function setDeleteWhereOperator(?string $deleteWhereOperator): ManifestOp
$this->deleteWhereOperator = $deleteWhereOperator;
return $this;
}

public function setLegacyPrimaryKeys(array $primaryKey): ManifestOptions
{
$this->legacyPrimaryKeys = $primaryKey;
return $this;
}

public function getLegacyPrimaryKeys(): ?array
{
return $this->legacyPrimaryKeys;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ public function normalize($object, ?string $format = null, array $context = []):
/** @var ManifestOptions $object */
$this->normalizeBasicProperties($object, $data);
$this->normalizeTableMetadata($object, $data);
$this->normalizeSchema($object, $data);
if ($object->getLegacyPrimaryKeys() !== null) {
$data['primary_key'] = $object->getLegacyPrimaryKeys();
} else {
$this->normalizeSchema($object, $data);
}

return $data;
}
Expand Down Expand Up @@ -119,7 +123,7 @@ public function denormalize($data, string $type, ?string $format = null, array $
$metadataBackend = $this->setTableMetadata($manifestOptions, $data);

if (isset($data['primary_key']) && !isset($data['columns'])) {
throw new OptionsValidationException('Columns must be specified when primary key is specified.');
$manifestOptions->setLegacyPrimaryKeys($data['primary_key']);
}

if (isset($data['columns'])) {
Expand Down
17 changes: 14 additions & 3 deletions tests/Manifest/ManifestManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,21 @@ public function testManifestWithOnlyPrimaryKeysSpecified(): void
{
$manager = new ManifestManager(__DIR__ . '/fixtures/manifest-data-dir');

$this->expectException(OptionsValidationException::class);
$this->expectExceptionMessage('Columns must be specified when primary key is specified.');
$expectedManifest = [
'destination' => 'destination-table',
'primary_key' => [
'id',
'number',
],
];

$this->assertSame($expectedManifest, $manager->getTableManifest('onlyPrimaryKeys.csv')->toArray());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty vogo... než jsem našel kde je tenhle file :D


$manager->getTableManifest('onlyPrimaryKeys.csv');
// Test that toArray(legacy: false) force fallbacks to the same result
$this->assertSame(
$expectedManifest,
$manager->getTableManifest('onlyPrimaryKeys.csv')->toArray(false),
);
}

public function testNonexistentManifestReturnsEmptyArray(): void
Expand Down