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
Hide 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,9 +38,10 @@ final class Events
const
onSchemaCreateTable
=
'onSchemaCreateTable'
;
const
onSchemaCreateTableColumn
=
'onSchemaCreateTableColumn'
;
const
onSchemaDropTable
=
'onSchemaDropTable'
;
const
onSchemaAlterTableAddColumn
=
'onSchemaAlterTableAddColumn'
;
const
onSchemaAlterTableRemoveColumn
=
'onSchemaAlterTableRemoveColumn'
;
const
onSchemaAlterTableChangeColumn
=
'onSchemaAlterTableChangeColumn'
;
const
onSchemaAlterTableRenameColumn
=
'onSchemaAlterTableRenameColumn'
;
const
onSchemaAlterTable
=
'onSchemaAlterTable'
;
const
onSchemaAlterTableAddColumn
=
'onSchemaAlterTableAddColumn'
;
const
onSchemaAlterTableRemoveColumn
=
'onSchemaAlterTableRemoveColumn'
;
const
onSchemaAlterTableChangeColumn
=
'onSchemaAlterTableChangeColumn'
;
const
onSchemaAlterTableRenameColumn
=
'onSchemaAlterTableRenameColumn'
;
const
onSchemaColumnDefinition
=
'onSchemaColumnDefinition'
;
}
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
5bc8a179
...
...
@@ -34,6 +34,7 @@ use Doctrine\DBAL\DBALException,
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
,
...
...
@@ -1378,6 +1379,27 @@ abstract class AbstractPlatform
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
)
{
...
...
lib/Doctrine/DBAL/Platforms/DB2Platform.php
View file @
5bc8a179
...
...
@@ -411,17 +411,21 @@ class DB2Platform extends AbstractPlatform
$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
array_merge
(
$sql
,
$columnSql
);
return
array_merge
(
$sql
,
$
tableSql
,
$
columnSql
);
}
public
function
getDefaultValueDeclarationSQL
(
$field
)
...
...
lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
View file @
5bc8a179
...
...
@@ -320,14 +320,20 @@ class MsSqlPlatform extends AbstractPlatform
$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
;
}
$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
}
$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
),
$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
$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
,
$t
his
->
_getAlterTableIndexForeignKeySQL
(
$diff
),
$commentsSQL
,
$columnSql
);
return
array_merge
(
$sql
,
$t
ableSql
,
$columnSql
);
}
/**
...
...
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
5bc8a179
...
...
@@ -454,11 +454,17 @@ class PostgreSqlPlatform extends AbstractPlatform
$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
,
$t
his
->
_getAlterTableIndexForeignKeySQL
(
$diff
),
$commentsSQL
,
$columnSql
);
return
array_merge
(
$sql
,
$t
ableSql
,
$columnSql
);
}
/**
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
View file @
5bc8a179
...
...
@@ -219,6 +219,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
public
function
testGetAlterTableSqlDispatchEvent
()
{
$events
=
array
(
'onSchemaAlterTable'
,
'onSchemaAlterTableAddColumn'
,
'onSchemaAlterTableRemoveColumn'
,
'onSchemaAlterTableChangeColumn'
,
...
...
@@ -226,6 +227,9 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
);
$listenerMock
=
$this
->
getMock
(
'GetAlterTableSqlDispatchEvenListener'
,
$events
);
$listenerMock
->
expects
(
$this
->
once
())
->
method
(
'onSchemaAlterTable'
);
$listenerMock
->
expects
(
$this
->
once
())
->
method
(
'onSchemaAlterTableAddColumn'
);
...
...
@@ -241,6 +245,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$eventManager
=
new
EventManager
();
$events
=
array
(
Events
::
onSchemaAlterTable
,
Events
::
onSchemaAlterTableAddColumn
,
Events
::
onSchemaAlterTableRemoveColumn
,
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