composer update
This commit is contained in:
@@ -1,28 +1,13 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Id;
|
||||
|
||||
use Doctrine\DBAL\DriverManager;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\DBALException;
|
||||
use Doctrine\DBAL\DriverManager;
|
||||
use Doctrine\DBAL\FetchMode;
|
||||
use Doctrine\DBAL\LockMode;
|
||||
use Throwable;
|
||||
use const CASE_LOWER;
|
||||
use function array_change_key_case;
|
||||
|
||||
@@ -62,39 +47,30 @@ use function array_change_key_case;
|
||||
*
|
||||
* If no row is present for a given sequence a new one will be created with the
|
||||
* default values 'value' = 1 and 'increment_by' = 1
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class TableGenerator
|
||||
{
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Connection
|
||||
*/
|
||||
/** @var Connection */
|
||||
private $conn;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
/** @var string */
|
||||
private $generatorTableName;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
/** @var mixed[][] */
|
||||
private $sequences = [];
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Connection $conn
|
||||
* @param string $generatorTableName
|
||||
* @param string $generatorTableName
|
||||
*
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
* @throws DBALException
|
||||
*/
|
||||
public function __construct(Connection $conn, $generatorTableName = 'sequences')
|
||||
{
|
||||
$params = $conn->getParams();
|
||||
if ($params['driver'] == 'pdo_sqlite') {
|
||||
throw new \Doctrine\DBAL\DBALException("Cannot use TableGenerator with SQLite.");
|
||||
if ($params['driver'] === 'pdo_sqlite') {
|
||||
throw new DBALException('Cannot use TableGenerator with SQLite.');
|
||||
}
|
||||
$this->conn = DriverManager::getConnection($params, $conn->getConfiguration(), $conn->getEventManager());
|
||||
$this->conn = DriverManager::getConnection($params, $conn->getConfiguration(), $conn->getEventManager());
|
||||
$this->generatorTableName = $generatorTableName;
|
||||
}
|
||||
|
||||
@@ -105,7 +81,7 @@ class TableGenerator
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
* @throws DBALException
|
||||
*/
|
||||
public function nextValue($sequenceName)
|
||||
{
|
||||
@@ -113,7 +89,7 @@ class TableGenerator
|
||||
$value = $this->sequences[$sequenceName]['value'];
|
||||
$this->sequences[$sequenceName]['value']++;
|
||||
if ($this->sequences[$sequenceName]['value'] >= $this->sequences[$sequenceName]['max']) {
|
||||
unset ($this->sequences[$sequenceName]);
|
||||
unset($this->sequences[$sequenceName]);
|
||||
}
|
||||
|
||||
return $value;
|
||||
@@ -138,17 +114,17 @@ class TableGenerator
|
||||
if ($row['sequence_increment_by'] > 1) {
|
||||
$this->sequences[$sequenceName] = [
|
||||
'value' => $value,
|
||||
'max' => $row['sequence_value'] + $row['sequence_increment_by']
|
||||
'max' => $row['sequence_value'] + $row['sequence_increment_by'],
|
||||
];
|
||||
}
|
||||
|
||||
$sql = "UPDATE " . $this->generatorTableName . " ".
|
||||
"SET sequence_value = sequence_value + sequence_increment_by " .
|
||||
"WHERE sequence_name = ? AND sequence_value = ?";
|
||||
$sql = 'UPDATE ' . $this->generatorTableName . ' ' .
|
||||
'SET sequence_value = sequence_value + sequence_increment_by ' .
|
||||
'WHERE sequence_name = ? AND sequence_value = ?';
|
||||
$rows = $this->conn->executeUpdate($sql, [$sequenceName, $row['sequence_value']]);
|
||||
|
||||
if ($rows != 1) {
|
||||
throw new \Doctrine\DBAL\DBALException("Race-condition detected while updating sequence. Aborting generation");
|
||||
if ($rows !== 1) {
|
||||
throw new DBALException('Race-condition detected while updating sequence. Aborting generation');
|
||||
}
|
||||
} else {
|
||||
$this->conn->insert(
|
||||
@@ -159,10 +135,9 @@ class TableGenerator
|
||||
}
|
||||
|
||||
$this->conn->commit();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
} catch (Throwable $e) {
|
||||
$this->conn->rollBack();
|
||||
throw new \Doctrine\DBAL\DBALException("Error occurred while generating ID with TableGenerator, aborted generation: " . $e->getMessage(), 0, $e);
|
||||
throw new DBALException('Error occurred while generating ID with TableGenerator, aborted generation: ' . $e->getMessage(), 0, $e);
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
||||
@@ -1,36 +1,18 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Id;
|
||||
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\Column;
|
||||
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
|
||||
use Doctrine\DBAL\Schema\Sequence;
|
||||
use Doctrine\DBAL\Schema\Index;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\Sequence;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Schema\Visitor\Visitor;
|
||||
|
||||
class TableGeneratorSchemaVisitor implements \Doctrine\DBAL\Schema\Visitor\Visitor
|
||||
class TableGeneratorSchemaVisitor implements Visitor
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
/** @var string */
|
||||
private $generatorTableName;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user