From a3c5a782bdfe5c4d3e82c58ec92ad28499d239d6 Mon Sep 17 00:00:00 2001 From: Gaylord Aulke Date: Fri, 7 Jun 2019 12:36:42 +0200 Subject: [PATCH 1/8] fix for postgresql --- src/Database/DBALConnection.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Database/DBALConnection.php b/src/Database/DBALConnection.php index 0ba6c9b..e952240 100644 --- a/src/Database/DBALConnection.php +++ b/src/Database/DBALConnection.php @@ -18,14 +18,18 @@ public function __construct(DbConnection $connection) $this->connection = $connection; } - /** @throws \Doctrine\DBAL\DBALException */ + /** + * @param string $table + * @param Row $row + * @throws \Doctrine\DBAL\DBALException + */ public function insert(string $table, Row $row): void { $insert = Insert::into($table, $row); $this->connection->executeUpdate($insert->toSQL($this->connection), $insert->parameters()); - $row->assignId($this->connection->lastInsertId()); + $row->assignId(@$this->connection->lastInsertId()); } /** From 070d108025db6fc71a28dd8387f67a8bdf381a23 Mon Sep 17 00:00:00 2001 From: Gaylord Aulke Date: Fri, 7 Jun 2019 12:43:56 +0200 Subject: [PATCH 2/8] fix for postgresql --- src/Database/DBALConnection.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Database/DBALConnection.php b/src/Database/DBALConnection.php index e952240..f189dcd 100644 --- a/src/Database/DBALConnection.php +++ b/src/Database/DBALConnection.php @@ -29,7 +29,10 @@ public function insert(string $table, Row $row): void $this->connection->executeUpdate($insert->toSQL($this->connection), $insert->parameters()); - $row->assignId(@$this->connection->lastInsertId()); + try { + $id = $this->connection->lastInsertId(); + $row->assignId($id); + } catch (\Exception $e) {}; } /** From b23ee52428671d3d458a1e7773d7cc0e9c312c76 Mon Sep 17 00:00:00 2001 From: Gaylord Aulke Date: Thu, 26 Mar 2020 22:17:31 +0100 Subject: [PATCH 3/8] try sf 5 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index ec8c265..71e4cde 100644 --- a/composer.json +++ b/composer.json @@ -13,8 +13,8 @@ "php": ">=7.1", "doctrine/dbal": "^2.5", "fzaninotto/faker": "^1.6", - "symfony/console": "^4.0", - "symfony/yaml": "^4.0" + "symfony/console": "^4.0 | ^5.0", + "symfony/yaml": "^4.0 | ^5.0" }, "require-dev": { "phpunit/phpunit": "^6.0" From c45b3cb94ef39d0781b2ba21547a11c965340b53 Mon Sep 17 00:00:00 2001 From: Gaylord Aulke Date: Fri, 27 Nov 2020 18:26:26 +0100 Subject: [PATCH 4/8] moved to fakerphp/faker --- bin/doctrine-dbal | 1 + bin/phpunit | 1 + bin/yaml-lint | 1 + composer.json | 4 ++-- 4 files changed, 5 insertions(+), 2 deletions(-) create mode 120000 bin/doctrine-dbal create mode 120000 bin/phpunit create mode 120000 bin/yaml-lint diff --git a/bin/doctrine-dbal b/bin/doctrine-dbal new file mode 120000 index 0000000..110e93c --- /dev/null +++ b/bin/doctrine-dbal @@ -0,0 +1 @@ +../vendor/doctrine/dbal/bin/doctrine-dbal \ No newline at end of file diff --git a/bin/phpunit b/bin/phpunit new file mode 120000 index 0000000..4ba3256 --- /dev/null +++ b/bin/phpunit @@ -0,0 +1 @@ +../vendor/phpunit/phpunit/phpunit \ No newline at end of file diff --git a/bin/yaml-lint b/bin/yaml-lint new file mode 120000 index 0000000..73c0353 --- /dev/null +++ b/bin/yaml-lint @@ -0,0 +1 @@ +../vendor/symfony/yaml/Resources/bin/yaml-lint \ No newline at end of file diff --git a/composer.json b/composer.json index 71e4cde..df55446 100644 --- a/composer.json +++ b/composer.json @@ -12,9 +12,9 @@ "require": { "php": ">=7.1", "doctrine/dbal": "^2.5", - "fzaninotto/faker": "^1.6", "symfony/console": "^4.0 | ^5.0", - "symfony/yaml": "^4.0 | ^5.0" + "symfony/yaml": "^4.0 | ^5.0", + "fakerphp/faker": "^1.12" }, "require-dev": { "phpunit/phpunit": "^6.0" From c08ceb30f11734d2e341ee0324d30f6f5d4e588b Mon Sep 17 00:00:00 2001 From: Gaylord Aulke Date: Tue, 16 Feb 2021 16:38:26 +0100 Subject: [PATCH 5/8] allow arrays for field value in fixtures, converted to JSON before insert --- src/Database/Insert.php | 4 +++- src/Database/Row.php | 2 +- src/Processors/FakerProcessor.php | 1 + src/Processors/ForeignKeyProcessor.php | 3 ++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Database/Insert.php b/src/Database/Insert.php index f136ac0..1538778 100644 --- a/src/Database/Insert.php +++ b/src/Database/Insert.php @@ -36,7 +36,9 @@ public function parameters(): array { $parameters = []; foreach ($this->row->values() as $value) { - if (is_numeric($value) || trim($value, '`') === $value) { + if(is_array($value)) { + $parameters[] = json_encode($value); + } elseif (is_numeric($value) || trim($value, '`') === $value) { $parameters[] = $value; } } diff --git a/src/Database/Row.php b/src/Database/Row.php index 658af3d..1b1795f 100644 --- a/src/Database/Row.php +++ b/src/Database/Row.php @@ -76,7 +76,7 @@ public function placeholders(): array { $placeholders = []; foreach ($this->values as $column => $value) { - if (is_numeric($value) || trim($value, '`') === $value) { + if (is_array($value) || is_numeric($value) || trim($value, '`') === $value) { $placeholders[$column] = '?'; } else { $placeholders[$column] = $value === null ? 'null' : trim($value, '`'); diff --git a/src/Processors/FakerProcessor.php b/src/Processors/FakerProcessor.php index 61dbbb9..1662169 100644 --- a/src/Processors/FakerProcessor.php +++ b/src/Processors/FakerProcessor.php @@ -32,6 +32,7 @@ public function beforeInsert(Row $row): void private function generateFakeDataIfNeeded(Row $row, string $column, ?string $value): void { + if(!is_scalar($value)) return; $formatted = $value; while (FormatterCall::matches($formatted)) { $formatted = FormatterCall::from($formatted)->run($this->generator); diff --git a/src/Processors/ForeignKeyProcessor.php b/src/Processors/ForeignKeyProcessor.php index c0120e6..4a4f54b 100644 --- a/src/Processors/ForeignKeyProcessor.php +++ b/src/Processors/ForeignKeyProcessor.php @@ -59,8 +59,9 @@ public function addReference(Row $row) /** * @return mixed */ - private function parseKeyIfNeeded(string $value) + private function parseKeyIfNeeded($value) { + if (!is_scalar($value)) return $value; if ($this->isAReference($value) && $this->referenceExistsFor($value)) { return $this->references[substr($value, 1)]; } From 15a40b83e0f92a3a9132096eb4082acb5f6a5822 Mon Sep 17 00:00:00 2001 From: Gaylord Aulke Date: Tue, 16 Feb 2021 17:44:52 +0100 Subject: [PATCH 6/8] bugfix --- src/Processors/FakerProcessor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Processors/FakerProcessor.php b/src/Processors/FakerProcessor.php index 1662169..71d58d1 100644 --- a/src/Processors/FakerProcessor.php +++ b/src/Processors/FakerProcessor.php @@ -30,7 +30,7 @@ public function beforeInsert(Row $row): void } } - private function generateFakeDataIfNeeded(Row $row, string $column, ?string $value): void + private function generateFakeDataIfNeeded(Row $row, string $column, $value): void { if(!is_scalar($value)) return; $formatted = $value; From a818bca7b7baea8948985d87063e2b2871274262 Mon Sep 17 00:00:00 2001 From: Gaylord Aulke Date: Wed, 26 Jan 2022 13:48:12 +0100 Subject: [PATCH 7/8] see if this will work with sf 6 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index df55446..0a64e9e 100644 --- a/composer.json +++ b/composer.json @@ -12,8 +12,8 @@ "require": { "php": ">=7.1", "doctrine/dbal": "^2.5", - "symfony/console": "^4.0 | ^5.0", - "symfony/yaml": "^4.0 | ^5.0", + "symfony/console": "^4.0 | ^5.0 | ^6.0", + "symfony/yaml": "^4.0 | ^5.0 | ^6.0", "fakerphp/faker": "^1.12" }, "require-dev": { From d30d042db59483a2e0df4d7f8702a63aece7a29e Mon Sep 17 00:00:00 2001 From: Gaylord Aulke Date: Wed, 26 Jan 2022 13:54:16 +0100 Subject: [PATCH 8/8] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0a64e9e..dd64543 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ ], "require": { "php": ">=7.1", - "doctrine/dbal": "^2.5", + "doctrine/dbal": "^2.5 | ^3.3", "symfony/console": "^4.0 | ^5.0 | ^6.0", "symfony/yaml": "^4.0 | ^5.0 | ^6.0", "fakerphp/faker": "^1.12"