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
4df1a9d1
Commit
4df1a9d1
authored
Jul 10, 2006
by
doctrine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Record refactoring + new method Doctrine_Manager::install
parent
bb1a3968
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
67 deletions
+98
-67
Manager.php
Doctrine/Manager.php
+17
-0
Record.php
Doctrine/Record.php
+7
-67
Relation.php
Doctrine/Relation.php
+74
-0
No files found.
Doctrine/Manager.php
View file @
4df1a9d1
...
@@ -105,7 +105,24 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
...
@@ -105,7 +105,24 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
return
$instance
;
return
$instance
;
}
}
/**
* install
*
* @return void
*/
final
public
function
install
()
{
$parent
=
new
ReflectionClass
(
'Doctrine_Record'
);
$old
=
$this
->
getAttribute
(
Doctrine
::
ATTR_CREATE_TABLES
);
$this
->
attributes
[
Doctrine
::
ATTR_CREATE_TABLES
]
=
true
;
foreach
(
get_declared_classes
()
as
$name
)
{
$class
=
new
ReflectionClass
(
$name
);
if
(
$class
->
isSubclassOf
(
$parent
))
$obj
=
new
$class
();
}
$this
->
attributes
[
Doctrine
::
ATTR_CREATE_TABLES
]
=
$old
;
}
/**
/**
* openSession
* openSession
* opens a new session and saves it to Doctrine_Manager->sessions
* opens a new session and saves it to Doctrine_Manager->sessions
...
...
Doctrine/Record.php
View file @
4df1a9d1
...
@@ -812,14 +812,16 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -812,14 +812,16 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this
->
loadReference
(
$alias
);
$this
->
loadReference
(
$alias
);
}
}
$r
=
$this
->
getRelationOperations
(
$alias
,
$new
);
$r
=
Doctrine_Relation
::
getDeleteOperations
(
$this
->
originals
[
$alias
]
,
$new
);
foreach
(
$r
[
"delete"
]
as
$record
)
{
foreach
(
$r
as
$record
)
{
$query
=
"DELETE FROM "
.
$asf
->
getTableName
()
.
" WHERE "
.
$fk
->
getForeign
()
.
" = ?"
$query
=
"DELETE FROM "
.
$asf
->
getTableName
()
.
" WHERE "
.
$fk
->
getForeign
()
.
" = ?"
.
" AND "
.
$fk
->
getLocal
()
.
" = ?"
;
.
" AND "
.
$fk
->
getLocal
()
.
" = ?"
;
$this
->
table
->
getSession
()
->
execute
(
$query
,
array
(
$record
->
getIncremented
(),
$this
->
getIncremented
()));
$this
->
table
->
getSession
()
->
execute
(
$query
,
array
(
$record
->
getIncremented
(),
$this
->
getIncremented
()));
}
}
foreach
(
$r
[
"add"
]
as
$record
)
{
$r
=
Doctrine_Relation
::
getInsertOperations
(
$this
->
originals
[
$alias
],
$new
);
foreach
(
$r
as
$record
)
{
$reldao
=
$asf
->
create
();
$reldao
=
$asf
->
create
();
$reldao
->
set
(
$fk
->
getForeign
(),
$record
);
$reldao
->
set
(
$fk
->
getForeign
(),
$record
);
$reldao
->
set
(
$fk
->
getLocal
(),
$this
);
$reldao
->
set
(
$fk
->
getLocal
(),
$this
);
...
@@ -846,9 +848,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -846,9 +848,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
if
(
!
isset
(
$this
->
originals
[
$alias
]))
if
(
!
isset
(
$this
->
originals
[
$alias
]))
$this
->
loadReference
(
$alias
);
$this
->
loadReference
(
$alias
);
$r
=
$this
->
getRelationOperations
(
$alias
,
$new
);
$r
=
Doctrine_Relation
::
getDeleteOperations
(
$this
->
originals
[
$alias
],
$new
);
foreach
(
$r
[
"delete"
]
as
$record
)
{
foreach
(
$r
as
$record
)
{
$record
->
delete
();
$record
->
delete
();
}
}
...
@@ -859,68 +861,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -859,68 +861,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
}
}
endforeach
;
endforeach
;
}
}
/**
* get the records that need to be added
* and/or 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)
*
* First we iterate through the new collection and get the
* records that do not exist in the old collection (Doctrine_Records that need to be added).
*
* Then 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).
*/
final
public
function
getRelationOperations
(
$name
,
Doctrine_Collection
$new
)
{
$r
[
"add"
]
=
array
();
$r
[
"delete"
]
=
array
();
foreach
(
$new
as
$k
=>
$record
)
{
$found
=
false
;
$id
=
$record
->
getIncremented
();
if
(
!
empty
(
$id
))
{
foreach
(
$this
->
originals
[
$name
]
as
$k2
=>
$record2
)
{
if
(
$record2
->
getIncremented
()
===
$record
->
getIncremented
())
{
$found
=
true
;
break
;
}
}
}
if
(
!
$found
)
{
$this
->
originals
[
$name
][]
=
$record
;
$r
[
"add"
][]
=
$record
;
}
}
foreach
(
$this
->
originals
[
$name
]
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
[
"delete"
][]
=
$record
;
unset
(
$this
->
originals
[
$name
][
$k
]);
}
}
return
$r
;
}
/**
/**
* getOriginals
* getOriginals
*/
*/
...
...
Doctrine/Relation.php
View file @
4df1a9d1
...
@@ -95,6 +95,80 @@ class Doctrine_Relation {
...
@@ -95,6 +95,80 @@ class Doctrine_Relation {
public
function
getForeign
()
{
public
function
getForeign
()
{
return
$this
->
foreign
;
return
$this
->
foreign
;
}
}
/**
* 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).
*/
final
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).
*/
final
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
;
}
/**
/**
* __toString
* __toString
*/
*/
...
...
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