Commit a9eb7b48 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge pull request #82 from jsor/schema_events

Schema events
parents e4d01268 4befd47b
......@@ -214,6 +214,8 @@ class Connection implements DriverConnection
throw DBALException::invalidPlatformSpecified();
}
$this->_platform->setEventManager($eventManager);
$this->_transactionIsolationLevel = $this->_platform->getDefaultTransactionIsolationLevel();
}
......
<?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 LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Platforms\AbstractPlatform,
Doctrine\DBAL\Schema\Column,
Doctrine\DBAL\Schema\TableDiff;
/**
* Event Arguments used when SQL queries for adding table columns are generated inside Doctrine\DBAL\Platform\*Platform.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.com
* @since 2.2
* @author Jan Sorgalla <jsorgalla@googlemail.com>
*/
class SchemaAlterTableAddColumnEventArgs extends SchemaEventArgs
{
/**
* @var \Doctrine\DBAL\Schema\Column
*/
private $_column = null;
/**
* @var \Doctrine\DBAL\Schema\TableDiff
*/
private $_tableDiff = null;
/**
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
private $_platform = null;
/**
* @var array
*/
private $_sql = array();
/**
* @param \Doctrine\DBAL\Schema\Column $column
* @param \Doctrine\DBAL\Schema\TableDiff $tableDiff
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
*/
public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatform $platform)
{
$this->_column = $column;
$this->_tableDiff = $tableDiff;
$this->_platform = $platform;
}
/**
* @return \Doctrine\DBAL\Schema\Column
*/
public function getColumn()
{
return $this->_column;
}
/**
* @return \Doctrine\DBAL\Schema\TableDiff
*/
public function getTableDiff()
{
return $this->_tableDiff;
}
/**
* @return \Doctrine\DBAL\Platforms\AbstractPlatform
*/
public function getPlatform()
{
return $this->_platform;
}
/**
* @param string|array $sql
* @return \Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs
*/
public function addSql($sql)
{
if (is_array($sql)) {
$this->_sql = array_merge($this->_sql, $sql);
} else {
$this->_sql[] = $sql;
}
return $this;
}
/**
* @return array
*/
public function getSql()
{
return $this->_sql;
}
}
<?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 LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Platforms\AbstractPlatform,
Doctrine\DBAL\Schema\ColumnDiff,
Doctrine\DBAL\Schema\TableDiff;
/**
* Event Arguments used when SQL queries for changing table columns are generated inside Doctrine\DBAL\Platform\*Platform.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.com
* @since 2.2
* @author Jan Sorgalla <jsorgalla@googlemail.com>
*/
class SchemaAlterTableChangeColumnEventArgs extends SchemaEventArgs
{
/**
* @var \Doctrine\DBAL\Schema\ColumnDiff
*/
private $_columnDiff = null;
/**
* @var \Doctrine\DBAL\Schema\TableDiff
*/
private $_tableDiff = null;
/**
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
private $_platform = null;
/**
* @var array
*/
private $_sql = array();
/**
* @param \Doctrine\DBAL\Schema\ColumnDiff $columnDiff
* @param \Doctrine\DBAL\Schema\TableDiff $tableDiff
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
*/
public function __construct(ColumnDiff $columnDiff, TableDiff $tableDiff, AbstractPlatform $platform)
{
$this->_columnDiff = $columnDiff;
$this->_tableDiff = $tableDiff;
$this->_platform = $platform;
}
/**
* @return \Doctrine\DBAL\Schema\ColumnDiff
*/
public function getColumnDiff()
{
return $this->_columnDiff;
}
/**
* @return \Doctrine\DBAL\Schema\TableDiff
*/
public function getTableDiff()
{
return $this->_tableDiff;
}
/**
* @return \Doctrine\DBAL\Platforms\AbstractPlatform
*/
public function getPlatform()
{
return $this->_platform;
}
/**
* @param string|array $sql
* @return \Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs
*/
public function addSql($sql)
{
if (is_array($sql)) {
$this->_sql = array_merge($this->_sql, $sql);
} else {
$this->_sql[] = $sql;
}
return $this;
}
/**
* @return array
*/
public function getSql()
{
return $this->_sql;
}
}
<?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 LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Platforms\AbstractPlatform,
Doctrine\DBAL\Schema\Column,
Doctrine\DBAL\Schema\TableDiff;
/**
* Event Arguments used when SQL queries for creating tables are generated inside Doctrine\DBAL\Platform\*Platform.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.com
* @since 2.2
* @author Jan Sorgalla <jsorgalla@googlemail.com>
*/
class SchemaAlterTableEventArgs extends SchemaEventArgs
{
/**
* @var \Doctrine\DBAL\Schema\TableDiff
*/
private $_tableDiff = null;
/**
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
private $_platform = null;
/**
* @var array
*/
private $_sql = array();
/**
* @param \Doctrine\DBAL\Schema\TableDiff $tableDiff
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
*/
public function __construct(TableDiff $tableDiff, AbstractPlatform $platform)
{
$this->_tableDiff = $tableDiff;
$this->_platform = $platform;
}
/**
* @return \Doctrine\DBAL\Schema\TableDiff
*/
public function getTableDiff()
{
return $this->_tableDiff;
}
/**
* @return \Doctrine\DBAL\Platforms\AbstractPlatform
*/
public function getPlatform()
{
return $this->_platform;
}
/**
* @param string|array $sql
* @return \Doctrine\DBAL\Event\SchemaAlterTableEventArgs
*/
public function addSql($sql)
{
if (is_array($sql)) {
$this->_sql = array_merge($this->_sql, $sql);
} else {
$this->_sql[] = $sql;
}
return $this;
}
/**
* @return array
*/
public function getSql()
{
return $this->_sql;
}
}
<?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 LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Platforms\AbstractPlatform,
Doctrine\DBAL\Schema\Column,
Doctrine\DBAL\Schema\TableDiff;
/**
* Event Arguments used when SQL queries for removing table columns are generated inside Doctrine\DBAL\Platform\*Platform.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.com
* @since 2.2
* @author Jan Sorgalla <jsorgalla@googlemail.com>
*/
class SchemaAlterTableRemoveColumnEventArgs extends SchemaEventArgs
{
/**
* @var \Doctrine\DBAL\Schema\Column
*/
private $_column = null;
/**
* @var \Doctrine\DBAL\Schema\TableDiff
*/
private $_tableDiff = null;
/**
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
private $_platform = null;
/**
* @var array
*/
private $_sql = array();
/**
* @param \Doctrine\DBAL\Schema\Column $column
* @param \Doctrine\DBAL\Schema\TableDiff $tableDiff
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
*/
public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatform $platform)
{
$this->_column = $column;
$this->_tableDiff = $tableDiff;
$this->_platform = $platform;
}
/**
* @return \Doctrine\DBAL\Schema\Column
*/
public function getColumn()
{
return $this->_column;
}
/**
* @return \Doctrine\DBAL\Schema\TableDiff
*/
public function getTableDiff()
{
return $this->_tableDiff;
}
/**
* @return \Doctrine\DBAL\Platforms\AbstractPlatform
*/
public function getPlatform()
{
return $this->_platform;
}
/**
* @param string|array $sql
* @return \Doctrine\DBAL\Event\SchemaAlterTableRemoveColumnEventArgs
*/
public function addSql($sql)
{
if (is_array($sql)) {
$this->_sql = array_merge($this->_sql, $sql);
} else {
$this->_sql[] = $sql;
}
return $this;
}
/**
* @return array
*/
public function getSql()
{
return $this->_sql;
}
}
<?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 LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Platforms\AbstractPlatform,
Doctrine\DBAL\Schema\Column,
Doctrine\DBAL\Schema\TableDiff;
/**
* Event Arguments used when SQL queries for renaming table columns are generated inside Doctrine\DBAL\Platform\*Platform.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.com
* @since 2.2
* @author Jan Sorgalla <jsorgalla@googlemail.com>
*/
class SchemaAlterTableRenameColumnEventArgs extends SchemaEventArgs
{
/**
* @var string
*/
private $_oldColumnName = null;
/**
* @var \Doctrine\DBAL\Schema\Column
*/
private $_column = null;
/**
* @var \Doctrine\DBAL\Schema\TableDiff
*/
private $_tableDiff = null;
/**
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
private $_platform = null;
/**
* @var array
*/
private $_sql = array();
/**
* @param string $oldColumnName
* @param \Doctrine\DBAL\Schema\Column $column
* @param \Doctrine\DBAL\Schema\TableDiff $tableDiff
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
*/
public function __construct($oldColumnName, Column $column, TableDiff $tableDiff, AbstractPlatform $platform)
{
$this->_oldColumnName = $oldColumnName;
$this->_column = $column;
$this->_tableDiff = $tableDiff;
$this->_platform = $platform;
}
/**
* @return string
*/
public function getOldColumnName()
{
return $this->_oldColumnName;
}
/**
* @return \Doctrine\DBAL\Schema\Column
*/
public function getColumn()
{
return $this->_column;
}
/**
* @return \Doctrine\DBAL\Schema\TableDiff
*/
public function getTableDiff()
{
return $this->_tableDiff;
}
/**
* @return \Doctrine\DBAL\Platforms\AbstractPlatform
*/
public function getPlatform()
{
return $this->_platform;
}
/**
* @param string|array $sql
* @return \Doctrine\DBAL\Event\SchemaAlterTableRenameColumnEventArgs
*/
public function addSql($sql)
{
if (is_array($sql)) {
$this->_sql = array_merge($this->_sql, $sql);
} else {
$this->_sql[] = $sql;
}
return $this;
}
/**
* @return array
*/
public function getSql()
{
return $this->_sql;
}
}
<?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 LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Connection,
Doctrine\DBAL\Schema\Column;
/**
* Event Arguments used when the portable column definition is generated inside Doctrine\DBAL\Schema\AbstractSchemaManager.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.com
* @since 2.2
* @author Jan Sorgalla <jsorgalla@googlemail.com>
*/
class SchemaColumnDefinitionEventArgs extends SchemaEventArgs
{
/**
* @var \Doctrine\DBAL\Schema\Column
*/
private $_column = null;
/**
* Raw column data as fetched from the database
*
* @var array
*/
private $_tableColumn = null;
/**
* @var string
*/
private $_table = null;
/**
* @var string
*/
private $_database = null;
/**
* @var \Doctrine\DBAL\Connection
*/
private $_connection = null;
/**
* @param array $tableColumn
* @param string $table
* @param string $database
* @param \Doctrine\DBAL\Connection $conn
*/
public function __construct(array $tableColumn, $table, $database, Connection $connection)
{
$this->_tableColumn = $tableColumn;
$this->_table = $table;
$this->_database = $database;
$this->_connection = $connection;
}
/**
* Allows to clear the column which means the column will be excluded from
* tables column list.
*
* @param null|\Doctrine\DBAL\Schema\Column $column
* @return SchemaColumnDefinitionEventArgs
*/
public function setColumn(Column $column = null)
{
$this->_column = $column;
return $this;
}
/**
* @return \Doctrine\DBAL\Schema\Column
*/
public function getColumn()
{
return $this->_column;
}
/**
* @return array
*/
public function getTableColumn()
{
return $this->_tableColumn;
}
/**
* @return string
*/
public function getTable()
{
return $this->_table;
}
/**
* @return string
*/
public function getDatabase()
{
return $this->_database;
}
/**
* @return \Doctrine\DBAL\Connection
*/
public function getConnection()
{
return $this->_connection;
}
/**
* @return \Doctrine\DBAL\Platforms\AbstractPlatform
*/
public function getDatabasePlatform()
{
return $this->_connection->getDatabasePlatform();
}
}
<?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 LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Platforms\AbstractPlatform,
Doctrine\DBAL\Schema\Column,
Doctrine\DBAL\Schema\Table;
/**
* Event Arguments used when SQL queries for creating table columns are generated inside Doctrine\DBAL\Platform\AbstractPlatform.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.com
* @since 2.2
* @author Jan Sorgalla <jsorgalla@googlemail.com>
*/
class SchemaCreateTableColumnEventArgs extends SchemaEventArgs
{
/**
* @var \Doctrine\DBAL\Schema\Column
*/
private $_column = null;
/**
* @var \Doctrine\DBAL\Schema\Table
*/
private $_table = null;
/**
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
private $_platform = null;
/**
* @var array
*/
private $_sql = array();
/**
* @param \Doctrine\DBAL\Schema\Column $column
* @param \Doctrine\DBAL\Schema\Table $table
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
*/
public function __construct(Column $column, Table $table, AbstractPlatform $platform)
{
$this->_column = $column;
$this->_table = $table;
$this->_platform = $platform;
}
/**
* @return \Doctrine\DBAL\Schema\Column
*/
public function getColumn()
{
return $this->_column;
}
/**
* @return \Doctrine\DBAL\Schema\Table
*/
public function getTable()
{
return $this->_table;
}
/**
* @return \Doctrine\DBAL\Platforms\AbstractPlatform
*/
public function getPlatform()
{
return $this->_platform;
}
/**
* @param string|array $sql
* @return \Doctrine\DBAL\Event\SchemaCreateTableColumnEventArgs
*/
public function addSql($sql)
{
if (is_array($sql)) {
$this->_sql = array_merge($this->_sql, $sql);
} else {
$this->_sql[] = $sql;
}
return $this;
}
/**
* @return array
*/
public function getSql()
{
return $this->_sql;
}
}
<?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 LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Platforms\AbstractPlatform,
Doctrine\DBAL\Schema\Table;
/**
* Event Arguments used when SQL queries for creating tables are generated inside Doctrine\DBAL\Platform\AbstractPlatform.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.com
* @since 2.2
* @author Jan Sorgalla <jsorgalla@googlemail.com>
*/
class SchemaCreateTableEventArgs extends SchemaEventArgs
{
/**
* @var \Doctrine\DBAL\Schema\Table
*/
private $_table = null;
/**
* @var array
*/
private $_columns = null;
/**
* @var array
*/
private $_options = null;
/**
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
private $_platform = null;
/**
* @var array
*/
private $_sql = array();
/**
* @param \Doctrine\DBAL\Schema\Table $table
* @param array $columns
* @param array $options
* @param Doctrine\DBAL\Platforms\AbstractPlatform $platform
*/
public function __construct(Table $table, array $columns, array $options, AbstractPlatform $platform)
{
$this->_table = $table;
$this->_columns = $columns;
$this->_options = $options;
$this->_platform = $platform;
}
/**
* @return \Doctrine\DBAL\Schema\Table
*/
public function getTable()
{
return $this->_table;
}
/**
* @return array
*/
public function getColumns()
{
return $this->_columns;
}
/**
* @return array
*/
public function getOptions()
{
return $this->_options;
}
/**
* @return \Doctrine\DBAL\Platforms\AbstractPlatform
*/
public function getPlatform()
{
return $this->_platform;
}
/**
* @param string|array $sql
* @return \Doctrine\DBAL\Event\SchemaCreateTableEventArgs
*/
public function addSql($sql)
{
if (is_array($sql)) {
$this->_sql = array_merge($this->_sql, $sql);
} else {
$this->_sql[] = $sql;
}
return $this;
}
/**
* @return array
*/
public function getSql()
{
return $this->_sql;
}
}
<?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 LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Platforms\AbstractPlatform,
Doctrine\DBAL\Schema\Table;
/**
* Event Arguments used when the SQL query for dropping tables are generated inside Doctrine\DBAL\Platform\AbstractPlatform.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.com
* @since 2.2
* @author Jan Sorgalla <jsorgalla@googlemail.com>
*/
class SchemaDropTableEventArgs extends SchemaEventArgs
{
/**
* @var string|\Doctrine\DBAL\Schema\Table
*/
private $_table = null;
/**
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
private $_platform = null;
/**
* @var string
*/
private $_sql = null;
/**
* @param string|\Doctrine\DBAL\Schema\Table $table
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
*/
public function __construct($table, AbstractPlatform $platform)
{
if (!$table instanceof Table && !is_string($table)) {
throw new \InvalidArgumentException('SchemaCreateTableEventArgs expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
}
$this->_table = $table;
$this->_platform = $platform;
}
/**
* @return string|\Doctrine\DBAL\Schema\Table
*/
public function getTable()
{
return $this->_table;
}
/**
* @return \Doctrine\DBAL\Platforms\AbstractPlatform
*/
public function getPlatform()
{
return $this->_platform;
}
/**
* @param string $sql
* @return \Doctrine\DBAL\Event\SchemaDropTableEventArgs
*/
public function setSql($sql)
{
$this->_sql = $sql;
return $this;
}
/**
* @return string
*/
public function getSql()
{
return $this->_sql;
}
}
<?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 LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Event;
use Doctrine\Common\EventArgs;
/**
* Base class for schema related events.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.com
* @since 2.2
* @author Jan Sorgalla <jsorgalla@googlemail.com>
*/
class SchemaEventArgs extends EventArgs
{
/**
* @var boolean
*/
private $_preventDefault = false;
/**
* @return \Doctrine\DBAL\Event\SchemaEventArgs
*/
public function preventDefault()
{
$this->_preventDefault = true;
return $this;
}
/**
* @return boolean
*/
public function isDefaultPrevented()
{
return $this->_preventDefault;
}
}
<?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 LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Connection,
Doctrine\DBAL\Schema\Index;
/**
* Event Arguments used when the portable index definition is generated inside Doctrine\DBAL\Schema\AbstractSchemaManager.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.com
* @since 2.2
* @author Jan Sorgalla <jsorgalla@googlemail.com>
*/
class SchemaIndexDefinitionEventArgs extends SchemaEventArgs
{
/**
* @var \Doctrine\DBAL\Schema\Index
*/
private $_index = null;
/**
* Raw index data as fetched from the database
*
* @var array
*/
private $_tableIndex = null;
/**
* @var string
*/
private $_table = null;
/**
* @var \Doctrine\DBAL\Connection
*/
private $_connection = null;
/**
* @param array $tableIndex
* @param string $table
* @param \Doctrine\DBAL\Connection $conn
*/
public function __construct(array $tableIndex, $table, Connection $connection)
{
$this->_tableIndex = $tableIndex;
$this->_table = $table;
$this->_connection = $connection;
}
/**
* Allows to clear the index which means the index will be excluded from
* tables index list.
*
* @param null|\Doctrine\DBAL\Schema\Index $index
* @return SchemaIndexDefinitionEventArgs
*/
public function setIndex(Index $index = null)
{
$this->_index = $index;
return $this;
}
/**
* @return \Doctrine\DBAL\Schema\Index
*/
public function getIndex()
{
return $this->_index;
}
/**
* @return array
*/
public function getTableIndex()
{
return $this->_tableIndex;
}
/**
* @return string
*/
public function getTable()
{
return $this->_table;
}
/**
* @return \Doctrine\DBAL\Connection
*/
public function getConnection()
{
return $this->_connection;
}
/**
* @return \Doctrine\DBAL\Platforms\AbstractPlatform
*/
public function getDatabasePlatform()
{
return $this->_connection->getDatabasePlatform();
}
}
......@@ -34,5 +34,15 @@ final class Events
private function __construct() {}
const postConnect = 'postConnect';
}
const onSchemaCreateTable = 'onSchemaCreateTable';
const onSchemaCreateTableColumn = 'onSchemaCreateTableColumn';
const onSchemaDropTable = 'onSchemaDropTable';
const onSchemaAlterTable = 'onSchemaAlterTable';
const onSchemaAlterTableAddColumn = 'onSchemaAlterTableAddColumn';
const onSchemaAlterTableRemoveColumn = 'onSchemaAlterTableRemoveColumn';
const onSchemaAlterTableChangeColumn = 'onSchemaAlterTableChangeColumn';
const onSchemaAlterTableRenameColumn = 'onSchemaAlterTableRenameColumn';
const onSchemaColumnDefinition = 'onSchemaColumnDefinition';
const onSchemaIndexDefinition = 'onSchemaIndexDefinition';
}
......@@ -27,7 +27,18 @@ use Doctrine\DBAL\DBALException,
Doctrine\DBAL\Schema\ForeignKeyConstraint,
Doctrine\DBAL\Schema\TableDiff,
Doctrine\DBAL\Schema\Column,
Doctrine\DBAL\Types\Type;
Doctrine\DBAL\Schema\ColumnDiff,
Doctrine\DBAL\Types\Type,
Doctrine\DBAL\Events,
Doctrine\Common\EventManager,
Doctrine\DBAL\Event\SchemaCreateTableEventArgs,
Doctrine\DBAL\Event\SchemaCreateTableColumnEventArgs,
Doctrine\DBAL\Event\SchemaDropTableEventArgs,
Doctrine\DBAL\Event\SchemaAlterTableEventArgs,
Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs,
Doctrine\DBAL\Event\SchemaAlterTableRemoveColumnEventArgs,
Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs,
Doctrine\DBAL\Event\SchemaAlterTableRenameColumnEventArgs;
/**
* Base class for all DatabasePlatforms. The DatabasePlatforms are the central
......@@ -90,11 +101,36 @@ abstract class AbstractPlatform
*/
protected $doctrineTypeComments = null;
/**
* @var Doctrine\Common\EventManager
*/
protected $_eventManager;
/**
* Constructor.
*/
public function __construct() {}
/**
* Sets the EventManager used by the Platform.
*
* @param \Doctrine\Common\EventManager
*/
public function setEventManager(EventManager $eventManager)
{
$this->_eventManager = $eventManager;
}
/**
* Gets the EventManager used by the Platform.
*
* @return \Doctrine\Common\EventManager
*/
public function getEventManager()
{
return $this->_eventManager;
}
/**
* Gets the SQL snippet that declares a boolean column.
*
......@@ -876,12 +912,23 @@ abstract class AbstractPlatform
*/
public function getDropTableSQL($table)
{
$tableArg = $table;
if ($table instanceof \Doctrine\DBAL\Schema\Table) {
$table = $table->getQuotedName($this);
} else if(!is_string($table)) {
throw new \InvalidArgumentException('getDropTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
}
if (null !== $this->_eventManager && $this->_eventManager->hasListeners(Events::onSchemaDropTable)) {
$eventArgs = new SchemaDropTableEventArgs($tableArg, $this);
$this->_eventManager->dispatchEvent(Events::onSchemaDropTable, $eventArgs);
if ($eventArgs->isDefaultPrevented()) {
return $eventArgs->getSql();
}
}
return 'DROP TABLE ' . $table;
}
......@@ -987,9 +1034,22 @@ abstract class AbstractPlatform
}
}
$columnSql = array();
$columns = array();
foreach ($table->getColumns() AS $column) {
/* @var \Doctrine\DBAL\Schema\Column $column */
if (null !== $this->_eventManager && $this->_eventManager->hasListeners(Events::onSchemaCreateTableColumn)) {
$eventArgs = new SchemaCreateTableColumnEventArgs($column, $table, $this);
$this->_eventManager->dispatchEvent(Events::onSchemaCreateTableColumn, $eventArgs);
$columnSql = array_merge($columnSql, $eventArgs->getSql());
if ($eventArgs->isDefaultPrevented()) {
continue;
}
}
$columnData = array();
$columnData['name'] = $column->getQuotedName($this);
$columnData['type'] = $column->getType();
......@@ -1023,6 +1083,15 @@ abstract class AbstractPlatform
}
}
if (null !== $this->_eventManager && $this->_eventManager->hasListeners(Events::onSchemaCreateTable)) {
$eventArgs = new SchemaCreateTableEventArgs($table, $columns, $options, $this);
$this->_eventManager->dispatchEvent(Events::onSchemaCreateTable, $eventArgs);
if ($eventArgs->isDefaultPrevented()) {
return array_merge($eventArgs->getSql(), $columnSql);
}
}
$sql = $this->_getCreateTableSQL($tableName, $columns, $options);
if ($this->supportsCommentOnStatement()) {
foreach ($table->getColumns() AS $column) {
......@@ -1031,7 +1100,8 @@ abstract class AbstractPlatform
}
}
}
return $sql;
return array_merge($sql, $columnSql);
}
public function getCommentOnColumnSQL($tableName, $columnName, $comment)
......@@ -1253,6 +1323,120 @@ abstract class AbstractPlatform
throw DBALException::notSupported(__METHOD__);
}
/**
* @param Column $column
* @param TableDiff $diff
* @param array $columnSql
*/
protected function onSchemaAlterTableAddColumn(Column $column, TableDiff $diff, &$columnSql)
{
if (null === $this->_eventManager) {
return false;
}
if (!$this->_eventManager->hasListeners(Events::onSchemaAlterTableAddColumn)) {
return false;
}
$eventArgs = new SchemaAlterTableAddColumnEventArgs($column, $diff, $this);
$this->_eventManager->dispatchEvent(Events::onSchemaAlterTableAddColumn, $eventArgs);
$columnSql = array_merge($columnSql, $eventArgs->getSql());
return $eventArgs->isDefaultPrevented();
}
/**
* @param Column $column
* @param TableDiff $diff
* @param array $columnSql
*/
protected function onSchemaAlterTableRemoveColumn(Column $column, TableDiff $diff, &$columnSql)
{
if (null === $this->_eventManager) {
return false;
}
if (!$this->_eventManager->hasListeners(Events::onSchemaAlterTableRemoveColumn)) {
return false;
}
$eventArgs = new SchemaAlterTableRemoveColumnEventArgs($column, $diff, $this);
$this->_eventManager->dispatchEvent(Events::onSchemaAlterTableRemoveColumn, $eventArgs);
$columnSql = array_merge($columnSql, $eventArgs->getSql());
return $eventArgs->isDefaultPrevented();
}
/**
* @param ColumnDiff $columnDiff
* @param TableDiff $diff
* @param array $columnSql
*/
protected function onSchemaAlterTableChangeColumn(ColumnDiff $columnDiff, TableDiff $diff, &$columnSql)
{
if (null === $this->_eventManager) {
return false;
}
if (!$this->_eventManager->hasListeners(Events::onSchemaAlterTableChangeColumn)) {
return false;
}
$eventArgs = new SchemaAlterTableChangeColumnEventArgs($columnDiff, $diff, $this);
$this->_eventManager->dispatchEvent(Events::onSchemaAlterTableChangeColumn, $eventArgs);
$columnSql = array_merge($columnSql, $eventArgs->getSql());
return $eventArgs->isDefaultPrevented();
}
/**
* @param string $oldColumnName
* @param Column $column
* @param TableDiff $diff
* @param array $columnSql
*/
protected function onSchemaAlterTableRenameColumn($oldColumnName, Column $column, TableDiff $diff, &$columnSql)
{
if (null === $this->_eventManager) {
return false;
}
if (!$this->_eventManager->hasListeners(Events::onSchemaAlterTableRenameColumn)) {
return false;
}
$eventArgs = new SchemaAlterTableRenameColumnEventArgs($oldColumnName, $column, $diff, $this);
$this->_eventManager->dispatchEvent(Events::onSchemaAlterTableRenameColumn, $eventArgs);
$columnSql = array_merge($columnSql, $eventArgs->getSql());
return $eventArgs->isDefaultPrevented();
}
/**
* @param TableDiff $diff
* @param array $columnSql
*/
protected function onSchemaAlterTable(TableDiff $diff, &$sql)
{
if (null === $this->_eventManager) {
return false;
}
if (!$this->_eventManager->hasListeners(Events::onSchemaAlterTable)) {
return false;
}
$eventArgs = new SchemaAlterTableEventArgs($diff, $this);
$this->_eventManager->dispatchEvent(Events::onSchemaAlterTable, $eventArgs);
$sql = array_merge($sql, $eventArgs->getSql());
return $eventArgs->isDefaultPrevented();
}
protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff)
{
$tableName = $diff->name;
......
......@@ -373,17 +373,30 @@ class DB2Platform extends AbstractPlatform
public function getAlterTableSQL(TableDiff $diff)
{
$sql = array();
$columnSql = array();
$queryParts = array();
foreach ($diff->addedColumns AS $fieldName => $column) {
if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) {
continue;
}
$queryParts[] = 'ADD COLUMN ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
}
foreach ($diff->removedColumns AS $column) {
if ($this->onSchemaAlterTableRemoveColumn($column, $diff, $columnSql)) {
continue;
}
$queryParts[] = 'DROP COLUMN ' . $column->getQuotedName($this);
}
foreach ($diff->changedColumns AS $columnDiff) {
if ($this->onSchemaAlterTableChangeColumn($columnDiff, $diff, $columnSql)) {
continue;
}
/* @var $columnDiff Doctrine\DBAL\Schema\ColumnDiff */
$column = $columnDiff->column;
$queryParts[] = 'ALTER ' . ($columnDiff->oldColumnName) . ' '
......@@ -391,20 +404,28 @@ class DB2Platform extends AbstractPlatform
}
foreach ($diff->renamedColumns AS $oldColumnName => $column) {
if ($this->onSchemaAlterTableRenameColumn($oldColumnName, $column, $diff, $columnSql)) {
continue;
}
$queryParts[] = 'RENAME ' . $oldColumnName . ' TO ' . $column->getQuotedName($this);
}
if (count($queryParts) > 0) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . implode(" ", $queryParts);
}
$tableSql = array();
if (!$this->onSchemaAlterTable($diff, $tableSql)) {
if (count($queryParts) > 0) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . implode(" ", $queryParts);
}
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff));
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff));
if ($diff->newName !== false) {
$sql[] = 'RENAME TABLE TO ' . $diff->newName;
if ($diff->newName !== false) {
$sql[] = 'RENAME TABLE TO ' . $diff->newName;
}
}
return $sql;
return array_merge($sql, $tableSql, $columnSql);
}
public function getDefaultValueDeclarationSQL($field)
......
......@@ -278,20 +278,33 @@ class MsSqlPlatform extends AbstractPlatform
{
$queryParts = array();
$sql = array();
$columnSql = array();
if ($diff->newName !== false) {
$queryParts[] = 'RENAME TO ' . $diff->newName;
}
foreach ($diff->addedColumns AS $fieldName => $column) {
if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) {
continue;
}
$queryParts[] = 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
}
foreach ($diff->removedColumns AS $column) {
if ($this->onSchemaAlterTableRemoveColumn($column, $diff, $columnSql)) {
continue;
}
$queryParts[] = 'DROP COLUMN ' . $column->getQuotedName($this);
}
foreach ($diff->changedColumns AS $columnDiff) {
if ($this->onSchemaAlterTableChangeColumn($columnDiff, $diff, $columnSql)) {
continue;
}
/* @var $columnDiff Doctrine\DBAL\Schema\ColumnDiff */
$column = $columnDiff->column;
$queryParts[] = 'ALTER COLUMN ' .
......@@ -299,10 +312,20 @@ class MsSqlPlatform extends AbstractPlatform
}
foreach ($diff->renamedColumns AS $oldColumnName => $column) {
if ($this->onSchemaAlterTableRenameColumn($oldColumnName, $column, $diff, $columnSql)) {
continue;
}
$sql[] = "sp_RENAME '". $diff->name. ".". $oldColumnName . "' , '".$column->getQuotedName($this)."', 'COLUMN'";
$queryParts[] = 'ALTER COLUMN ' .
$this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
}
$tableSql = array();
if ($this->onSchemaAlterTable($diff, $tableSql)) {
return array_merge($tableSql, $columnSql);
}
foreach ($queryParts as $query) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query;
......@@ -310,7 +333,7 @@ class MsSqlPlatform extends AbstractPlatform
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff));
return $sql;
return array_merge($sql, $tableSql, $columnSql);
}
/**
......
......@@ -454,22 +454,35 @@ class MySqlPlatform extends AbstractPlatform
*/
public function getAlterTableSQL(TableDiff $diff)
{
$columnSql = array();
$queryParts = array();
if ($diff->newName !== false) {
$queryParts[] = 'RENAME TO ' . $diff->newName;
}
foreach ($diff->addedColumns AS $fieldName => $column) {
if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) {
continue;
}
$columnArray = $column->toArray();
$columnArray['comment'] = $this->getColumnComment($column);
$queryParts[] = 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray);
}
foreach ($diff->removedColumns AS $column) {
if ($this->onSchemaAlterTableRemoveColumn($column, $diff, $columnSql)) {
continue;
}
$queryParts[] = 'DROP ' . $column->getQuotedName($this);
}
foreach ($diff->changedColumns AS $columnDiff) {
if ($this->onSchemaAlterTableChangeColumn($columnDiff, $diff, $columnSql)) {
continue;
}
/* @var $columnDiff Doctrine\DBAL\Schema\ColumnDiff */
$column = $columnDiff->column;
$columnArray = $column->toArray();
......@@ -479,6 +492,10 @@ class MySqlPlatform extends AbstractPlatform
}
foreach ($diff->renamedColumns AS $oldColumnName => $column) {
if ($this->onSchemaAlterTableRenameColumn($oldColumnName, $column, $diff, $columnSql)) {
continue;
}
$columnArray = $column->toArray();
$columnArray['comment'] = $this->getColumnComment($column);
$queryParts[] = 'CHANGE ' . $oldColumnName . ' '
......@@ -486,15 +503,20 @@ class MySqlPlatform extends AbstractPlatform
}
$sql = array();
if (count($queryParts) > 0) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . implode(", ", $queryParts);
$tableSql = array();
if (!$this->onSchemaAlterTable($diff, $tableSql)) {
if (count($queryParts) > 0) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . implode(", ", $queryParts);
}
$sql = array_merge(
$this->getPreAlterTableIndexForeignKeySQL($diff),
$sql,
$this->getPostAlterTableIndexForeignKeySQL($diff)
);
}
$sql = array_merge(
$this->getPreAlterTableIndexForeignKeySQL($diff),
$sql,
$this->getPostAlterTableIndexForeignKeySQL($diff)
);
return $sql;
return array_merge($sql, $tableSql, $columnSql);
}
/**
......
......@@ -570,9 +570,14 @@ LEFT JOIN all_cons_columns r_cols
{
$sql = array();
$commentsSQL = array();
$columnSql = array();
$fields = array();
foreach ($diff->addedColumns AS $column) {
if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) {
continue;
}
$fields[] = $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
if ($comment = $this->getColumnComment($column)) {
$commentsSQL[] = $this->getCommentOnColumnSQL($diff->name, $column->getName(), $comment);
......@@ -584,6 +589,10 @@ LEFT JOIN all_cons_columns r_cols
$fields = array();
foreach ($diff->changedColumns AS $columnDiff) {
if ($this->onSchemaAlterTableChangeColumn($columnDiff, $diff, $columnSql)) {
continue;
}
$column = $columnDiff->column;
$fields[] = $column->getQuotedName($this). ' ' . $this->getColumnDeclarationSQL('', $column->toArray());
if ($columnDiff->hasChanged('comment') && $comment = $this->getColumnComment($column)) {
......@@ -595,22 +604,36 @@ LEFT JOIN all_cons_columns r_cols
}
foreach ($diff->renamedColumns AS $oldColumnName => $column) {
if ($this->onSchemaAlterTableRenameColumn($oldColumnName, $column, $diff, $columnSql)) {
continue;
}
$sql[] = 'ALTER TABLE ' . $diff->name . ' RENAME COLUMN ' . $oldColumnName .' TO ' . $column->getQuotedName($this);
}
$fields = array();
foreach ($diff->removedColumns AS $column) {
if ($this->onSchemaAlterTableRemoveColumn($column, $diff, $columnSql)) {
continue;
}
$fields[] = $column->getQuotedName($this);
}
if (count($fields)) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' DROP (' . implode(', ', $fields).')';
}
if ($diff->newName !== false) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' RENAME TO ' . $diff->newName;
$tableSql = array();
if (!$this->onSchemaAlterTable($diff, $tableSql)) {
if ($diff->newName !== false) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' RENAME TO ' . $diff->newName;
}
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff), $commentsSQL);
}
return array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff), $commentsSQL);
return array_merge($sql, $tableSql, $columnSql);
}
/**
......
......@@ -380,8 +380,13 @@ class PostgreSqlPlatform extends AbstractPlatform
{
$sql = array();
$commentsSQL = array();
$columnSql = array();
foreach ($diff->addedColumns as $column) {
if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) {
continue;
}
$query = 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query;
if ($comment = $this->getColumnComment($column)) {
......@@ -390,11 +395,19 @@ class PostgreSqlPlatform extends AbstractPlatform
}
foreach ($diff->removedColumns as $column) {
if ($this->onSchemaAlterTableRemoveColumn($column, $diff, $columnSql)) {
continue;
}
$query = 'DROP ' . $column->getQuotedName($this);
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query;
}
foreach ($diff->changedColumns AS $columnDiff) {
if ($this->onSchemaAlterTableChangeColumn($columnDiff, $diff, $columnSql)) {
continue;
}
$oldColumnName = $columnDiff->oldColumnName;
$column = $columnDiff->column;
......@@ -434,14 +447,24 @@ class PostgreSqlPlatform extends AbstractPlatform
}
foreach ($diff->renamedColumns as $oldColumnName => $column) {
if ($this->onSchemaAlterTableRenameColumn($oldColumnName, $column, $diff, $columnSql)) {
continue;
}
$sql[] = 'ALTER TABLE ' . $diff->name . ' RENAME COLUMN ' . $oldColumnName . ' TO ' . $column->getQuotedName($this);
}
if ($diff->newName !== false) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' RENAME TO ' . $diff->newName;
$tableSql = array();
if (!$this->onSchemaAlterTable($diff, $tableSql)) {
if ($diff->newName !== false) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' RENAME TO ' . $diff->newName;
}
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff), $commentsSQL);
}
return array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff), $commentsSQL);
return array_merge($sql, $tableSql, $columnSql);
}
/**
......
......@@ -19,6 +19,9 @@
namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Events;
use Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs;
use Doctrine\DBAL\Event\SchemaIndexDefinitionEventArgs;
use Doctrine\DBAL\Types;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
......@@ -153,7 +156,7 @@ abstract class AbstractSchemaManager
$tableColumns = $this->_conn->fetchAll($sql);
return $this->_getPortableTableColumnList($tableColumns);
return $this->_getPortableTableColumnList($table, $database, $tableColumns);
}
/**
......@@ -618,14 +621,33 @@ abstract class AbstractSchemaManager
*
* The name of the created column instance however is kept in its case.
*
* @param array $tableColumns
* @param string $table The name of the table.
* @param string $database
* @param array $tableColumns
* @return array
*/
protected function _getPortableTableColumnList($tableColumns)
protected function _getPortableTableColumnList($table, $database, $tableColumns)
{
$eventManager = $this->_platform->getEventManager();
$list = array();
foreach ($tableColumns as $key => $column) {
if ($column = $this->_getPortableTableColumnDefinition($column)) {
foreach ($tableColumns as $key => $tableColumn) {
$column = null;
$defaultPrevented = false;
if (null !== $eventManager && $eventManager->hasListeners(Events::onSchemaColumnDefinition)) {
$eventArgs = new SchemaColumnDefinitionEventArgs($tableColumn, $table, $database, $this->_conn);
$eventManager->dispatchEvent(Events::onSchemaColumnDefinition, $eventArgs);
$defaultPrevented = $eventArgs->isDefaultPrevented();
$column = $eventArgs->getColumn();
}
if (!$defaultPrevented) {
$column = $this->_getPortableTableColumnDefinition($tableColumn);
}
if ($column) {
$name = strtolower($column->getQuotedName($this->_platform));
$list[$name] = $column;
}
......@@ -670,9 +692,28 @@ abstract class AbstractSchemaManager
}
}
$eventManager = $this->_platform->getEventManager();
$indexes = array();
foreach($result AS $indexKey => $data) {
$indexes[$indexKey] = new Index($data['name'], $data['columns'], $data['unique'], $data['primary']);
$index = null;
$defaultPrevented = false;
if (null !== $eventManager && $eventManager->hasListeners(Events::onSchemaIndexDefinition)) {
$eventArgs = new SchemaIndexDefinitionEventArgs($data, $tableName, $this->_conn);
$eventManager->dispatchEvent(Events::onSchemaIndexDefinition, $eventArgs);
$defaultPrevented = $eventArgs->isDefaultPrevented();
$index = $eventArgs->getIndex();
}
if (!$defaultPrevented) {
$index = new Index($data['name'], $data['columns'], $data['unique'], $data['primary']);
}
if ($index) {
$indexes[$indexKey] = $index;
}
}
return $indexes;
......
......@@ -93,6 +93,11 @@ class Column extends AbstractAsset
*/
protected $_comment = null;
/**
* @var array
*/
protected $_customSchemaOptions = array();
/**
* Create a new Column
*
......@@ -340,6 +345,53 @@ class Column extends AbstractAsset
return $this->_comment;
}
/**
* @param string $name
* @param mixed $value
* @return Column
*/
public function setCustomSchemaOption($name, $value)
{
$this->_customSchemaOptions[$name] = $value;
return $this;
}
/**
* @param string $name
* @return boolean
*/
public function hasCustomSchemaOption($name)
{
return isset($this->_customSchemaOptions[$name]);
}
/**
* @param string $name
* @return mixed
*/
public function getCustomSchemaOption($name)
{
return $this->_customSchemaOptions[$name];
}
/**
* @param array $customSchemaOptions
* @return Column
*/
public function setCustomSchemaOptions(array $customSchemaOptions)
{
$this->_customSchemaOptions = $customSchemaOptions;
return $this;
}
/**
* @return array
*/
public function getCustomSchemaOptions()
{
return $this->_customSchemaOptions;
}
/**
* @param Visitor $visitor
*/
......@@ -366,6 +418,6 @@ class Column extends AbstractAsset
'autoincrement' => $this->_autoincrement,
'columnDefinition' => $this->_columnDefinition,
'comment' => $this->_comment,
), $this->_platformOptions);
), $this->_platformOptions, $this->_customSchemaOptions);
}
}
\ No newline at end of file
......@@ -355,6 +355,21 @@ class Comparator
$changedProperties[] = 'comment';
}
$options1 = $column1->getCustomSchemaOptions();
$options2 = $column2->getCustomSchemaOptions();
$commonKeys = array_keys(array_intersect_key($options1, $options2));
foreach ($commonKeys as $key) {
if ($options1[$key] !== $options2[$key]) {
$changedProperties[] = $key;
}
}
$diffKeys = array_keys(array_diff_key($options1, $options2) + array_diff_key($options2, $options1));
$changedProperties = array_merge($changedProperties, $diffKeys);
return $changedProperties;
}
......
......@@ -21,6 +21,8 @@
namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Event\SchemaIndexDefinitionEventArgs;
/**
* IBM Db2 Schema Manager
*
......@@ -120,6 +122,8 @@ class DB2SchemaManager extends AbstractSchemaManager
protected function _getPortableTableIndexesList($tableIndexes, $tableName=null)
{
$eventManager = $this->_platform->getEventManager();
$tableIndexRows = array();
$indexes = array();
foreach($tableIndexes AS $indexKey => $data) {
......@@ -134,7 +138,31 @@ class DB2SchemaManager extends AbstractSchemaManager
$keyName = $indexName;
}
$indexes[$keyName] = new Index($indexName, explode("+", ltrim($data['colnames'], '+')), $unique, $primary);
$data = array(
'name' => $indexName,
'columns' => explode("+", ltrim($data['colnames'], '+')),
'unique' => $unique,
'primary' => $primary
);
$index = null;
$defaultPrevented = false;
if (null !== $eventManager && $eventManager->hasListeners(Events::onSchemaIndexDefinition)) {
$eventArgs = new SchemaIndexDefinitionEventArgs($data, $tableName, $this->_conn);
$eventManager->dispatchEvent(Events::onSchemaIndexDefinition, $eventArgs);
$defaultPrevented = $eventArgs->isDefaultPrevented();
$index = $eventArgs->getIndex();
}
if (!$defaultPrevented) {
$index = new Index($data['name'], $data['columns'], $data['unique'], $data['primary']);
}
if ($index) {
$indexes[$indexKey] = $index;
}
}
return $indexes;
......
......@@ -19,6 +19,8 @@
namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Event\SchemaIndexDefinitionEventArgs;
/**
* xxx
*
......@@ -119,9 +121,28 @@ class MsSqlSchemaManager extends AbstractSchemaManager
);
}
$eventManager = $this->_platform->getEventManager();
$indexes = array();
foreach ($result AS $indexKey => $data) {
$indexes[$indexKey] = new Index($data['name'], $data['columns'], $data['unique'], $data['primary']);
$index = null;
$defaultPrevented = false;
if (null !== $eventManager && $eventManager->hasListeners(Events::onSchemaIndexDefinition)) {
$eventArgs = new SchemaIndexDefinitionEventArgs($data, $tableName, $this->_conn);
$eventManager->dispatchEvent(Events::onSchemaIndexDefinition, $eventArgs);
$defaultPrevented = $eventArgs->isDefaultPrevented();
$index = $eventArgs->getIndex();
}
if (!$defaultPrevented) {
$index = new Index($data['name'], $data['columns'], $data['unique'], $data['primary']);
}
if ($index) {
$indexes[$indexKey] = $index;
}
}
return $indexes;
......
......@@ -217,7 +217,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
}
}
}
return parent::_getPortableTableIndexesList($buffer);
return parent::_getPortableTableIndexesList($buffer, $tableName);
}
protected function _getPortableDatabaseDefinition($database)
......
......@@ -96,7 +96,7 @@ class CreateSchemaSqlCollector implements Visitor
if ($this->_platform->supportsForeignKeyConstraints()) {
$this->_createFkConstraintQueries = array_merge($this->_createFkConstraintQueries,
(array) $this->_platform->getCreateForeignKeySQL(
$fkConstraint, $localTable->getQuotedName($this->_platform)
$fkConstraint, $localTable
)
);
}
......
......@@ -143,15 +143,15 @@ class DropSchemaSqlCollector implements Visitor
$sql = array();
foreach ($this->constraints AS $fkConstraint) {
$localTable = $this->constraints[$fkConstraint];
$sql[] = $this->platform->getDropForeignKeySQL($fkConstraint->getQuotedName($this->platform), $localTable->getQuotedName($this->platform));
$sql[] = $this->platform->getDropForeignKeySQL($fkConstraint, $localTable);
}
foreach ($this->sequences AS $sequence) {
$sql[] = $this->platform->getDropSequenceSQL($sequence->getQuotedName($this->platform));
$sql[] = $this->platform->getDropSequenceSQL($sequence);
}
foreach ($this->tables AS $table) {
$sql[] = $this->platform->getDropTableSQL($table->getQuotedName($this->platform));
$sql[] = $this->platform->getDropTableSQL($table);
}
return $sql;
......
......@@ -116,6 +116,12 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
$conn->connect();
}
public function testEventManagerPassedToPlatform()
{
$this->assertInstanceOf('Doctrine\Common\EventManager', $this->_conn->getDatabasePlatform()->getEventManager());
$this->assertSame($this->_conn->getEventManager(), $this->_conn->getDatabasePlatform()->getEventManager());
}
/**
* Pretty dumb test, however we want to check that the EchoSQLLogger correctly implements the interface.
*
......
......@@ -5,6 +5,8 @@ namespace Doctrine\Tests\DBAL\Functional\Schema;
use Doctrine\DBAL\Types\Type,
Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Events;
require_once __DIR__ . '/../../../TestInit.php';
......@@ -171,6 +173,54 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$this->assertInternalType('array', $columns['baz3']->getPlatformOptions());
}
public function testListTableColumnsDispatchEvent()
{
$table = $this->createListTableColumns();
$this->_sm->dropAndCreateTable($table);
$listenerMock = $this->getMock('ListTableColumnsDispatchEventListener', array('onSchemaColumnDefinition'));
$listenerMock
->expects($this->exactly(7))
->method('onSchemaColumnDefinition');
$oldEventManager = $this->_sm->getDatabasePlatform()->getEventManager();
$eventManager = new EventManager();
$eventManager->addEventListener(array(Events::onSchemaColumnDefinition), $listenerMock);
$this->_sm->getDatabasePlatform()->setEventManager($eventManager);
$this->_sm->listTableColumns('list_table_columns');
$this->_sm->getDatabasePlatform()->setEventManager($oldEventManager);
}
public function testListTableIndexesDispatchEvent()
{
$table = $this->getTestTable('list_table_indexes_test');
$table->addUniqueIndex(array('test'), 'test_index_name');
$table->addIndex(array('id', 'test'), 'test_composite_idx');
$this->_sm->dropAndCreateTable($table);
$listenerMock = $this->getMock('ListTableIndexesDispatchEventListener', array('onSchemaIndexDefinition'));
$listenerMock
->expects($this->exactly(3))
->method('onSchemaIndexDefinition');
$oldEventManager = $this->_sm->getDatabasePlatform()->getEventManager();
$eventManager = new EventManager();
$eventManager->addEventListener(array(Events::onSchemaIndexDefinition), $listenerMock);
$this->_sm->getDatabasePlatform()->setEventManager($eventManager);
$this->_sm->listTableIndexes('list_table_indexes_test');
$this->_sm->getDatabasePlatform()->setEventManager($oldEventManager);
}
public function testDiffListTableColumns()
{
if ($this->_sm->getDatabasePlatform()->getName() == 'oracle') {
......@@ -192,7 +242,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$table->addUniqueIndex(array('test'), 'test_index_name');
$table->addIndex(array('id', 'test'), 'test_composite_idx');
$this->_sm->createTable($table);
$this->_sm->dropAndCreateTable($table);
$tableIndexes = $this->_sm->listTableIndexes('list_table_indexes_test');
......
......@@ -2,6 +2,9 @@
namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Events;
abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
{
/**
......@@ -204,6 +207,96 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$this->assertEquals('foo MEDIUMINT(6) UNSIGNED', $this->_platform->getColumnDeclarationSQL('foo', $field));
}
public function testGetCreateTableSqlDispatchEvent()
{
$listenerMock = $this->getMock('GetCreateTableSqlDispatchEvenListener', array('onSchemaCreateTable', 'onSchemaCreateTableColumn'));
$listenerMock
->expects($this->once())
->method('onSchemaCreateTable');
$listenerMock
->expects($this->exactly(2))
->method('onSchemaCreateTableColumn');
$eventManager = new EventManager();
$eventManager->addEventListener(array(Events::onSchemaCreateTable, Events::onSchemaCreateTableColumn), $listenerMock);
$this->_platform->setEventManager($eventManager);
$table = new \Doctrine\DBAL\Schema\Table('test');
$table->addColumn('foo', 'string', array('notnull' => false, 'length' => 255));
$table->addColumn('bar', 'string', array('notnull' => false, 'length' => 255));
$this->_platform->getCreateTableSQL($table);
}
public function testGetDropTableSqlDispatchEvent()
{
$listenerMock = $this->getMock('GetDropTableSqlDispatchEventListener', array('onSchemaDropTable'));
$listenerMock
->expects($this->once())
->method('onSchemaDropTable');
$eventManager = new EventManager();
$eventManager->addEventListener(array(Events::onSchemaDropTable), $listenerMock);
$this->_platform->setEventManager($eventManager);
$this->_platform->getDropTableSQL('TABLE');
}
public function testGetAlterTableSqlDispatchEvent()
{
$events = array(
'onSchemaAlterTable',
'onSchemaAlterTableAddColumn',
'onSchemaAlterTableRemoveColumn',
'onSchemaAlterTableChangeColumn',
'onSchemaAlterTableRenameColumn'
);
$listenerMock = $this->getMock('GetAlterTableSqlDispatchEvenListener', $events);
$listenerMock
->expects($this->once())
->method('onSchemaAlterTable');
$listenerMock
->expects($this->once())
->method('onSchemaAlterTableAddColumn');
$listenerMock
->expects($this->once())
->method('onSchemaAlterTableRemoveColumn');
$listenerMock
->expects($this->once())
->method('onSchemaAlterTableChangeColumn');
$listenerMock
->expects($this->once())
->method('onSchemaAlterTableRenameColumn');
$eventManager = new EventManager();
$events = array(
Events::onSchemaAlterTable,
Events::onSchemaAlterTableAddColumn,
Events::onSchemaAlterTableRemoveColumn,
Events::onSchemaAlterTableChangeColumn,
Events::onSchemaAlterTableRenameColumn
);
$eventManager->addEventListener($events, $listenerMock);
$this->_platform->setEventManager($eventManager);
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff('mytable');
$tableDiff->addedColumns['added'] = new \Doctrine\DBAL\Schema\Column('added', \Doctrine\DBAL\Types\Type::getType('integer'), array());
$tableDiff->removedColumns['removed'] = new \Doctrine\DBAL\Schema\Column('removed', \Doctrine\DBAL\Types\Type::getType('integer'), array());
$tableDiff->changedColumns['changed'] = new \Doctrine\DBAL\Schema\ColumnDiff(
'changed', new \Doctrine\DBAL\Schema\Column(
'changed2', \Doctrine\DBAL\Types\Type::getType('string'), array()
),
array()
);
$tableDiff->renamedColumns['renamed'] = new \Doctrine\DBAL\Schema\Column('renamed2', \Doctrine\DBAL\Types\Type::getType('integer'), array());
$this->_platform->getAlterTableSQL($tableDiff);
}
/**
* @group DBAL-42
*/
......
......@@ -126,4 +126,9 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
{
$this->markTestSkipped('SQlite does not support ALTER Table.');
}
public function testGetAlterTableSqlDispatchEvent()
{
$this->markTestSkipped('SQlite does not support ALTER Table.');
}
}
\ No newline at end of file
......@@ -30,6 +30,11 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($column->hasPlatformOption('foo'));
$this->assertEquals('bar', $column->getPlatformOption('foo'));
$this->assertFalse($column->hasPlatformOption('bar'));
$this->assertEquals(array('bar' => 'baz'), $column->getCustomSchemaOptions());
$this->assertTrue($column->hasCustomSchemaOption('bar'));
$this->assertEquals('baz', $column->getCustomSchemaOption('bar'));
$this->assertFalse($column->hasCustomSchemaOption('foo'));
}
public function testToArray()
......@@ -48,6 +53,7 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
'columnDefinition' => null,
'comment' => null,
'foo' => 'bar',
'bar' => 'baz'
);
$this->assertEquals($expected, $this->createColumn()->toArray());
......@@ -67,6 +73,7 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
'fixed' => true,
'default' => 'baz',
'platformOptions' => array('foo' => 'bar'),
'customSchemaOptions' => array('bar' => 'baz'),
);
$string = Type::getType('string');
......
......@@ -193,6 +193,22 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array(), $c->diffColumn($column1, $column1));
}
public function testCompareChangedColumns_ChangeCustomSchemaOption()
{
$column1 = new Column('charfield1', Type::getType('string'));
$column2 = new Column('charfield1', Type::getType('string'));
$column1->setCustomSchemaOption('foo', 'bar');
$column2->setCustomSchemaOption('foo', 'bar');
$column1->setCustomSchemaOption('foo1', 'bar1');
$column2->setCustomSchemaOption('foo2', 'bar2');
$c = new Comparator();
$this->assertEquals(array('foo1', 'foo2'), $c->diffColumn($column1, $column2));
$this->assertEquals(array(), $c->diffColumn($column1, $column1));
}
public function testCompareRemovedIndex()
{
$schema1 = new Schema( array(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment