Skip to content

Commit a188172

Browse files
committed
Added PostgresqlGateway
1 parent 8f93363 commit a188172

File tree

6 files changed

+112
-10
lines changed

6 files changed

+112
-10
lines changed

src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,16 +1357,7 @@ public function setName(int $contentId, int $version, string $name, string $lang
13571357
*/
13581358
private function getSetNameLanguageMaskSubQuery(): string
13591359
{
1360-
return <<<SQL
1361-
(SELECT
1362-
CASE
1363-
WHEN (initial_language_id = :language_id AND (language_mask & :language_id) <> 0 )
1364-
THEN (:language_id | 1)
1365-
ELSE :language_id
1366-
END
1367-
FROM ezcontentobject
1368-
WHERE id = :content_id)
1369-
SQL;
1360+
return $this->sharedGateway->getSetNameLanguageMaskSubQuery();
13701361
}
13711362

13721363
public function deleteContent(int $contentId): void

src/lib/Persistence/Legacy/SharedGateway/DatabasePlatform/FallbackGateway.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,28 @@ public function getColumnNextIntegerValue(
2929
return null;
3030
}
3131

32+
/**
33+
* Return a language sub select query for setName.
34+
*
35+
* The query generates the proper language mask at the runtime of the INSERT/UPDATE query
36+
* generated by setName.
37+
*
38+
* @see setName
39+
*/
40+
public function getSetNameLanguageMaskSubQuery(): string
41+
{
42+
return <<<SQL
43+
(SELECT
44+
CASE
45+
WHEN (initial_language_id = :language_id AND (language_mask & :language_id) <> 0 )
46+
THEN (:language_id | 1)
47+
ELSE :language_id
48+
END
49+
FROM ezcontentobject
50+
WHERE id = :content_id)
51+
SQL;
52+
}
53+
3254
public function getLastInsertedId(string $sequenceName): int
3355
{
3456
return (int)$this->connection->lastInsertId($sequenceName);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Core\Persistence\Legacy\SharedGateway\DatabasePlatform;
10+
11+
use Doctrine\DBAL\Connection;
12+
use Ibexa\Core\Persistence\Legacy\SharedGateway\Gateway;
13+
14+
final class PostgresqlGateway implements Gateway
15+
{
16+
/** @var \Doctrine\DBAL\Connection */
17+
private $connection;
18+
19+
public function __construct(Connection $connection)
20+
{
21+
$this->connection = $connection;
22+
}
23+
24+
public function getColumnNextIntegerValue(
25+
string $tableName,
26+
string $columnName,
27+
string $sequenceName
28+
): ?int {
29+
return null;
30+
}
31+
32+
public function getLastInsertedId(string $sequenceName): int
33+
{
34+
return (int)$this->connection->lastInsertId($sequenceName);
35+
}
36+
37+
/**
38+
* Return a language sub select query for setName.
39+
*
40+
* The query generates the proper language mask at the runtime of the INSERT/UPDATE query
41+
* generated by setName.
42+
*
43+
* @see setName
44+
*/
45+
public function getSetNameLanguageMaskSubQuery(): string
46+
{
47+
return <<<SQL
48+
(SELECT
49+
CASE
50+
WHEN (initial_language_id = :language_id AND (language_mask & :language_id) <> 0 )
51+
THEN (cast(:language_id as BIGINT) | 1)
52+
ELSE :language_id
53+
END
54+
FROM ezcontentobject
55+
WHERE id = :content_id)
56+
SQL;
57+
}
58+
}

src/lib/Persistence/Legacy/SharedGateway/DatabasePlatform/SqliteGateway.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,28 @@ public function getLastInsertedId(string $sequenceName): int
4949

5050
return $this->lastInsertedIds[$sequenceName];
5151
}
52+
53+
/**
54+
* Return a language sub select query for setName.
55+
*
56+
* The query generates the proper language mask at the runtime of the INSERT/UPDATE query
57+
* generated by setName.
58+
*
59+
* @see setName
60+
*/
61+
public function getSetNameLanguageMaskSubQuery(): string
62+
{
63+
return <<<SQL
64+
(SELECT
65+
CASE
66+
WHEN (initial_language_id = :language_id AND (language_mask & :language_id) <> 0 )
67+
THEN (:language_id | 1)
68+
ELSE :language_id
69+
END
70+
FROM ezcontentobject
71+
WHERE id = :content_id)
72+
SQL;
73+
}
5274
}
5375

5476
class_alias(SqliteGateway::class, 'eZ\Publish\Core\Persistence\Legacy\SharedGateway\DatabasePlatform\SqliteGateway');

src/lib/Persistence/Legacy/SharedGateway/Gateway.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public function getColumnNextIntegerValue(
4141
* It returns integer as all the IDs in the Ibexa Legacy Storage are (big)integers
4242
*/
4343
public function getLastInsertedId(string $sequenceName): int;
44+
45+
/**
46+
* Return a language sub select query for setName.
47+
*/
48+
public function getSetNameLanguageMaskSubQuery(): string;
4449
}
4550

4651
class_alias(Gateway::class, 'eZ\Publish\Core\Persistence\Legacy\SharedGateway\Gateway');

src/lib/Resources/settings/storage_engines/legacy/shared_gateway.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ services:
1212
tags:
1313
- { name: ibexa.storage.legacy.gateway.shared, platform: sqlite }
1414

15+
Ibexa\Core\Persistence\Legacy\SharedGateway\DatabasePlatform\PostgresqlGateway:
16+
tags:
17+
- { name: ibexa.storage.legacy.gateway.shared, platform: postgresql }
18+
1519
Ibexa\Core\Persistence\Legacy\SharedGateway\GatewayFactory:
1620
arguments:
1721
$fallbackGateway: '@Ibexa\Core\Persistence\Legacy\SharedGateway\DatabasePlatform\FallbackGateway'

0 commit comments

Comments
 (0)