-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4846 from neos/feature/4468-contentrepository-sta…
…tus-2 FEATURE: Content Repository status
- Loading branch information
Showing
23 changed files
with
708 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
Neos.ContentRepository.Core/Classes/Infrastructure/DbalSchemaDiff.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\ContentRepository\Core\Infrastructure; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\Exception; | ||
use Doctrine\DBAL\Schema\AbstractSchemaManager; | ||
use Doctrine\DBAL\Schema\Comparator; | ||
use Doctrine\DBAL\Schema\Schema; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class DbalSchemaDiff | ||
{ | ||
// This class only contains static members and should not be constructed | ||
private function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* Compares the tables of the given $schema with existing tables for the given $connection | ||
* and returns an array of required CREATE and ALTER TABLE statements if they don't match | ||
* | ||
* @return array<string> Array of SQL statements that have to be executed in order to create/adjust the tables | ||
*/ | ||
public static function determineRequiredSqlStatements(Connection $connection, Schema $schema): array | ||
{ | ||
$schemaManager = $connection->getSchemaManager(); | ||
if (!$schemaManager instanceof AbstractSchemaManager) { | ||
throw new \RuntimeException('Failed to retrieve Schema Manager', 1705679142); | ||
} | ||
try { | ||
$platform = $connection->getDatabasePlatform(); | ||
} catch (Exception $e) { | ||
throw new \RuntimeException(sprintf('Failed to retrieve Database platform: %s', $e->getMessage()), 1705679144, $e); | ||
} | ||
if ($platform === null) { // @phpstan-ignore-line This is not possible according to doc types, but there is no corresponding type hint in DBAL 2.x | ||
throw new \RuntimeException('Failed to retrieve Database platform', 1705679147); | ||
} | ||
$fromTableSchemas = []; | ||
foreach ($schema->getTables() as $tableSchema) { | ||
if ($schemaManager->tablesExist([$tableSchema->getName()])) { | ||
$fromTableSchemas[] = $schemaManager->listTableDetails($tableSchema->getName()); | ||
} | ||
} | ||
$fromSchema = new Schema($fromTableSchemas, [], $schemaManager->createSchemaConfig()); | ||
return (new Comparator())->compare($fromSchema, $schema)->toSql($platform); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
Neos.ContentRepository.Core/Classes/Projection/CheckpointStorageStatus.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Neos\ContentRepository\Core\Projection; | ||
|
||
/** | ||
* @api | ||
*/ | ||
final readonly class CheckpointStorageStatus | ||
{ | ||
public function __construct( | ||
public CheckpointStorageStatusType $type, | ||
public string $details, | ||
) { | ||
} | ||
|
||
public static function ok(string $details = ''): self | ||
{ | ||
return new self(CheckpointStorageStatusType::OK, $details); | ||
} | ||
|
||
public static function error(string $details): self | ||
{ | ||
return new self(CheckpointStorageStatusType::ERROR, $details); | ||
} | ||
|
||
public static function setupRequired(string $details = ''): self | ||
{ | ||
return new self(CheckpointStorageStatusType::SETUP_REQUIRED, $details); | ||
} | ||
} |
Oops, something went wrong.