Skip to content

Commit

Permalink
Support final eZ Platform v3
Browse files Browse the repository at this point in the history
  • Loading branch information
emodric committed Apr 20, 2020
1 parent 6caadea commit 064a30c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
13 changes: 8 additions & 5 deletions bundle/Command/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Netgen\Bundle\EnhancedSelectionBundle\Command;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\PDOStatement;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\FetchMode;
use Netgen\Bundle\EnhancedSelectionBundle\Core\FieldType\EnhancedSelection\Type as EnhancedSelectionType;
use PDO;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -44,14 +44,17 @@ protected function configure(): void
$this->setDescription('Migrates sckenhancedselection field type to version which stores content object data to database table.');
}

protected function execute(InputInterface $input, OutputInterface $output): ?int
protected function initialize(InputInterface $input, OutputInterface $output): void
{
$this->io = new SymfonyStyle($input, $output);
}

protected function execute(InputInterface $input, OutputInterface $output): ?int
{
$statement = $this->getFields();
$this->io->progressStart($statement->rowCount());

while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
while ($row = $statement->fetch(FetchMode::ASSOCIATIVE)) {
if ($row['data_text'] !== null) {
$fieldId = (int) $row['id'];
$version = (int) $row['version'];
Expand All @@ -74,7 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
return 0;
}

private function getFields(): PDOStatement
private function getFields(): Statement
{
$builder = $this->db->createQueryBuilder();
$builder->select('a.id', 'a.version', 'a.data_text')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
namespace Netgen\Bundle\EnhancedSelectionBundle\Core\FieldType\EnhancedSelection\EnhancedSelectionStorage\Gateway;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\Types\Types;
use eZ\Publish\SPI\Persistence\Content\Field;
use eZ\Publish\SPI\Persistence\Content\VersionInfo;
use Netgen\Bundle\EnhancedSelectionBundle\Core\FieldType\EnhancedSelection\EnhancedSelectionStorage\Gateway;
use PDO;

final class DoctrineStorage extends Gateway
{
Expand All @@ -35,9 +36,9 @@ public function storeFieldData(VersionInfo $versionInfo, Field $field): void
'identifier' => ':identifier',
]
)
->setParameter(':contentobject_attribute_id', $field->id, PDO::PARAM_INT)
->setParameter(':contentobject_attribute_version', $versionInfo->versionNo, PDO::PARAM_INT)
->setParameter(':identifier', $identifier, PDO::PARAM_STR);
->setParameter(':contentobject_attribute_id', $field->id, Types::INTEGER)
->setParameter(':contentobject_attribute_version', $versionInfo->versionNo, Types::INTEGER)
->setParameter(':identifier', $identifier, Types::STRING);

$insertQuery->execute();
}
Expand All @@ -60,7 +61,7 @@ public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds): void
)
)
->setParameter(':contentobject_attribute_id', $fieldIds, Connection::PARAM_INT_ARRAY)
->setParameter(':contentobject_attribute_version', $versionInfo->versionNo, PDO::PARAM_INT);
->setParameter(':contentobject_attribute_version', $versionInfo->versionNo, Types::INTEGER);

$query->execute();
}
Expand All @@ -85,12 +86,12 @@ private function loadFieldData($fieldId, $versionNo): array
$query->expr()->eq('contentobject_attribute_version', ':contentobject_attribute_version')
)
)
->setParameter(':contentobject_attribute_id', $fieldId, PDO::PARAM_INT)
->setParameter(':contentobject_attribute_version', $versionNo, PDO::PARAM_INT);
->setParameter(':contentobject_attribute_id', $fieldId, Types::INTEGER)
->setParameter(':contentobject_attribute_version', $versionNo, Types::INTEGER);

$statement = $query->execute();

$rows = $statement->fetchAll(PDO::FETCH_ASSOC);
$rows = $statement->fetchAll(FetchMode::ASSOCIATIVE);

return array_map(
static function (array $row) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function prepend(ContainerBuilder $container): void
{
$configFile = __DIR__ . '/../Resources/config/ezplatform.yaml';
$config = Yaml::parse(file_get_contents($configFile));
$container->prependExtensionConfig('ezpublish', $config);
$container->prependExtensionConfig('ezplatform', $config);
$container->addResource(new FileResource($configFile));
}
}
11 changes: 4 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,21 @@
}
],
"require": {
"ezsystems/ezpublish-kernel": "^8.0",
"ezsystems/ezplatform-kernel": "^1.0",
"ezsystems/ezplatform-content-forms": "^1.0",
"twig/twig": "^2.11.3"
"twig/twig": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^8.3",
"phpunit/phpunit": "^9.0",
"netgen/ez-forms-bundle": "^3.0",
"friendsofphp/php-cs-fixer": "^2.15.3"
"friendsofphp/php-cs-fixer": "^2.16"
},
"minimum-stability": "dev",
"prefer-stable": true,
"suggest": {
"netgen/ez-forms-bundle": "Allows use of enhanced selection field type with Symfony forms",
"ezsystems/ezplatform-solr-search-engine": "Allows use of EnhancedSelection search criterion with Solr search engine"
},
"conflict": {
"ezsystems/ezplatform-solr-search-engine": "<2.0"
},
"autoload": {
"psr-4": {
"Netgen\\Bundle\\EnhancedSelectionBundle\\": "bundle/"
Expand Down
7 changes: 4 additions & 3 deletions tests/Templating/Twig/NetgenEnhancedSelectionRuntimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use eZ\Publish\Core\Repository\Values\Content\VersionInfo;
use eZ\Publish\Core\Repository\Values\ContentType\ContentType;
use eZ\Publish\Core\Repository\Values\ContentType\FieldDefinition;
use eZ\Publish\Core\Repository\Values\ContentType\FieldDefinitionCollection;
use eZ\Publish\SPI\Persistence\Content\ContentInfo;
use Netgen\Bundle\EnhancedSelectionBundle\Core\FieldType\EnhancedSelection\Value;
use Netgen\Bundle\EnhancedSelectionBundle\Templating\Twig\NetgenEnhancedSelectionRuntime;
Expand Down Expand Up @@ -76,7 +77,7 @@ public function testGetSelectionName(): void
]
);

$contentType = new ContentType(['fieldDefinitions' => [$fieldDefinition]]);
$contentType = new ContentType(['fieldDefinitions' => new FieldDefinitionCollection([$fieldDefinition])]);

$this->contentTypeService->expects(self::once())
->method('loadContentType')
Expand Down Expand Up @@ -128,7 +129,7 @@ public function testGetSelectionNameBySpecifiedIdentifier(): void
]
);

$contentType = new ContentType(['fieldDefinitions' => [$fieldDefinition]]);
$contentType = new ContentType(['fieldDefinitions' => new FieldDefinitionCollection([$fieldDefinition])]);

$this->contentTypeService->expects(self::once())
->method('loadContentType')
Expand Down Expand Up @@ -175,7 +176,7 @@ public function testGetSelectionNameForNonExistingOne(): void
]
);

$contentType = new ContentType(['fieldDefinitions' => [$fieldDefinition]]);
$contentType = new ContentType(['fieldDefinitions' => new FieldDefinitionCollection([$fieldDefinition])]);

$this->contentTypeService->expects(self::once())
->method('loadContentType')
Expand Down

0 comments on commit 064a30c

Please sign in to comment.