Completed
Push — ezp-31420-merge-up ( ec14fb...141a64 )
by
unknown
40:13 queued 27:42
created

SqliteConnectionHandler::getSequenceName()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
nc 4
nop 2
dl 0
loc 16
rs 8.8333
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Publish\Core\Persistence\Doctrine\ConnectionHandler;
8
9
use eZ\Publish\Core\Persistence\Doctrine\ConnectionHandler;
10
11
class SqliteConnectionHandler extends ConnectionHandler
0 ignored issues
show
Deprecated Code introduced by
The class eZ\Publish\Core\Persiste...trine\ConnectionHandler has been deprecated with message: Since 6.13, please use Doctrine DBAL instead (@ezpublish.persistence.connection) it provides richer and more powerful DB abstraction which is also easier to use.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
12
{
13
    protected $lastInsertedIds = [];
14
15
    /**
16
     * Retrieve the last auto incremet or sequence id.
17
     *
18
     * @param string $sequenceName
19
     *
20
     * @return string
21
     */
22
    public function lastInsertId($sequenceName = null)
23
    {
24
        if (isset($this->lastInsertedIds[$sequenceName])) {
25
            $lastInsertId = $this->lastInsertedIds[$sequenceName];
26
            unset($this->lastInsertedIds[$sequenceName]);
27
28
            return $lastInsertId;
29
        }
30
31
        return $this->connection->lastInsertId($sequenceName);
32
    }
33
34
    /**
35
     * Get auto increment value.
36
     *
37
     * Returns the value used for autoincrement tables. Usually this will just
38
     * be null. In case for sequence based RDBMS this method can return a
39
     * proper value for the given column.
40
     *
41
     * @param string $table
42
     * @param string $column
43
     *
44
     * @return mixed
45
     */
46
    public function getAutoIncrementValue($table, $column)
47
    {
48 View Code Duplication
        if (($table === 'ezcontentobject_attribute') && ($column === 'id')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
            // This is a @HACK -- since this table has a multi-column key with
50
            // auto-increment, which is not easy to simulate in SQLite. This
51
            // solves it for now.
52
            $q = $this->createSelectQuery();
53
            $q->select($q->expr->max('id'))->from('ezcontentobject_attribute');
54
            $statement = $q->prepare();
55
            $statement->execute();
56
57
            $this->lastInsertedIds['ezcontentobject_attribute.id'] = (int)$statement->fetchColumn() + 1;
58
59
            return $this->lastInsertedIds['ezcontentobject_attribute.id'];
60
        }
61
62 View Code Duplication
        if (($table === 'ezcontentclass') && ($column === 'id')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
            // This is a @HACK -- since this table has a multi-column key with
64
            // auto-increment, which is not easy to simulate in SQLite. This
65
            // solves it for now.
66
            $q = $this->createSelectQuery();
67
            $q->select($q->expr->max('id'))->from('ezcontentclass');
68
            $statement = $q->prepare();
69
            $statement->execute();
70
71
            $this->lastInsertedIds['ezcontentclass.id'] = (int)$statement->fetchColumn() + 1;
72
73
            return $this->lastInsertedIds['ezcontentclass.id'];
74
        }
75
76 View Code Duplication
        if (($table === 'ezcontentclass_attribute') && ($column === 'id')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
            // This is a @HACK -- since this table has a multi-column key with
78
            // auto-increment, which is not easy to simulate in SQLite. This
79
            // solves it for now.
80
            $q = $this->createSelectQuery();
81
            $q->select($q->expr->max('id'))->from('ezcontentclass_attribute');
82
            $statement = $q->prepare();
83
            $statement->execute();
84
85
            $this->lastInsertedIds['ezcontentclass_attribute.id'] = (int)$statement->fetchColumn() + 1;
86
87
            return $this->lastInsertedIds['ezcontentclass_attribute.id'];
88
        }
89
90
        return 'NULL';
91
    }
92
93
    /**
94
     * Returns the name of the affected sequence.
95
     *
96
     * @param string $table
97
     * @param string $column
98
     *
99
     * @return string
100
     */
101
    public function getSequenceName($table, $column)
102
    {
103
        if (($table === 'ezcontentobject_attribute') && ($column === 'id')) {
104
            return "{$table}.{$column}";
105
        }
106
107
        if (($table === 'ezcontentclass') && ($column === 'id')) {
108
            return "{$table}.{$column}";
109
        }
110
111
        if (($table === 'ezcontentclass_attribute') && ($column === 'id')) {
112
            return "{$table}.{$column}";
113
        }
114
115
        return null;
116
    }
117
}
118