Skip to content

Commit

Permalink
Fix DBAL deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsunet committed Jul 10, 2024
1 parent 8cb5fb3 commit 9d5da8f
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ private function createNodeTable(): Table
DbalSchemaFactory::columnForNodeAggregateId('nodeaggregateid')->setNotnull(false),
DbalSchemaFactory::columnForDimensionSpacePointHash('origindimensionspacepointhash')->setNotnull(false),
DbalSchemaFactory::columnForNodeTypeName('nodetypename'),
(new Column('name', self::type(Types::STRING)))->setLength(255)->setNotnull(false)->setCustomSchemaOption('charset', 'ascii')->setCustomSchemaOption('collation', 'ascii_general_ci'),
(new Column('properties', self::type(Types::TEXT)))->setNotnull(true)->setCustomSchemaOption('collation', self::DEFAULT_TEXT_COLLATION),
(new Column('name', self::type(Types::STRING)))->setLength(255)->setNotnull(false)->setPlatformOption('charset', 'ascii')->setPlatformOption('collation', 'ascii_general_ci'),
(new Column('properties', self::type(Types::TEXT)))->setNotnull(true)->setPlatformOption('collation', self::DEFAULT_TEXT_COLLATION),
(new Column('classification', self::type(Types::BINARY)))->setLength(20)->setNotnull(true),
(new Column('created', self::type(Types::DATETIME_IMMUTABLE)))->setDefault('CURRENT_TIMESTAMP')->setNotnull(true),
(new Column('originalcreated', self::type(Types::DATETIME_IMMUTABLE)))->setDefault('CURRENT_TIMESTAMP')->setNotnull(true),
Expand Down Expand Up @@ -93,10 +93,10 @@ private function createDimensionSpacePointsTable(): Table
private function createReferenceRelationTable(): Table
{
$table = self::createTable($this->contentGraphTableNames->referenceRelation(), [
(new Column('name', self::type(Types::STRING)))->setLength(255)->setNotnull(true)->setCustomSchemaOption('charset', 'ascii')->setCustomSchemaOption('collation', 'ascii_general_ci'),
(new Column('name', self::type(Types::STRING)))->setLength(255)->setNotnull(true)->setPlatformOption('charset', 'ascii')->setPlatformOption('collation', 'ascii_general_ci'),
(new Column('position', self::type(Types::INTEGER)))->setNotnull(true),
DbalSchemaFactory::columnForNodeAnchorPoint('nodeanchorpoint'),
(new Column('properties', self::type(Types::TEXT)))->setNotnull(false)->setCustomSchemaOption('collation', self::DEFAULT_TEXT_COLLATION),
(new Column('properties', self::type(Types::TEXT)))->setNotnull(false)->setPlatformOption('collation', self::DEFAULT_TEXT_COLLATION),
DbalSchemaFactory::columnForNodeAggregateId('destinationnodeaggregateid')->setNotnull(true)
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection\Feature;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Exception as DBALException;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection\NodeRelationAnchorPoint;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\NodeFactory;
Expand Down Expand Up @@ -58,7 +58,7 @@ private function addSubtreeTag(ContentStreamId $contentStreamId, NodeAggregateId
'dimensionSpacePointHashes' => $affectedDimensionSpacePoints->getPointHashes(),
'tagPath' => '$.' . $tag->value,
], [
'dimensionSpacePointHashes' => Connection::PARAM_STR_ARRAY,
'dimensionSpacePointHashes' => ArrayParameterType::STRING,
]);
} catch (DBALException $e) {
throw new \RuntimeException(sprintf('Failed to add subtree tag %s for content stream %s, node aggregate id %s and dimension space points %s: %s', $tag->value, $contentStreamId->value, $nodeAggregateId->value, $affectedDimensionSpacePoints->toJson(), $e->getMessage()), 1716479749, $e);
Expand All @@ -80,7 +80,7 @@ private function addSubtreeTag(ContentStreamId $contentStreamId, NodeAggregateId
'dimensionSpacePointHashes' => $affectedDimensionSpacePoints->getPointHashes(),
'tagPath' => '$.' . $tag->value,
], [
'dimensionSpacePointHashes' => Connection::PARAM_STR_ARRAY,
'dimensionSpacePointHashes' => ArrayParameterType::STRING,
]);
} catch (DBALException $e) {
throw new \RuntimeException(sprintf('Failed to add subtree tag %s for content stream %s, node aggregate id %s and dimension space points %s: %s', $tag->value, $contentStreamId->value, $nodeAggregateId->value, $affectedDimensionSpacePoints->toJson(), $e->getMessage()), 1716479840, $e);
Expand Down Expand Up @@ -135,7 +135,7 @@ private function removeSubtreeTag(ContentStreamId $contentStreamId, NodeAggregat
'dimensionSpacePointHashes' => $affectedDimensionSpacePoints->getPointHashes(),
'tagPath' => '$.' . $tag->value,
], [
'dimensionSpacePointHashes' => Connection::PARAM_STR_ARRAY,
'dimensionSpacePointHashes' => ArrayParameterType::STRING,
]);
} catch (DBALException $e) {
throw new \RuntimeException(sprintf('Failed to remove subtree tag %s for content stream %s, node aggregate id %s and dimension space points %s: %s', $tag->value, $contentStreamId->value, $nodeAggregateId->value, $affectedDimensionSpacePoints->toJson(), $e->getMessage()), 1716482293, $e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository;

use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\Exception as DriverException;
use Doctrine\DBAL\Exception as DBALException;
Expand Down Expand Up @@ -292,7 +293,7 @@ public function getDimensionSpacePointsOccupiedByChildNodeName(NodeName $nodeNam
'dimensionSpacePointHashes' => $dimensionSpacePointsToCheck->getPointHashes(),
'nodeName' => $nodeName->value
], [
'dimensionSpacePointHashes' => Connection::PARAM_STR_ARRAY,
'dimensionSpacePointHashes' => ArrayParameterType::STRING,
]);
$dimensionSpacePoints = [];
foreach ($this->fetchRows($queryBuilder) as $hierarchyRelationData) {
Expand All @@ -308,12 +309,9 @@ public function countNodes(): int
->select('COUNT(*)')
->from($this->nodeQueryBuilder->tableNames->node());
try {
$result = $queryBuilder->execute();
if (!$result instanceof Result) {
throw new \RuntimeException(sprintf('Failed to count nodes. Expected result to be of type %s, got: %s', Result::class, get_debug_type($result)), 1701444550);
}
$result = $queryBuilder->executeQuery();
return (int)$result->fetchOne();
} catch (DriverException | DBALException $e) {
} catch (DBALException $e) {
throw new \RuntimeException(sprintf('Failed to count rows in database: %s', $e->getMessage()), 1701444590, $e);
}
}
Expand Down Expand Up @@ -361,12 +359,8 @@ private function mapQueryBuilderToNodeAggregates(QueryBuilder $queryBuilder): No
private function fetchRows(QueryBuilder $queryBuilder): array
{
try {
$result = $queryBuilder->execute();
if (!$result instanceof Result) {
throw new \RuntimeException(sprintf('Failed to execute query. Expected result to be of type %s, got: %s', Result::class, get_debug_type($result)), 1701443535);
}
return $result->fetchAllAssociative();
} catch (DriverException | DBALException $e) {
return $queryBuilder->executeQuery()->fetchAllAssociative();
} catch (DBALException $e) {
throw new \RuntimeException(sprintf('Failed to fetch rows from database: %s', $e->getMessage()), 1701444358, $e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ private function fetchNodes(QueryBuilder $queryBuilder): Nodes
private function fetchCount(QueryBuilder $queryBuilder): int
{
try {
return (int)$this->executeQuery($queryBuilder->select('COUNT(*)')->resetQueryPart('orderBy')->setFirstResult(0)->setMaxResults(1))->fetchOne();
return (int)$this->executeQuery($queryBuilder->select('COUNT(*)')->resetOrderBy()->setFirstResult(0)->setMaxResults(1))->fetchOne();
} catch (DBALException $e) {
throw new \RuntimeException(sprintf('Failed to fetch count: %s', $e->getMessage()), 1679048349, $e);
}
Expand Down Expand Up @@ -750,7 +750,7 @@ private function fetchCteCountResult(QueryBuilder $queryBuilderInitial, QueryBui
UNION
{$queryBuilderRecursive->getSQL()}
)
{$queryBuilderCte->select('COUNT(*)')->resetQueryPart('orderBy')->setFirstResult(0)->setMaxResults(1)}
{$queryBuilderCte->select('COUNT(*)')->resetOrderBy()->setFirstResult(0)->setMaxResults(1)}
SQL;
$parameters = array_merge($queryBuilderInitial->getParameters(), $queryBuilderRecursive->getParameters(), $queryBuilderCte->getParameters());
$parameterTypes = array_merge($queryBuilderInitial->getParameterTypes(), $queryBuilderRecursive->getParameterTypes(), $queryBuilderCte->getParameterTypes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository;

use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception as DBALException;
use Neos\ContentGraph\DoctrineDbalAdapter\ContentGraphTableNames;
Expand Down Expand Up @@ -411,7 +412,7 @@ public function findIngoingHierarchyRelationsForNode(
if ($restrictToSet) {
$ingoingHierarchyRelationsStatement .= ' AND h.dimensionspacepointhash IN (:dimensionSpacePointHashes)';
$parameters['dimensionSpacePointHashes'] = $restrictToSet->getPointHashes();
$types['dimensionSpacePointHashes'] = Connection::PARAM_STR_ARRAY;
$types['dimensionSpacePointHashes'] = ArrayParameterType::STRING;
}
try {
$rows = $this->dbal->fetchAllAssociative($ingoingHierarchyRelationsStatement, $parameters, $types);
Expand Down Expand Up @@ -451,7 +452,7 @@ public function findOutgoingHierarchyRelationsForNode(
if ($restrictToSet) {
$outgoingHierarchyRelationsStatement .= ' AND h.dimensionspacepointhash IN (:dimensionSpacePointHashes)';
$parameters['dimensionSpacePointHashes'] = $restrictToSet->getPointHashes();
$types['dimensionSpacePointHashes'] = Connection::PARAM_STR_ARRAY;
$types['dimensionSpacePointHashes'] = ArrayParameterType::STRING;
}
try {
$rows = $this->dbal->fetchAllAssociative($outgoingHierarchyRelationsStatement, $parameters, $types);
Expand Down Expand Up @@ -490,7 +491,7 @@ public function findOutgoingHierarchyRelationsForNodeAggregate(
'contentStreamId' => $contentStreamId->value,
'dimensionSpacePointHashes' => $dimensionSpacePointSet->getPointHashes()
], [
'dimensionSpacePointHashes' => Connection::PARAM_STR_ARRAY
'dimensionSpacePointHashes' => ArrayParameterType::STRING
]);
} catch (DBALException $e) {
throw new \RuntimeException(sprintf('Failed to load outgoing hierarchy relations for content stream %s, node aggregate id %s and dimension space points %s from database: %s', $contentStreamId->value, $nodeAggregateId->value, $dimensionSpacePointSet->toJson(), $e->getMessage()), 1716476690, $e);
Expand Down Expand Up @@ -524,7 +525,7 @@ public function findIngoingHierarchyRelationsForNodeAggregate(
if ($dimensionSpacePointSet !== null) {
$ingoingHierarchyRelationsStatement .= ' AND h.dimensionspacepointhash IN (:dimensionSpacePointHashes)';
$parameters['dimensionSpacePointHashes'] = $dimensionSpacePointSet->getPointHashes();
$types['dimensionSpacePointHashes'] = Connection::PARAM_STR_ARRAY;
$types['dimensionSpacePointHashes'] = ArrayParameterType::STRING;
}
try {
$rows = $this->dbal->fetchAllAssociative($ingoingHierarchyRelationsStatement, $parameters, $types);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Neos\ContentGraph\DoctrineDbalAdapter;

use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Query\QueryBuilder;
Expand Down Expand Up @@ -155,12 +156,12 @@ public function addNodeTypeCriteria(QueryBuilder $queryBuilder, ExpandedNodeType
$allowanceQueryPart = '';
if (!$constraintsWithSubNodeTypes->explicitlyAllowedNodeTypeNames->isEmpty()) {
$allowanceQueryPart = $queryBuilder->expr()->in($nodeTablePrefix . 'nodetypename', ':explicitlyAllowedNodeTypeNames');
$queryBuilder->setParameter('explicitlyAllowedNodeTypeNames', $constraintsWithSubNodeTypes->explicitlyAllowedNodeTypeNames->toStringArray(), Connection::PARAM_STR_ARRAY);
$queryBuilder->setParameter('explicitlyAllowedNodeTypeNames', $constraintsWithSubNodeTypes->explicitlyAllowedNodeTypeNames->toStringArray(), ArrayParameterType::STRING);
}
$denyQueryPart = '';
if (!$constraintsWithSubNodeTypes->explicitlyDisallowedNodeTypeNames->isEmpty()) {
$denyQueryPart = $queryBuilder->expr()->notIn($nodeTablePrefix . 'nodetypename', ':explicitlyDisallowedNodeTypeNames');
$queryBuilder->setParameter('explicitlyDisallowedNodeTypeNames', $constraintsWithSubNodeTypes->explicitlyDisallowedNodeTypeNames->toStringArray(), Connection::PARAM_STR_ARRAY);
$queryBuilder->setParameter('explicitlyDisallowedNodeTypeNames', $constraintsWithSubNodeTypes->explicitlyDisallowedNodeTypeNames->toStringArray(), ArrayParameterType::STRING);
}
if ($allowanceQueryPart && $denyQueryPart) {
if ($constraintsWithSubNodeTypes->isWildCardAllowed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public static function columnForNodeAggregateId(string $columnName): Column
{
return (new Column($columnName, Type::getType(Types::STRING)))
->setLength(64)
->setCustomSchemaOption('charset', 'ascii')
->setCustomSchemaOption('collation', 'ascii_general_ci');
->setPlatformOption('charset', 'ascii')
->setPlatformOption('collation', 'ascii_general_ci');
}

/**
Expand Down Expand Up @@ -86,7 +86,7 @@ public static function columnForDimensionSpacePoint(string $columnName): Column
{
return (new Column($columnName, Type::getType(Types::TEXT)))
->setDefault('{}')
->setCustomSchemaOption('collation', 'utf8mb4_unicode_520_ci');
->setPlatformOption('collation', 'utf8mb4_unicode_520_ci');
}

/**
Expand Down Expand Up @@ -114,8 +114,8 @@ public static function columnForNodeTypeName(string $columnName): Column
return (new Column($columnName, Type::getType(Types::STRING)))
->setLength(255)
->setNotnull(true)
->setCustomSchemaOption('charset', 'ascii')
->setCustomSchemaOption('collation', 'ascii_general_ci');
->setPlatformOption('charset', 'ascii')
->setPlatformOption('collation', 'ascii_general_ci');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ private function determineRequiredSqlStatements(): array
{
$schemaManager = $this->dbal->createSchemaManager();
$workspaceTable = new Table($this->tableName, [
(new Column('workspacename', Type::getType(Types::STRING)))->setLength(255)->setNotnull(true)->setCustomSchemaOption('collation', self::DEFAULT_TEXT_COLLATION),
(new Column('baseworkspacename', Type::getType(Types::STRING)))->setLength(255)->setNotnull(false)->setCustomSchemaOption('collation', self::DEFAULT_TEXT_COLLATION),
(new Column('workspacetitle', Type::getType(Types::STRING)))->setLength(255)->setNotnull(true)->setCustomSchemaOption('collation', self::DEFAULT_TEXT_COLLATION),
(new Column('workspacedescription', Type::getType(Types::STRING)))->setLength(255)->setNotnull(true)->setCustomSchemaOption('collation', self::DEFAULT_TEXT_COLLATION),
(new Column('workspaceowner', Type::getType(Types::STRING)))->setLength(255)->setNotnull(false)->setCustomSchemaOption('collation', self::DEFAULT_TEXT_COLLATION),
(new Column('workspacename', Type::getType(Types::STRING)))->setLength(255)->setNotnull(true)->setPlatformOption('collation', self::DEFAULT_TEXT_COLLATION),
(new Column('baseworkspacename', Type::getType(Types::STRING)))->setLength(255)->setNotnull(false)->setPlatformOption('collation', self::DEFAULT_TEXT_COLLATION),
(new Column('workspacetitle', Type::getType(Types::STRING)))->setLength(255)->setNotnull(true)->setPlatformOption('collation', self::DEFAULT_TEXT_COLLATION),
(new Column('workspacedescription', Type::getType(Types::STRING)))->setLength(255)->setNotnull(true)->setPlatformOption('collation', self::DEFAULT_TEXT_COLLATION),
(new Column('workspaceowner', Type::getType(Types::STRING)))->setLength(255)->setNotnull(false)->setPlatformOption('collation', self::DEFAULT_TEXT_COLLATION),
DbalSchemaFactory::columnForContentStreamId('currentcontentstreamid')->setNotNull(true),
(new Column('status', Type::getType(Types::BINARY)))->setLength(20)->setNotnull(false)
]);
Expand Down
16 changes: 7 additions & 9 deletions Neos.Media/Classes/Command/MediaCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public function removeUnusedCommand(string $assetSource = '', bool $quiet = fals
!$quiet && $this->output->progressStart($assetCount);

/** @var Asset $asset */
foreach ($this->assetRepository->iterate($iterator) as $asset) {
foreach ($iterator as $asset) {
!$quiet && $this->output->progressAdvance(1);

if ($limit !== null && $unusedAssetCount === $limit) {
Expand Down Expand Up @@ -326,7 +326,7 @@ public function createThumbnailsCommand(string $preset = null, bool $async = nul
$iterator = $this->assetRepository->findAllIterator();
$imageCount = $this->assetRepository->countAll();
!$quiet && $this->output->progressStart($imageCount * count($presetThumbnailConfigurations));
foreach ($this->assetRepository->iterate($iterator) as $image) {
foreach ($iterator as $image) {
foreach ($presetThumbnailConfigurations as $presetThumbnailConfiguration) {
$this->thumbnailService->getThumbnail($image, $presetThumbnailConfiguration);
$this->persistenceManager->persistAll();
Expand Down Expand Up @@ -362,11 +362,10 @@ public function clearThumbnailsCommand(string $preset = null, bool $quiet = fals
}

!$quiet && $this->output->progressStart($thumbnailCount);
foreach ($this->thumbnailRepository->iterate($iterator, function ($iteration) {
$this->persistAll($iteration);
}) as $thumbnail) {
foreach ($iterator as $iteration => $thumbnail) {
$this->thumbnailRepository->remove($thumbnail);
!$quiet && $this->output->progressAdvance(1);
$this->persistAll($iteration);
!$quiet && $this->output->progressAdvance(1);
}
!$quiet && $this->output->progressFinish();
!$quiet && $this->output->outputLine();
Expand All @@ -387,14 +386,13 @@ public function renderThumbnailsCommand(int $limit = null, bool $quiet = false)
$thumbnailCount = $this->thumbnailRepository->countUngenerated();
$iterator = $this->thumbnailRepository->findUngeneratedIterator();
!$quiet && $this->output->progressStart($limit !== null && $thumbnailCount > $limit ? $limit : $thumbnailCount);
$iteration = 0;
foreach ($this->thumbnailRepository->iterate($iterator) as $thumbnail) {
foreach ($iterator as $iteration => $thumbnail) {
if ($thumbnail->getResource() === null) {
$this->thumbnailService->refreshThumbnail($thumbnail);
$this->persistenceManager->persistAll();
}
!$quiet && $this->output->progressAdvance(1);
if (++$iteration === $limit) {
if ($iteration === $limit) {
break;
}
}
Expand Down
Loading

0 comments on commit 9d5da8f

Please sign in to comment.