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
b175e1c2
Commit
b175e1c2
authored
Dec 13, 2011
by
Jan Sorgalla
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new onSchemaIndexDefinition event
parent
445e39e4
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
222 additions
and
5 deletions
+222
-5
SchemaIndexDefinitionEventArgs.php
lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php
+122
-0
Events.php
lib/Doctrine/DBAL/Events.php
+1
-0
AbstractSchemaManager.php
lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
+21
-1
DB2SchemaManager.php
lib/Doctrine/DBAL/Schema/DB2SchemaManager.php
+29
-1
MsSqlSchemaManager.php
lib/Doctrine/DBAL/Schema/MsSqlSchemaManager.php
+22
-1
PostgreSqlSchemaManager.php
lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
+1
-1
SchemaManagerFunctionalTestCase.php
...BAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
+26
-1
No files found.
lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php
0 → 100644
View file @
b175e1c2
<?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
();
}
}
lib/Doctrine/DBAL/Events.php
View file @
b175e1c2
...
@@ -44,4 +44,5 @@ final class Events
...
@@ -44,4 +44,5 @@ final class Events
const
onSchemaAlterTableChangeColumn
=
'onSchemaAlterTableChangeColumn'
;
const
onSchemaAlterTableChangeColumn
=
'onSchemaAlterTableChangeColumn'
;
const
onSchemaAlterTableRenameColumn
=
'onSchemaAlterTableRenameColumn'
;
const
onSchemaAlterTableRenameColumn
=
'onSchemaAlterTableRenameColumn'
;
const
onSchemaColumnDefinition
=
'onSchemaColumnDefinition'
;
const
onSchemaColumnDefinition
=
'onSchemaColumnDefinition'
;
const
onSchemaIndexDefinition
=
'onSchemaIndexDefinition'
;
}
}
lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
View file @
b175e1c2
...
@@ -21,6 +21,7 @@ namespace Doctrine\DBAL\Schema;
...
@@ -21,6 +21,7 @@ namespace Doctrine\DBAL\Schema;
use
Doctrine\DBAL\Events
;
use
Doctrine\DBAL\Events
;
use
Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs
;
use
Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs
;
use
Doctrine\DBAL\Event\SchemaIndexDefinitionEventArgs
;
use
Doctrine\DBAL\Types
;
use
Doctrine\DBAL\Types
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
...
@@ -691,9 +692,28 @@ abstract class AbstractSchemaManager
...
@@ -691,9 +692,28 @@ abstract class AbstractSchemaManager
}
}
}
}
$eventManager
=
$this
->
_platform
->
getEventManager
();
$indexes
=
array
();
$indexes
=
array
();
foreach
(
$result
AS
$indexKey
=>
$data
)
{
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
;
return
$indexes
;
...
...
lib/Doctrine/DBAL/Schema/DB2SchemaManager.php
View file @
b175e1c2
...
@@ -21,6 +21,8 @@
...
@@ -21,6 +21,8 @@
namespace
Doctrine\DBAL\Schema
;
namespace
Doctrine\DBAL\Schema
;
use
Doctrine\DBAL\Event\SchemaIndexDefinitionEventArgs
;
/**
/**
* IBM Db2 Schema Manager
* IBM Db2 Schema Manager
*
*
...
@@ -120,6 +122,8 @@ class DB2SchemaManager extends AbstractSchemaManager
...
@@ -120,6 +122,8 @@ class DB2SchemaManager extends AbstractSchemaManager
protected
function
_getPortableTableIndexesList
(
$tableIndexes
,
$tableName
=
null
)
protected
function
_getPortableTableIndexesList
(
$tableIndexes
,
$tableName
=
null
)
{
{
$eventManager
=
$this
->
_platform
->
getEventManager
();
$tableIndexRows
=
array
();
$tableIndexRows
=
array
();
$indexes
=
array
();
$indexes
=
array
();
foreach
(
$tableIndexes
AS
$indexKey
=>
$data
)
{
foreach
(
$tableIndexes
AS
$indexKey
=>
$data
)
{
...
@@ -134,7 +138,31 @@ class DB2SchemaManager extends AbstractSchemaManager
...
@@ -134,7 +138,31 @@ class DB2SchemaManager extends AbstractSchemaManager
$keyName
=
$indexName
;
$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
;
return
$indexes
;
...
...
lib/Doctrine/DBAL/Schema/MsSqlSchemaManager.php
View file @
b175e1c2
...
@@ -19,6 +19,8 @@
...
@@ -19,6 +19,8 @@
namespace
Doctrine\DBAL\Schema
;
namespace
Doctrine\DBAL\Schema
;
use
Doctrine\DBAL\Event\SchemaIndexDefinitionEventArgs
;
/**
/**
* xxx
* xxx
*
*
...
@@ -119,9 +121,28 @@ class MsSqlSchemaManager extends AbstractSchemaManager
...
@@ -119,9 +121,28 @@ class MsSqlSchemaManager extends AbstractSchemaManager
);
);
}
}
$eventManager
=
$this
->
_platform
->
getEventManager
();
$indexes
=
array
();
$indexes
=
array
();
foreach
(
$result
AS
$indexKey
=>
$data
)
{
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
;
return
$indexes
;
...
...
lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
View file @
b175e1c2
...
@@ -218,7 +218,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
...
@@ -218,7 +218,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
}
}
}
}
}
}
return
parent
::
_getPortableTableIndexesList
(
$buffer
);
return
parent
::
_getPortableTableIndexesList
(
$buffer
,
$tableName
);
}
}
protected
function
_getPortableDatabaseDefinition
(
$database
)
protected
function
_getPortableDatabaseDefinition
(
$database
)
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
View file @
b175e1c2
...
@@ -196,6 +196,31 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
...
@@ -196,6 +196,31 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$this
->
_sm
->
getDatabasePlatform
()
->
setEventManager
(
$oldEventManager
);
$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
()
public
function
testDiffListTableColumns
()
{
{
if
(
$this
->
_sm
->
getDatabasePlatform
()
->
getName
()
==
'oracle'
)
{
if
(
$this
->
_sm
->
getDatabasePlatform
()
->
getName
()
==
'oracle'
)
{
...
@@ -217,7 +242,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
...
@@ -217,7 +242,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$table
->
addUniqueIndex
(
array
(
'test'
),
'test_index_name'
);
$table
->
addUniqueIndex
(
array
(
'test'
),
'test_index_name'
);
$table
->
addIndex
(
array
(
'id'
,
'test'
),
'test_composite_idx'
);
$table
->
addIndex
(
array
(
'id'
,
'test'
),
'test_composite_idx'
);
$this
->
_sm
->
c
reateTable
(
$table
);
$this
->
_sm
->
dropAndC
reateTable
(
$table
);
$tableIndexes
=
$this
->
_sm
->
listTableIndexes
(
'list_table_indexes_test'
);
$tableIndexes
=
$this
->
_sm
->
listTableIndexes
(
'list_table_indexes_test'
);
...
...
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