Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
5bc8a179
Commit
5bc8a179
authored
Dec 11, 2011
by
Jan Sorgalla
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing general alter table event
parent
a6bef6a3
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
182 additions
and
28 deletions
+182
-28
SchemaAlterTableEventArgs.php
lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php
+100
-0
Events.php
lib/Doctrine/DBAL/Events.php
+5
-4
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+22
-0
DB2Platform.php
lib/Doctrine/DBAL/Platforms/DB2Platform.php
+11
-7
MsSqlPlatform.php
lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
+8
-2
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+13
-9
OraclePlatform.php
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
+9
-3
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+9
-3
AbstractPlatformTestCase.php
...octrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
+5
-0
No files found.
lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php
0 → 100644
View file @
5bc8a179
<?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
,
Doctrine\DBAL\Platforms\AbstractPlatform
,
Doctrine\DBAL\Schema\TableDiff
,
Doctrine\DBAL\Schema\Column
;
/**
* 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 TableDiff
*/
private
$_tableDiff
=
null
;
/**
* @var AbstractPlatform
*/
private
$_platform
=
null
;
/**
* @var array
*/
private
$_sql
=
array
();
/**
* @param TableDiff $tableDiff
* @param 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 SchemaEventArgs
*/
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
;
}
}
lib/Doctrine/DBAL/Events.php
View file @
5bc8a179
...
@@ -38,6 +38,7 @@ final class Events
...
@@ -38,6 +38,7 @@ final class Events
const
onSchemaCreateTable
=
'onSchemaCreateTable'
;
const
onSchemaCreateTable
=
'onSchemaCreateTable'
;
const
onSchemaCreateTableColumn
=
'onSchemaCreateTableColumn'
;
const
onSchemaCreateTableColumn
=
'onSchemaCreateTableColumn'
;
const
onSchemaDropTable
=
'onSchemaDropTable'
;
const
onSchemaDropTable
=
'onSchemaDropTable'
;
const
onSchemaAlterTable
=
'onSchemaAlterTable'
;
const
onSchemaAlterTableAddColumn
=
'onSchemaAlterTableAddColumn'
;
const
onSchemaAlterTableAddColumn
=
'onSchemaAlterTableAddColumn'
;
const
onSchemaAlterTableRemoveColumn
=
'onSchemaAlterTableRemoveColumn'
;
const
onSchemaAlterTableRemoveColumn
=
'onSchemaAlterTableRemoveColumn'
;
const
onSchemaAlterTableChangeColumn
=
'onSchemaAlterTableChangeColumn'
;
const
onSchemaAlterTableChangeColumn
=
'onSchemaAlterTableChangeColumn'
;
...
...
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
5bc8a179
...
@@ -34,6 +34,7 @@ use Doctrine\DBAL\DBALException,
...
@@ -34,6 +34,7 @@ use Doctrine\DBAL\DBALException,
Doctrine\DBAL\Event\SchemaCreateTableEventArgs
,
Doctrine\DBAL\Event\SchemaCreateTableEventArgs
,
Doctrine\DBAL\Event\SchemaCreateTableColumnEventArgs
,
Doctrine\DBAL\Event\SchemaCreateTableColumnEventArgs
,
Doctrine\DBAL\Event\SchemaDropTableEventArgs
,
Doctrine\DBAL\Event\SchemaDropTableEventArgs
,
Doctrine\DBAL\Event\SchemaAlterTableEventArgs
,
Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs
,
Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs
,
Doctrine\DBAL\Event\SchemaAlterTableRemoveColumnEventArgs
,
Doctrine\DBAL\Event\SchemaAlterTableRemoveColumnEventArgs
,
Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs
,
Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs
,
...
@@ -1378,6 +1379,27 @@ abstract class AbstractPlatform
...
@@ -1378,6 +1379,27 @@ abstract class AbstractPlatform
return
$eventArgs
->
isDefaultPrevented
();
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
)
protected
function
getPreAlterTableIndexForeignKeySQL
(
TableDiff
$diff
)
{
{
...
...
lib/Doctrine/DBAL/Platforms/DB2Platform.php
View file @
5bc8a179
...
@@ -411,6 +411,9 @@ class DB2Platform extends AbstractPlatform
...
@@ -411,6 +411,9 @@ class DB2Platform extends AbstractPlatform
$queryParts
[]
=
'RENAME '
.
$oldColumnName
.
' TO '
.
$column
->
getQuotedName
(
$this
);
$queryParts
[]
=
'RENAME '
.
$oldColumnName
.
' TO '
.
$column
->
getQuotedName
(
$this
);
}
}
$tableSql
=
array
();
if
(
!
$this
->
onSchemaAlterTable
(
$diff
,
$tableSql
))
{
if
(
count
(
$queryParts
)
>
0
)
{
if
(
count
(
$queryParts
)
>
0
)
{
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' '
.
implode
(
" "
,
$queryParts
);
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' '
.
implode
(
" "
,
$queryParts
);
}
}
...
@@ -420,8 +423,9 @@ class DB2Platform extends AbstractPlatform
...
@@ -420,8 +423,9 @@ class DB2Platform extends AbstractPlatform
if
(
$diff
->
newName
!==
false
)
{
if
(
$diff
->
newName
!==
false
)
{
$sql
[]
=
'RENAME TABLE TO '
.
$diff
->
newName
;
$sql
[]
=
'RENAME TABLE TO '
.
$diff
->
newName
;
}
}
}
return
array_merge
(
$sql
,
$columnSql
);
return
array_merge
(
$sql
,
$
tableSql
,
$
columnSql
);
}
}
public
function
getDefaultValueDeclarationSQL
(
$field
)
public
function
getDefaultValueDeclarationSQL
(
$field
)
...
...
lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
View file @
5bc8a179
...
@@ -321,13 +321,19 @@ class MsSqlPlatform extends AbstractPlatform
...
@@ -321,13 +321,19 @@ class MsSqlPlatform extends AbstractPlatform
$this
->
getColumnDeclarationSQL
(
$column
->
getQuotedName
(
$this
),
$column
->
toArray
());
$this
->
getColumnDeclarationSQL
(
$column
->
getQuotedName
(
$this
),
$column
->
toArray
());
}
}
$tableSql
=
array
();
if
(
$this
->
onSchemaAlterTable
(
$diff
,
$tableSql
))
{
return
array_merge
(
$tableSql
,
$columnSql
);
}
foreach
(
$queryParts
as
$query
)
{
foreach
(
$queryParts
as
$query
)
{
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' '
.
$query
;
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' '
.
$query
;
}
}
$sql
=
array_merge
(
$sql
,
$this
->
_getAlterTableIndexForeignKeySQL
(
$diff
)
,
$columnSql
);
$sql
=
array_merge
(
$sql
,
$this
->
_getAlterTableIndexForeignKeySQL
(
$diff
));
return
$sql
;
return
array_merge
(
$sql
,
$tableSql
,
$columnSql
)
;
}
}
/**
/**
...
...
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
5bc8a179
...
@@ -503,16 +503,20 @@ class MySqlPlatform extends AbstractPlatform
...
@@ -503,16 +503,20 @@ class MySqlPlatform extends AbstractPlatform
}
}
$sql
=
array
();
$sql
=
array
();
$tableSql
=
array
();
if
(
!
$this
->
onSchemaAlterTable
(
$diff
,
$tableSql
))
{
if
(
count
(
$queryParts
)
>
0
)
{
if
(
count
(
$queryParts
)
>
0
)
{
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' '
.
implode
(
", "
,
$queryParts
);
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' '
.
implode
(
", "
,
$queryParts
);
}
}
$sql
=
array_merge
(
$sql
=
array_merge
(
$this
->
getPreAlterTableIndexForeignKeySQL
(
$diff
),
$this
->
getPreAlterTableIndexForeignKeySQL
(
$diff
),
$sql
,
$sql
,
$this
->
getPostAlterTableIndexForeignKeySQL
(
$diff
),
$this
->
getPostAlterTableIndexForeignKeySQL
(
$diff
)
$columnSql
);
);
return
$sql
;
}
return
array_merge
(
$sql
,
$tableSql
,
$columnSql
);
}
}
/**
/**
...
...
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
View file @
5bc8a179
...
@@ -593,11 +593,17 @@ LEFT JOIN all_cons_columns r_cols
...
@@ -593,11 +593,17 @@ LEFT JOIN all_cons_columns r_cols
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' DROP ('
.
implode
(
', '
,
$fields
)
.
')'
;
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' DROP ('
.
implode
(
', '
,
$fields
)
.
')'
;
}
}
$tableSql
=
array
();
if
(
!
$this
->
onSchemaAlterTable
(
$diff
,
$tableSql
))
{
if
(
$diff
->
newName
!==
false
)
{
if
(
$diff
->
newName
!==
false
)
{
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' RENAME TO '
.
$diff
->
newName
;
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' RENAME TO '
.
$diff
->
newName
;
}
}
return
array_merge
(
$sql
,
$this
->
_getAlterTableIndexForeignKeySQL
(
$diff
),
$commentsSQL
,
$columnSql
);
$sql
=
array_merge
(
$sql
,
$this
->
_getAlterTableIndexForeignKeySQL
(
$diff
),
$commentsSQL
);
}
return
array_merge
(
$sql
,
$tableSql
,
$columnSql
);
}
}
/**
/**
...
...
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
5bc8a179
...
@@ -454,11 +454,17 @@ class PostgreSqlPlatform extends AbstractPlatform
...
@@ -454,11 +454,17 @@ class PostgreSqlPlatform extends AbstractPlatform
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' RENAME COLUMN '
.
$oldColumnName
.
' TO '
.
$column
->
getQuotedName
(
$this
);
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' RENAME COLUMN '
.
$oldColumnName
.
' TO '
.
$column
->
getQuotedName
(
$this
);
}
}
$tableSql
=
array
();
if
(
!
$this
->
onSchemaAlterTable
(
$diff
,
$tableSql
))
{
if
(
$diff
->
newName
!==
false
)
{
if
(
$diff
->
newName
!==
false
)
{
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' RENAME TO '
.
$diff
->
newName
;
$sql
[]
=
'ALTER TABLE '
.
$diff
->
name
.
' RENAME TO '
.
$diff
->
newName
;
}
}
return
array_merge
(
$sql
,
$this
->
_getAlterTableIndexForeignKeySQL
(
$diff
),
$commentsSQL
,
$columnSql
);
$sql
=
array_merge
(
$sql
,
$this
->
_getAlterTableIndexForeignKeySQL
(
$diff
),
$commentsSQL
);
}
return
array_merge
(
$sql
,
$tableSql
,
$columnSql
);
}
}
/**
/**
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
View file @
5bc8a179
...
@@ -219,6 +219,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
...
@@ -219,6 +219,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
public
function
testGetAlterTableSqlDispatchEvent
()
public
function
testGetAlterTableSqlDispatchEvent
()
{
{
$events
=
array
(
$events
=
array
(
'onSchemaAlterTable'
,
'onSchemaAlterTableAddColumn'
,
'onSchemaAlterTableAddColumn'
,
'onSchemaAlterTableRemoveColumn'
,
'onSchemaAlterTableRemoveColumn'
,
'onSchemaAlterTableChangeColumn'
,
'onSchemaAlterTableChangeColumn'
,
...
@@ -226,6 +227,9 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
...
@@ -226,6 +227,9 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
);
);
$listenerMock
=
$this
->
getMock
(
'GetAlterTableSqlDispatchEvenListener'
,
$events
);
$listenerMock
=
$this
->
getMock
(
'GetAlterTableSqlDispatchEvenListener'
,
$events
);
$listenerMock
->
expects
(
$this
->
once
())
->
method
(
'onSchemaAlterTable'
);
$listenerMock
$listenerMock
->
expects
(
$this
->
once
())
->
expects
(
$this
->
once
())
->
method
(
'onSchemaAlterTableAddColumn'
);
->
method
(
'onSchemaAlterTableAddColumn'
);
...
@@ -241,6 +245,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
...
@@ -241,6 +245,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$eventManager
=
new
EventManager
();
$eventManager
=
new
EventManager
();
$events
=
array
(
$events
=
array
(
Events
::
onSchemaAlterTable
,
Events
::
onSchemaAlterTableAddColumn
,
Events
::
onSchemaAlterTableAddColumn
,
Events
::
onSchemaAlterTableRemoveColumn
,
Events
::
onSchemaAlterTableRemoveColumn
,
Events
::
onSchemaAlterTableChangeColumn
,
Events
::
onSchemaAlterTableChangeColumn
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment