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 b6834b1
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
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');

0 comments on commit b6834b1

Please sign in to comment.