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
82ba74e2
Commit
82ba74e2
authored
May 16, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
330bf1d4
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
13 additions
and
184 deletions
+13
-184
Collection.php
lib/Doctrine/Collection.php
+7
-9
UnitOfWork.php
lib/Doctrine/Connection/UnitOfWork.php
+3
-6
Hydrate.php
lib/Doctrine/Hydrate.php
+3
-3
Record.php
lib/Doctrine/Record.php
+0
-62
Relation.php
lib/Doctrine/Relation.php
+0
-84
LocalKey.php
lib/Doctrine/Relation/LocalKey.php
+0
-20
No files found.
lib/Doctrine/Collection.php
View file @
82ba74e2
...
...
@@ -549,26 +549,22 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* Snapshot with the objects 1, 2 and 4
* Current data with objects 2, 3 and 5
*
* The process would:
* 1. remove object 4
* 2. add objects 3 and 5
* The process would remove object 4
*
* @return Doctrine_Collection
*/
public
function
processDiff
()
{
foreach
(
array_diff
(
$this
->
snapshot
,
$this
->
data
)
as
$record
)
{
foreach
(
array_diff
(
$this
->
_snapshot
,
$this
->
data
)
as
$record
)
{
$record
->
delete
();
}
foreach
(
array_diff
(
$this
->
data
,
$this
->
snapshot
)
as
$record
)
{
$record
->
save
();
}
return
$this
;
}
/**
* save
* saves all records of this collection
* saves all records of this collection and processes the
* difference of the last snapshot and the current data
*
* @return Doctrine_Collection
*/
...
...
@@ -579,6 +575,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
}
$conn
->
beginTransaction
();
$this
->
processDiff
();
foreach
(
$this
as
$key
=>
$record
)
{
$record
->
save
(
$conn
);
}
...
...
lib/Doctrine/Connection/UnitOfWork.php
View file @
82ba74e2
...
...
@@ -140,10 +140,10 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
public
function
saveRelated
(
Doctrine_Record
$record
)
{
$saveLater
=
array
();
foreach
(
$record
->
getReferences
()
as
$k
=>
$v
)
{
foreach
(
$record
->
getReferences
()
as
$k
=>
$v
)
{
$fk
=
$record
->
getTable
()
->
getRelation
(
$k
);
if
(
$fk
instanceof
Doctrine_Relation_ForeignKey
||
$fk
instanceof
Doctrine_Relation_LocalKey
)
{
$fk
instanceof
Doctrine_Relation_LocalKey
)
{
$local
=
$fk
->
getLocal
();
$foreign
=
$fk
->
getForeign
();
...
...
@@ -157,8 +157,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
// ONE-TO-ONE relationship
$obj
=
$record
->
get
(
$fk
->
getAlias
());
$state
=
$obj
->
state
();
if
(
!
(
$state
==
Doctrine_Record
::
STATE_CLEAN
||
$state
==
Doctrine_Record
::
STATE_TCLEAN
)
)
{
if
(
$obj
->
exists
())
{
$obj
->
save
(
$this
->
conn
);
}
}
...
...
@@ -189,8 +188,6 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
foreach
(
$record
->
getTable
()
->
getRelations
()
as
$rel
)
{
$table
=
$rel
->
getTable
();
$alias
=
$rel
->
getAlias
();
$rel
->
processDiff
(
$record
,
$this
->
conn
);
}
}
/**
...
...
lib/Doctrine/Hydrate.php
View file @
82ba74e2
...
...
@@ -447,7 +447,7 @@ class Doctrine_Hydrate
if
(
$alias
==
$rootAlias
)
{
// add record into root collection
if
(
$identifiable
)
{
$coll
->
add
(
$record
);
unset
(
$prevRow
);
...
...
@@ -499,8 +499,8 @@ class Doctrine_Hydrate
}
}
// take snapshots from all initialized collections
foreach
(
array_unique
(
$colls
)
as
$c
oll
)
{
$c
oll
->
takeSnapshot
();
foreach
(
array_unique
(
$colls
)
as
$c
)
{
$c
->
takeSnapshot
();
}
return
$coll
;
...
...
lib/Doctrine/Record.php
View file @
82ba74e2
...
...
@@ -111,10 +111,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @var array $references an array containing all the references
*/
private
$references
=
array
();
/**
* @var array $originals an array containing all the original references
*/
private
$originals
=
array
();
/**
* @var integer $index this index is used for creating object identifiers
*/
...
...
@@ -1175,19 +1171,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
{
return
new
Doctrine_Record_Iterator
(
$this
);
}
/**
* getOriginals
* returns an original collection of related component
*
* @return Doctrine_Collection|false
*/
public
function
obtainOriginals
(
$name
)
{
if
(
isset
(
$this
->
originals
[
$name
]))
{
return
$this
->
originals
[
$name
];
}
return
false
;
}
/**
* deletes this data access object and all the related composites
* this operation is isolated by a transaction
...
...
@@ -1266,17 +1249,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this
->
_modified
=
array
();
}
}
/**
* assignOriginals
*
* @param string $alias
* @param Doctrine_Collection $coll
* @return void
*/
public
function
assignOriginals
(
$alias
,
Doctrine_Collection
$coll
)
{
$this
->
originals
[
$alias
]
=
$coll
;
}
/**
* returns the primary keys of this object
*
...
...
@@ -1332,36 +1304,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
return
$this
->
references
[
$name
];
}
throw
new
Doctrine_Record_Exception
(
"Unknown reference
$name
"
);
}
/**
* initalizes a one-to-many / many-to-many relation
*
* @param Doctrine_Collection $coll
* @param Doctrine_Relation $connector
* @return boolean
*/
public
function
initReference
(
$coll
,
Doctrine_Relation
$connector
)
{
$alias
=
$connector
->
getAlias
();
if
(
isset
(
$this
->
references
[
$alias
]))
{
return
false
;
}
if
(
!
$connector
->
isOneToOne
())
{
if
(
!
(
$connector
instanceof
Doctrine_Relation_Association
))
{
$coll
->
setReference
(
$this
,
$connector
);
}
$this
->
references
[
$alias
]
=
$coll
;
$this
->
originals
[
$alias
]
=
clone
$coll
;
return
true
;
}
return
false
;
}
public
function
lazyInitRelated
(
Doctrine_Collection
$coll
,
Doctrine_Relation
$connector
)
{
}
/**
* addReference
...
...
@@ -1374,7 +1316,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$alias
=
$connector
->
getAlias
();
$this
->
references
[
$alias
]
->
add
(
$record
,
$key
);
$this
->
originals
[
$alias
]
->
add
(
$record
,
$key
);
}
/**
* getReferences
...
...
@@ -1393,7 +1334,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
final
public
function
setRelated
(
$alias
,
Doctrine_Access
$coll
)
{
$this
->
references
[
$alias
]
=
$coll
;
$this
->
originals
[
$alias
]
=
$coll
;
}
/**
* loadReference
...
...
@@ -1410,12 +1350,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
if
(
$fk
->
isOneToOne
())
{
$this
->
references
[
$name
]
=
$fk
->
fetchRelatedFor
(
$this
);
}
else
{
$coll
=
$fk
->
fetchRelatedFor
(
$this
);
$this
->
references
[
$name
]
=
$coll
;
$this
->
originals
[
$name
]
=
clone
$coll
;
}
}
/**
...
...
lib/Doctrine/Relation.php
View file @
82ba74e2
...
...
@@ -239,90 +239,6 @@ abstract class Doctrine_Relation
return
$dql
;
}
/**
* getDeleteOperations
*
* get the records that need to be deleted in order to change the old collection
* to the new one
*
* The algorithm here is very simple and definitely not
* the fastest one, since we have to iterate through the collections twice.
* the complexity of this algorithm is O(n^2)
*
* We iterate through the old collection and get the records
* that do not exists in the new collection (Doctrine_Records that need to be deleted).
*
* @param Doctrine_Collection $old
* @param Doctrine_Collection $new
* @return array
*/
public
static
function
getDeleteOperations
(
Doctrine_Collection
$old
,
Doctrine_Collection
$new
)
{
$r
=
array
();
foreach
(
$old
as
$k
=>
$record
)
{
$id
=
$record
->
getIncremented
();
if
(
empty
(
$id
))
{
continue
;
}
$found
=
false
;
foreach
(
$new
as
$k2
=>
$record2
)
{
if
(
$record2
->
getIncremented
()
===
$record
->
getIncremented
())
{
$found
=
true
;
break
;
}
}
if
(
!
$found
)
{
$r
[]
=
$record
;
unset
(
$old
[
$k
]);
}
}
return
$r
;
}
/**
* getInsertOperations
*
* get the records that need to be added in order to change the old collection
* to the new one
*
* The algorithm here is very simple and definitely not
* the fastest one, since we have to iterate through the collections twice.
* the complexity of this algorithm is O(n^2)
*
* We iterate through the old collection and get the records
* that exists only in the new collection (Doctrine_Records that need to be added).
*
* @param Doctrine_Collection $old
* @param Doctrine_Collection $new
* @return array
*/
public
static
function
getInsertOperations
(
Doctrine_Collection
$old
,
Doctrine_Collection
$new
)
{
$r
=
array
();
foreach
(
$new
as
$k
=>
$record
)
{
$found
=
false
;
$id
=
$record
->
getIncremented
();
if
(
!
empty
(
$id
))
{
foreach
(
$old
as
$k2
=>
$record2
)
{
if
(
$record2
->
getIncremented
()
===
$record
->
getIncremented
())
{
$found
=
true
;
break
;
}
}
}
if
(
!
$found
)
{
$old
[]
=
$record
;
$r
[]
=
$record
;
}
}
return
$r
;
}
/**
* fetchRelatedFor
*
...
...
lib/Doctrine/Relation/LocalKey.php
View file @
82ba74e2
...
...
@@ -33,26 +33,6 @@ Doctrine::autoload('Doctrine_Relation');
*/
class
Doctrine_Relation_LocalKey
extends
Doctrine_Relation
{
/**
* processDiff
*
* @param Doctrine_Record $record
* @param Doctrine_Connection $conn
*/
public
function
processDiff
(
Doctrine_Record
$record
,
$conn
=
null
)
{
if
(
!
$conn
)
{
$conn
=
$this
->
getTable
()
->
getConnection
();
}
$alias
=
$this
->
getAlias
();
if
(
$record
->
obtainOriginals
(
$alias
)
&&
$record
->
obtainOriginals
(
$alias
)
->
obtainIdentifier
()
!=
$this
->
references
[
$alias
]
->
obtainIdentifier
()
)
{
$record
->
obtainOriginals
(
$alias
)
->
delete
(
$conn
);
}
}
/**
* fetchRelatedFor
*
...
...
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