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
e53a659c
Commit
e53a659c
authored
Nov 10, 2007
by
Jonathan.Wage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merged r3132:3133 fixed #591
parent
46f22770
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
45 deletions
+69
-45
Import.php
lib/Doctrine/Data/Import.php
+69
-45
No files found.
lib/Doctrine/Data/Import.php
View file @
e53a659c
...
...
@@ -32,8 +32,9 @@
*/
class
Doctrine_Data_Import
extends
Doctrine_Data
{
private
$_importedObjects
=
array
();
protected
$_importedObjects
=
array
();
protected
$_rows
=
array
();
/**
* constructor
*
...
...
@@ -85,10 +86,9 @@ class Doctrine_Data_Import extends Doctrine_Data
protected
function
_buildRows
(
$className
,
$data
)
{
$rows
=
array
();
foreach
(
$data
as
$rowKey
=>
$row
)
{
// do the same for the row information
$rows
[
$className
][
$rowKey
]
=
$row
;
$
this
->
_
rows
[
$className
][
$rowKey
]
=
$row
;
foreach
(
$row
as
$key
=>
$value
)
{
if
(
Doctrine
::
getTable
(
$className
)
->
hasRelation
(
$key
)
&&
is_array
(
$value
))
{
...
...
@@ -96,14 +96,54 @@ class Doctrine_Data_Import extends Doctrine_Data
// Skip associative arrays defining keys to relationships
if
(
!
isset
(
$keys
[
0
]))
{
$
rows
=
array_merge
(
$rows
,
$this
->
_buildRows
(
Doctrine
::
getTable
(
$className
)
->
getRelation
(
$key
)
->
getTable
()
->
getOption
(
'name'
),
$value
)
);
$
this
->
_buildRows
(
Doctrine
::
getTable
(
$className
)
->
getRelation
(
$key
)
->
getTable
()
->
getOption
(
'name'
),
$value
);
}
}
}
}
}
protected
function
_buildNestedSetRows
(
$className
,
$data
)
{
foreach
(
$data
as
$rowKey
=>
$row
)
{
$children
=
isset
(
$row
[
'children'
])
?
$row
[
'children'
]
:
array
();
unset
(
$row
[
'children'
]);
$this
->
_rows
[
$className
][
$rowKey
]
=
$row
;
$this
->
_buildNestedSetRows
(
$className
,
$children
);
}
}
protected
function
_processRow
(
$rowKey
,
$row
)
{
$obj
=
$this
->
_importedObjects
[
$rowKey
];
return
$rows
;
foreach
(
$row
as
$key
=>
$value
)
{
if
(
$obj
->
getTable
()
->
hasColumn
(
$key
))
{
$obj
->
set
(
$key
,
$value
);
}
else
if
(
$obj
->
getTable
()
->
hasRelation
(
$key
))
{
if
(
is_array
(
$value
))
{
if
(
isset
(
$value
[
0
]))
{
foreach
(
$value
as
$link
)
{
if
(
$obj
->
getTable
()
->
getRelation
(
$key
)
->
getType
()
===
Doctrine_Relation
::
ONE
)
{
$obj
->
set
(
$key
,
$this
->
_importedObjects
[
$link
]);
}
else
if
(
$obj
->
getTable
()
->
getRelation
(
$key
)
->
getType
()
===
Doctrine_Relation
::
MANY
)
{
$relation
=
$obj
->
$key
;
$relation
[]
=
$this
->
_importedObjects
[
$link
];
}
}
}
else
{
$obj
->
$key
->
fromArray
(
$value
);
}
}
else
if
(
isset
(
$this
->
_importedObjects
[
$value
]))
{
$obj
->
set
(
$key
,
$this
->
_importedObjects
[
$value
]);
}
}
}
}
/**
* loadData
*
...
...
@@ -112,6 +152,8 @@ class Doctrine_Data_Import extends Doctrine_Data
*/
protected
function
_loadData
(
array
$array
)
{
$nestedSets
=
array
();
$specifiedModels
=
$this
->
getModels
();
$rows
=
array
();
...
...
@@ -123,51 +165,27 @@ class Doctrine_Data_Import extends Doctrine_Data
// This is simple here to get the templates present for this model
// better way?
$obj
=
new
$className
();
$obj
=
new
$className
(
null
,
true
);
$templates
=
array_keys
(
$obj
->
getTable
()
->
getTemplates
());
if
(
in_array
(
'Doctrine_Template_NestedSet'
,
$templates
))
{
$this
->
_loadNestedSetData
(
$className
,
$data
);
$nestedSets
[
$className
][]
=
$data
;
$this
->
_buildNestedSetRows
(
$className
,
$data
);
}
else
{
$
rows
=
array_merge
(
$rows
,
$this
->
_buildRows
(
$className
,
$data
)
);
$
this
->
_buildRows
(
$className
,
$data
);
}
}
$buildRows
=
array
();
foreach
(
$rows
as
$className
=>
$classRows
)
{
foreach
(
$
this
->
_
rows
as
$className
=>
$classRows
)
{
foreach
(
$classRows
as
$rowKey
=>
$row
)
{
$buildRows
[
$rowKey
]
=
$row
;
$this
->
_importedObjects
[
$rowKey
]
=
new
$className
();
}
}
foreach
(
$buildRows
as
$rowKey
=>
$row
)
{
$obj
=
$this
->
_importedObjects
[
$rowKey
];
foreach
(
$row
as
$key
=>
$value
)
{
if
(
$obj
->
getTable
()
->
hasColumn
(
$key
))
{
$obj
->
set
(
$key
,
$value
);
}
else
if
(
$obj
->
getTable
()
->
hasRelation
(
$key
))
{
if
(
is_array
(
$value
))
{
if
(
isset
(
$value
[
0
]))
{
foreach
(
$value
as
$link
)
{
if
(
$obj
->
getTable
()
->
getRelation
(
$key
)
->
getType
()
===
Doctrine_Relation
::
ONE
)
{
$obj
->
set
(
$key
,
$this
->
_importedObjects
[
$link
]);
}
else
if
(
$obj
->
getTable
()
->
getRelation
(
$key
)
->
getType
()
===
Doctrine_Relation
::
MANY
)
{
$relation
=
$obj
->
$key
;
$relation
[]
=
$this
->
_importedObjects
[
$link
];
}
}
}
else
{
$obj
->
$key
->
fromArray
(
$value
);
}
}
else
if
(
isset
(
$this
->
_importedObjects
[
$value
]))
{
$obj
->
set
(
$key
,
$this
->
_importedObjects
[
$value
]);
}
}
}
$this
->
_processRow
(
$rowKey
,
$row
);
}
$manager
=
Doctrine_Manager
::
getInstance
();
...
...
@@ -180,11 +198,19 @@ class Doctrine_Data_Import extends Doctrine_Data
$tree
=
$connection
->
unitOfWork
->
buildFlushTree
(
$objects
);
foreach
(
$tree
as
$model
)
{
foreach
(
$this
->
_importedObjects
as
$obj
)
{
if
(
$obj
instanceof
$model
)
{
$obj
->
save
();
foreach
(
$this
->
_importedObjects
as
$obj
)
{
$templates
=
array_keys
(
$obj
->
getTable
()
->
getTemplates
());
if
(
$obj
instanceof
$model
&&
!
in_array
(
'Doctrine_Template_NestedSet'
,
$templates
))
{
$obj
->
save
();
}
}
}
}
}
foreach
(
$nestedSets
as
$className
=>
$sets
)
{
foreach
(
$sets
as
$data
)
{
$this
->
_loadNestedSetData
(
$className
,
$data
);
}
}
}
...
...
@@ -204,13 +230,11 @@ class Doctrine_Data_Import extends Doctrine_Data
unset
(
$nestedSet
[
'children'
]);
}
$record
=
new
$model
();
$this
->
_importedObjects
[
$rowKey
]
=
$record
;
$record
=
$this
->
_importedObjects
[
$rowKey
];
if
(
is_array
(
$nestedSet
)
AND
!
empty
(
$nestedSet
)
)
{
$
record
->
fromArray
(
$nestedSet
);
$
this
->
_processRow
(
$rowKey
,
$nestedSet
);
}
if
(
!
$parent
)
...
...
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