Skip to content

Commit

Permalink
Added PostgresqlGateway
Browse files Browse the repository at this point in the history
  • Loading branch information
reithor committed Nov 18, 2024
1 parent 8f93363 commit a188172
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 10 deletions.
11 changes: 1 addition & 10 deletions src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1357,16 +1357,7 @@ public function setName(int $contentId, int $version, string $name, string $lang
*/
private function getSetNameLanguageMaskSubQuery(): string
{
return <<<SQL
(SELECT
CASE
WHEN (initial_language_id = :language_id AND (language_mask & :language_id) <> 0 )
THEN (:language_id | 1)
ELSE :language_id
END
FROM ezcontentobject
WHERE id = :content_id)
SQL;
return $this->sharedGateway->getSetNameLanguageMaskSubQuery();
}

public function deleteContent(int $contentId): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@ public function getColumnNextIntegerValue(
return null;
}

/**
* Return a language sub select query for setName.
*
* The query generates the proper language mask at the runtime of the INSERT/UPDATE query
* generated by setName.
*
* @see setName
*/
public function getSetNameLanguageMaskSubQuery(): string
{
return <<<SQL
(SELECT
CASE
WHEN (initial_language_id = :language_id AND (language_mask & :language_id) <> 0 )
THEN (:language_id | 1)
ELSE :language_id
END
FROM ezcontentobject
WHERE id = :content_id)
SQL;
}

public function getLastInsertedId(string $sequenceName): int
{
return (int)$this->connection->lastInsertId($sequenceName);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Core\Persistence\Legacy\SharedGateway\DatabasePlatform;

use Doctrine\DBAL\Connection;
use Ibexa\Core\Persistence\Legacy\SharedGateway\Gateway;

final class PostgresqlGateway implements Gateway
{
/** @var \Doctrine\DBAL\Connection */
private $connection;

public function __construct(Connection $connection)
{
$this->connection = $connection;
}

public function getColumnNextIntegerValue(
string $tableName,
string $columnName,
string $sequenceName
): ?int {
return null;
}

public function getLastInsertedId(string $sequenceName): int
{
return (int)$this->connection->lastInsertId($sequenceName);
}

/**
* Return a language sub select query for setName.
*
* The query generates the proper language mask at the runtime of the INSERT/UPDATE query
* generated by setName.
*
* @see setName
*/
public function getSetNameLanguageMaskSubQuery(): string
{
return <<<SQL
(SELECT
CASE
WHEN (initial_language_id = :language_id AND (language_mask & :language_id) <> 0 )
THEN (cast(:language_id as BIGINT) | 1)
ELSE :language_id
END
FROM ezcontentobject
WHERE id = :content_id)
SQL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ public function getLastInsertedId(string $sequenceName): int

return $this->lastInsertedIds[$sequenceName];
}

/**
* Return a language sub select query for setName.
*
* The query generates the proper language mask at the runtime of the INSERT/UPDATE query
* generated by setName.
*
* @see setName
*/
public function getSetNameLanguageMaskSubQuery(): string
{
return <<<SQL
(SELECT
CASE
WHEN (initial_language_id = :language_id AND (language_mask & :language_id) <> 0 )
THEN (:language_id | 1)
ELSE :language_id
END
FROM ezcontentobject
WHERE id = :content_id)
SQL;
}
}

class_alias(SqliteGateway::class, 'eZ\Publish\Core\Persistence\Legacy\SharedGateway\DatabasePlatform\SqliteGateway');
5 changes: 5 additions & 0 deletions src/lib/Persistence/Legacy/SharedGateway/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public function getColumnNextIntegerValue(
* It returns integer as all the IDs in the Ibexa Legacy Storage are (big)integers
*/
public function getLastInsertedId(string $sequenceName): int;

/**
* Return a language sub select query for setName.
*/
public function getSetNameLanguageMaskSubQuery(): string;
}

class_alias(Gateway::class, 'eZ\Publish\Core\Persistence\Legacy\SharedGateway\Gateway');
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ services:
tags:
- { name: ibexa.storage.legacy.gateway.shared, platform: sqlite }

Ibexa\Core\Persistence\Legacy\SharedGateway\DatabasePlatform\PostgresqlGateway:
tags:
- { name: ibexa.storage.legacy.gateway.shared, platform: postgresql }

Ibexa\Core\Persistence\Legacy\SharedGateway\GatewayFactory:
arguments:
$fallbackGateway: '@Ibexa\Core\Persistence\Legacy\SharedGateway\DatabasePlatform\FallbackGateway'
Expand Down

0 comments on commit a188172

Please sign in to comment.