Passed
Push — master ( c57cd2...a0c679 )
by Jeremy
04:45 queued 14s
created

WallabagMigration::isTransactional()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Wallabag\CoreBundle\Doctrine;
4
5
use Doctrine\DBAL\Schema\Schema;
6
use Doctrine\Migrations\AbstractMigration;
7
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8
use Symfony\Component\DependencyInjection\ContainerInterface;
9
10
abstract class WallabagMigration extends AbstractMigration implements ContainerAwareInterface
11
{
12
    const UN_ESCAPED_TABLE = true;
13
14
    /**
15
     * @var ContainerInterface
16
     */
17
    protected $container;
18
19
    // because there are declared as abstract in `AbstractMigration` we need to delarer here too
20
    public function up(Schema $schema)
21
    {
22
    }
23
24
    public function down(Schema $schema)
25
    {
26
    }
27
28
    public function setContainer(ContainerInterface $container = null)
29
    {
30
        $this->container = $container;
31
    }
32
33
    /**
34
     * @todo remove when upgrading DoctrineMigration (only needed for PHP 8)
35
     *
36
     * @see https://github.com/doctrine/DoctrineMigrationsBundle/issues/393
37
     */
38
    public function isTransactional(): bool
39
    {
40
        return false;
41
    }
42
43
    protected function getTable($tableName, $unEscaped = false)
44
    {
45
        $table = $this->container->getParameter('database_table_prefix') . $tableName;
46
47
        if (self::UN_ESCAPED_TABLE === $unEscaped) {
48
            return $table;
49
        }
50
51
        // escape table name is handled using " on postgresql
52
        if ('postgresql' === $this->connection->getDatabasePlatform()->getName()) {
53
            return '"' . $table . '"';
54
        }
55
56
        // return escaped table
57
        return '`' . $table . '`';
58
    }
59
}
60