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
d6095a24
Commit
d6095a24
authored
Jun 14, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added IntegrityMapper for future emulation purposes
parent
72466b36
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
179 additions
and
1 deletion
+179
-1
IntegrityMapper.php
lib/Doctrine/IntegrityMapper.php
+142
-0
Manager.php
lib/Doctrine/Manager.php
+27
-0
Parser.php
lib/Doctrine/Relation/Parser.php
+10
-1
No files found.
lib/Doctrine/IntegrityMapper.php
0 → 100644
View file @
d6095a24
<?php
/*
* $Id: UnitOfWork.php 1495 2007-05-27 18:56:04Z zYne $
*
* 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.phpdoctrine.com>.
*/
Doctrine
::
autoload
(
'Doctrine_Connection_Module'
);
/**
* Doctrine_Connection_UnitOfWork
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision: 1495 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class
Doctrine_IntegrityMapper
{
public
function
processDeleteIntegrity
(
Doctrine_Record
$record
)
{
$coll
=
$this
->
buildIntegrityRelationQuery
(
$record
);
$this
->
invokeIntegrityActions
(
$record
);
}
public
function
invokeIntegrityActions
(
Doctrine_Record
$record
)
{
$deleteActions
=
Doctrine_Manager
::
getInstance
()
->
getDeleteActions
(
$record
->
getTable
()
->
getComponentName
());
foreach
(
$record
->
getTable
()
->
getRelations
()
as
$relation
)
{
$componentName
=
$relation
->
getTable
()
->
getComponentName
();
foreach
(
$record
->
get
(
$relation
->
getAlias
())
as
$coll
)
{
if
(
!
(
$coll
instanceof
Doctrine_Collection
))
{
$coll
=
array
(
$coll
);
}
foreach
(
$coll
as
$record
)
{
$this
->
invokeIntegrityActions
(
$record
);
if
(
isset
(
$deleteActions
[
$componentName
]))
{
if
(
$deleteActions
[
$componentName
]
===
'SET NULL'
)
{
$record
->
set
(
$relation
->
getForeign
(),
null
);
}
elseif
(
$deleteActions
[
$componentName
]
===
'CASCADE'
)
{
$this
->
conn
->
transaction
->
addDelete
(
$record
);
}
}
}
}
}
}
public
function
buildIntegrityRelationQuery
(
Doctrine_Record
$record
)
{
$q
=
new
Doctrine_Query
();
$aliases
=
array
();
$indexes
=
array
();
$root
=
$record
->
getTable
()
->
getComponentName
();
$rootAlias
=
strtolower
(
substr
(
$root
,
0
,
1
));
$aliases
[
$rootAlias
]
=
$root
;
foreach
((
array
)
$record
->
getTable
()
->
getIdentifier
()
as
$id
)
{
$field
=
$rootAlias
.
'.'
.
$id
;
$cond
[]
=
$field
.
' = ?'
;
$fields
[]
=
$field
;
$params
=
$record
->
get
(
$id
);
}
$fields
=
implode
(
', '
,
$fields
);
$components
[]
=
$root
;
$this
->
buildIntegrityRelations
(
$record
->
getTable
(),
$aliases
,
$fields
,
$indexes
,
$components
);
$q
->
select
(
$fields
)
->
from
(
$root
.
' '
.
$rootAlias
);
foreach
(
$aliases
as
$alias
=>
$name
)
{
$q
->
leftJoin
(
$rootAlias
.
'.'
.
$name
.
' '
.
$alias
);
}
$q
->
where
(
implode
(
' AND '
,
$cond
));
return
$q
->
execute
(
array
(
$params
));
}
public
function
buildIntegrityRelations
(
Doctrine_Table
$table
,
&
$aliases
,
&
$fields
,
&
$indexes
,
&
$components
)
{
$deleteActions
=
Doctrine_Manager
::
getInstance
()
->
getDeleteActions
(
$table
->
getComponentName
());
foreach
(
$table
->
getRelations
()
as
$relation
)
{
$componentName
=
$relation
->
getTable
()
->
getComponentName
();
if
(
in_array
(
$componentName
,
$components
))
{
continue
;
}
$components
[]
=
$componentName
;
$alias
=
strtolower
(
substr
(
$relation
->
getAlias
(),
0
,
1
));
if
(
!
isset
(
$indexes
[
$alias
]))
{
$indexes
[
$alias
]
=
1
;
}
if
(
isset
(
$deleteActions
[
$componentName
]))
{
if
(
isset
(
$aliases
[
$alias
]))
{
$alias
=
$alias
.
++
$indexes
[
$alias
];
}
$aliases
[
$alias
]
=
$relation
->
getAlias
();
if
(
$deleteActions
[
$componentName
]
===
'SET NULL'
)
{
if
(
$relation
instanceof
Doctrine_Relation_ForeignKey
)
{
foreach
((
array
)
$relation
->
getForeign
()
as
$foreign
)
{
$fields
.=
', '
.
$alias
.
'.'
.
$foreign
;
}
}
elseif
(
$relation
instanceof
Doctrine_Relation_LocalKey
)
{
foreach
((
array
)
$relation
->
getLocal
()
as
$foreign
)
{
$fields
.=
', '
.
$alias
.
'.'
.
$foreign
;
}
}
}
foreach
((
array
)
$relation
->
getTable
()
->
getIdentifier
()
as
$id
)
{
$fields
.=
', '
.
$alias
.
'.'
.
$id
;
}
if
(
$deleteActions
[
$componentName
]
===
'CASCADE'
)
{
$this
->
buildIntegrityRelations
(
$relation
->
getTable
(),
$aliases
,
$fields
,
$indexes
,
$components
);
}
}
}
}
}
lib/Doctrine/Manager.php
View file @
d6095a24
...
...
@@ -65,6 +65,9 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
'oci'
=>
'oci8'
,
'sqlite2'
=>
'sqlite'
,
'sqlite3'
=>
'sqlite'
);
protected
$_integrityActionsMap
=
array
();
/**
* constructor
*
...
...
@@ -79,6 +82,30 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
Doctrine_Validator
::
initNullObject
(
$this
->
_null
);
Doctrine_Object
::
initNullObject
(
$this
->
_null
);
}
public
function
addDeleteAction
(
$componentName
,
$foreignComponent
,
$action
)
{
$this
->
_integrityActions
[
$componentName
][
'onDelete'
][
$foreignComponent
]
=
$action
;
}
public
function
addUpdateAction
(
$componentName
,
$foreignComponent
,
$action
)
{
$this
->
_integrityActions
[
$componentName
][
'onUpdate'
][
$foreignComponent
]
=
$action
;
}
public
function
getDeleteActions
(
$componentName
)
{
if
(
!
isset
(
$this
->
_integrityActions
[
$componentName
][
'onDelete'
]))
{
return
null
;
}
return
$this
->
_integrityActions
[
$componentName
][
'onDelete'
];
}
public
function
getUpdateActions
(
$componentName
)
{
if
(
!
isset
(
$this
->
_integrityActions
[
$componentName
][
'onUpdate'
]))
{
return
null
;
}
return
$this
->
_integrityActions
[
$componentName
][
'onUpdate'
];
}
/**
* @return Doctrine_Null
*/
...
...
lib/Doctrine/Relation/Parser.php
View file @
d6095a24
...
...
@@ -102,7 +102,16 @@ class Doctrine_Relation_Parser
}
$this
->
_pending
[
$alias
]
=
array_merge
(
$options
,
array
(
'class'
=>
$name
,
'alias'
=>
$alias
));
$m
=
Doctrine_Manager
::
getInstance
();
if
(
isset
(
$options
[
'onDelete'
]))
{
$m
->
addDeleteAction
(
$name
,
$this
->
_table
->
getComponentName
(),
$options
[
'onDelete'
]);
}
if
(
isset
(
$options
[
'onUpdate'
]))
{
$m
->
addUpdateAction
(
$name
,
$this
->
_table
->
getComponentName
(),
$options
[
'onUpdate'
]);
}
return
$this
->
_pending
[
$alias
];
}
/**
...
...
@@ -126,7 +135,7 @@ class Doctrine_Relation_Parser
$localClasses
=
array_merge
(
$this
->
_table
->
getOption
(
'parents'
),
array
(
$this
->
_table
->
getComponentName
()));
if
(
!
isset
(
$this
->
_pending
[
$def
[
'refClass'
]])
&&
!
isset
(
$this
->
_relations
[
$def
[
'refClass'
]]))
{
!
isset
(
$this
->
_relations
[
$def
[
'refClass'
]]))
{
$def
[
'refTable'
]
->
getRelationParser
()
->
bind
(
$this
->
_table
->
getComponentName
(),
array
(
'type'
=>
Doctrine_Relation
::
ONE
,
...
...
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