Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/9.0' into task/use-int-relationa…
Browse files Browse the repository at this point in the history
…nchors
  • Loading branch information
mhsdesign committed Jan 31, 2024
2 parents 6d4ae51 + 6a028f6 commit 0a38f93
Show file tree
Hide file tree
Showing 121 changed files with 2,960 additions and 59,119 deletions.
1 change: 1 addition & 0 deletions .composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"license": ["GPL-3.0-or-later"],
"type": "neos-package-collection",
"require": {
"neos/flow-development-collection": "9.0.x-dev"
},
"replace": {
},
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: ['8.2']
php-versions: ['8.2', '8.3']
dependencies: ['highest']
composer-arguments: [''] # to run --ignore-platform-reqs in experimental builds

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

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Types\Types;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection\Feature\NodeDisabling;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection\Feature\NodeMove;
Expand Down Expand Up @@ -44,21 +43,22 @@
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodeSpecializationVariantWasCreated;
use Neos\ContentRepository\Core\Feature\RootNodeCreation\Event\RootNodeAggregateDimensionsWereUpdated;
use Neos\ContentRepository\Core\Feature\RootNodeCreation\Event\RootNodeAggregateWithNodeWasCreated;
use Neos\ContentRepository\Core\Infrastructure\DbalCheckpointStorage;
use Neos\ContentRepository\Core\Infrastructure\DbalClientInterface;
use Neos\ContentRepository\Core\Infrastructure\DbalSchemaDiff;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\Projection\CheckpointStorageStatusType;
use Neos\ContentRepository\Core\Projection\ContentGraph\Timestamps;
use Neos\ContentRepository\Core\Projection\ProjectionInterface;
use Neos\ContentRepository\Core\Projection\ProjectionStatus;
use Neos\ContentRepository\Core\Projection\WithMarkStaleInterface;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateClassification;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\EventStore\CatchUp\CheckpointStorageInterface;
use Neos\EventStore\DoctrineAdapter\DoctrineCheckpointStorage;
use Neos\EventStore\Model\Event\SequenceNumber;
use Neos\EventStore\Model\EventEnvelope;
use Neos\EventStore\Model\EventStore\SetupResult;

/**
* @implements ProjectionInterface<ContentGraph>
Expand All @@ -81,7 +81,7 @@ final class DoctrineDbalContentGraphProjection implements ProjectionInterface, W
*/
private ?ContentGraph $contentGraph = null;

private DoctrineCheckpointStorage $checkpointStorage;
private DbalCheckpointStorage $checkpointStorage;

