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
ab0c7b11
Commit
ab0c7b11
authored
Nov 11, 2009
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0][DDC-136] Some fixes to internal UnitOfWork logic.
parent
57a97eba
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
8 deletions
+54
-8
UnitOfWork.php
lib/Doctrine/ORM/UnitOfWork.php
+19
-8
BasicFunctionalTest.php
tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php
+3
-0
IdentityMapTest.php
tests/Doctrine/Tests/ORM/Functional/IdentityMapTest.php
+32
-0
No files found.
lib/Doctrine/ORM/UnitOfWork.php
View file @
ab0c7b11
...
...
@@ -771,7 +771,14 @@ class UnitOfWork implements PropertyChangedListener
foreach
(
$this
->
_entityDeletions
as
$oid
=>
$entity
)
{
if
(
get_class
(
$entity
)
==
$className
)
{
$persister
->
delete
(
$entity
);
unset
(
$this
->
_entityDeletions
[
$oid
]);
unset
(
$this
->
_entityDeletions
[
$oid
],
$this
->
_entityIdentifiers
[
$oid
],
$this
->
_originalEntityData
[
$oid
]
);
// Entity with this $oid after deletion treated as NEW, even if the $oid
// is obtained by a new entity because the old one went out of scope.
$this
->
_entityStates
[
$oid
]
=
self
::
STATE_NEW
;
if
(
$hasLifecycleCallbacks
)
{
$class
->
invokeLifecycleCallbacks
(
Events
::
postRemove
,
$entity
);
...
...
@@ -919,17 +926,21 @@ class UnitOfWork implements PropertyChangedListener
public
function
scheduleForDelete
(
$entity
)
{
$oid
=
spl_object_hash
(
$entity
);
if
(
!
$this
->
isInIdentityMap
(
$entity
))
{
return
;
}
$this
->
removeFromIdentityMap
(
$entity
);
if
(
isset
(
$this
->
_entityInsertions
[
$oid
]))
{
if
(
$this
->
isInIdentityMap
(
$entity
))
{
$this
->
removeFromIdentityMap
(
$entity
);
}
unset
(
$this
->
_entityInsertions
[
$oid
]);
return
;
// entity has not been persisted yet, so nothing more to do.
}
if
(
!
$this
->
isInIdentityMap
(
$entity
))
{
return
;
// ignore
}
$this
->
removeFromIdentityMap
(
$entity
);
if
(
isset
(
$this
->
_entityUpdates
[
$oid
]))
{
unset
(
$this
->
_entityUpdates
[
$oid
]);
}
...
...
tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php
View file @
ab0c7b11
...
...
@@ -66,6 +66,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this
->
assertFalse
(
$this
->
_em
->
getUnitOfWork
()
->
isScheduledForDelete
(
$user
));
$this
->
assertFalse
(
$this
->
_em
->
getUnitOfWork
()
->
isScheduledForDelete
(
$ph
));
$this
->
assertFalse
(
$this
->
_em
->
getUnitOfWork
()
->
isScheduledForDelete
(
$ph2
));
$this
->
assertEquals
(
\Doctrine\ORM\UnitOfWork
::
STATE_NEW
,
$this
->
_em
->
getUnitOfWork
()
->
getEntityState
(
$user
));
$this
->
assertEquals
(
\Doctrine\ORM\UnitOfWork
::
STATE_NEW
,
$this
->
_em
->
getUnitOfWork
()
->
getEntityState
(
$ph
));
$this
->
assertEquals
(
\Doctrine\ORM\UnitOfWork
::
STATE_NEW
,
$this
->
_em
->
getUnitOfWork
()
->
getEntityState
(
$ph2
));
}
public
function
testOneToManyAssociationModification
()
...
...
tests/Doctrine/Tests/ORM/Functional/IdentityMapTest.php
View file @
ab0c7b11
...
...
@@ -252,5 +252,37 @@ class IdentityMapTest extends \Doctrine\Tests\OrmFunctionalTestCase
// Now the collection should be refreshed with correct count
$this
->
assertEquals
(
4
,
count
(
$user2
->
getPhonenumbers
()));
}
public
function
testReusedSplObjectHashDoesNotConfuseUnitOfWork
()
{
$hash1
=
$this
->
subRoutine
(
$this
->
_em
);
// Make sure cycles are collected NOW, because a PersistentCollection references
// its owner, hence without forcing gc on cycles now the object will not (yet)
// be garbage collected and thus the object hash is not reused.
// This is not a memory leak!
gc_collect_cycles
();
$user1
=
new
CmsUser
;
$user1
->
status
=
'dev'
;
$user1
->
username
=
'jwage'
;
$user1
->
name
=
'Jonathan W.'
;
$hash2
=
spl_object_hash
(
$user1
);
$this
->
assertEquals
(
$hash1
,
$hash2
);
// Hash reused!
$this
->
_em
->
persist
(
$user1
);
$this
->
_em
->
flush
();
}
private
function
subRoutine
(
$em
)
{
$user
=
new
CmsUser
;
$user
->
status
=
'dev'
;
$user
->
username
=
'romanb'
;
$user
->
name
=
'Roman B.'
;
$em
->
persist
(
$user
);
$em
->
flush
();
$em
->
remove
(
$user
);
$em
->
flush
();
return
spl_object_hash
(
$user
);
}
}
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