public function __construct(
private readonly DbalClientInterface $dbalClient,
Expand All @@ -91,7 +91,7 @@ public function __construct(
private readonly ProjectionContentGraph $projectionContentGraph,
private readonly string $tableNamePrefix,
) {
$this->checkpointStorage = new DoctrineCheckpointStorage(
$this->checkpointStorage = new DbalCheckpointStorage(
$this->dbalClient->getConnection(),
$this->tableNamePrefix . '_checkpoint',
self::class
Expand All @@ -110,25 +110,49 @@ protected function getTableNamePrefix(): string

public function setUp(): void
{
$this->setupTables();
$this->checkpointStorage->setup();
foreach ($this->determineRequiredSqlStatements() as $statement) {
$this->getDatabaseConnection()->executeStatement($statement);
}
$this->checkpointStorage->setUp();
}

private function setupTables(): SetupResult
/**
* @return array<string>
*/
private function determineRequiredSqlStatements(): array
{
$connection = $this->dbalClient->getConnection();
$schemaManager = $connection->getSchemaManager();
if (!$schemaManager instanceof AbstractSchemaManager) {
throw new \RuntimeException('Failed to retrieve Schema Manager', 1625653914);
}

$schema = (new DoctrineDbalContentGraphSchemaBuilder($this->tableNamePrefix))->buildSchema($schemaManager);
return DbalSchemaDiff::determineRequiredSqlStatements($connection, $schema);
}

$schemaDiff = (new Comparator())->compare($schemaManager->createSchema(), $schema);
foreach ($schemaDiff->toSaveSql($connection->getDatabasePlatform()) as $statement) {
$connection->executeStatement($statement);
public function status(): ProjectionStatus
{
$checkpointStorageStatus = $this->checkpointStorage->status();
if ($checkpointStorageStatus->type === CheckpointStorageStatusType::ERROR) {
return ProjectionStatus::error($checkpointStorageStatus->details);
}
if ($checkpointStorageStatus->type === CheckpointStorageStatusType::SETUP_REQUIRED) {
return ProjectionStatus::setupRequired($checkpointStorageStatus->details);
}
try {
$this->getDatabaseConnection()->connect();
} catch (\Throwable $e) {
return ProjectionStatus::error(sprintf('Failed to connect to database: %s', $e->getMessage()));
}
try {
$requiredSqlStatements = $this->determineRequiredSqlStatements();
} catch (\Throwable $e) {
return ProjectionStatus::error(sprintf('Failed to determine required SQL statements: %s', $e->getMessage()));
}
if ($requiredSqlStatements !== []) {
return ProjectionStatus::setupRequired(sprintf('The following SQL statement%s required: %s', count($requiredSqlStatements) !== 1 ? 's are' : ' is', implode(chr(10), $requiredSqlStatements)));
}
return SetupResult::success('');
return ProjectionStatus::ok();
}

public function reset(): void
Expand Down Expand Up @@ -202,7 +226,7 @@ public function apply(EventInterface $event, EventEnvelope $eventEnvelope): void
};
}

public function getCheckpointStorage(): CheckpointStorageInterface
public function getCheckpointStorage(): DbalCheckpointStorage
{
return $this->checkpointStorage;
}
Expand Down Expand Up @@ -1233,7 +1257,8 @@ private function getDatabaseConnection(): Connection

private static function initiatingDateTime(EventEnvelope $eventEnvelope): \DateTimeImmutable
{
$result = $eventEnvelope->event->metadata->has('initiatingTimestamp') ? \DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, $eventEnvelope->event->metadata->get('initiatingTimestamp')) : $eventEnvelope->recordedAt;
$initiatingTimestamp = $eventEnvelope->event->metadata?->get('initiatingTimestamp');
$result = $initiatingTimestamp !== null ? \DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, $initiatingTimestamp) : $eventEnvelope->recordedAt;
if (!$result instanceof \DateTimeImmutable) {
throw new \RuntimeException(sprintf('Failed to extract initiating timestamp from event "%s"', $eventEnvelope->event->id->value), 1678902291);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private function createNodeTable(): Table
DbalSchemaFactory::columnForDimensionSpacePointHash('origindimensionspacepointhash')->setNotnull(false),
DbalSchemaFactory::columnForNodeTypeName('nodetypename'),
(new Column('properties', Type::getType(Types::TEXT)))->setNotnull(true)->setCustomSchemaOption('collation', self::DEFAULT_TEXT_COLLATION),
(new Column('classification', Type::getType(Types::STRING)))->setLength(20)->setNotnull(true)->setCustomSchemaOption('charset', 'binary'),
(new Column('classification', Type::getType(Types::BINARY)))->setLength(20)->setNotnull(true),
(new Column('created', Type::getType(Types::DATETIME_IMMUTABLE)))->setDefault('CURRENT_TIMESTAMP')->setNotnull(true),
(new Column('originalcreated', Type::getType(Types::DATETIME_IMMUTABLE)))->setDefault('CURRENT_TIMESTAMP')->setNotnull(true),
(new Column('lastmodified', Type::getType(Types::DATETIME_IMMUTABLE)))->setNotnull(false)->setDefault(null),
Expand Down
Loading

0 comments on commit 0a38f93

Please sign in to comment.