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
94bf9a4c
Commit
94bf9a4c
authored
Oct 08, 2007
by
Jonathan.Wage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix for importing.
parent
8c413b24
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
20 deletions
+37
-20
Export.php
lib/Doctrine/Data/Export.php
+12
-12
Builder.php
lib/Doctrine/Import/Builder.php
+21
-4
index.php
playground/index.php
+4
-4
No files found.
lib/Doctrine/Data/Export.php
View file @
94bf9a4c
...
...
@@ -140,6 +140,17 @@ class Doctrine_Data_Export extends Doctrine_Data
continue
;
}
// skip single primary keys, we need to maintain composite primary keys
$keys
=
$record
->
getTable
()
->
getIdentifier
();
if
(
!
is_array
(
$keys
))
{
$keys
=
array
(
$keys
);
}
if
(
count
(
$keys
)
<=
1
&&
in_array
(
$key
,
$keys
))
{
continue
;
}
if
(
$relation
=
$this
->
isRelation
(
$record
,
$key
))
{
$relationAlias
=
$relation
[
'alias'
];
$relationRecord
=
$record
->
$relationAlias
;
...
...
@@ -160,18 +171,7 @@ class Doctrine_Data_Export extends Doctrine_Data
$relationValue
=
$relationClassName
.
'_'
.
$value
;
$preparedData
[
$className
][
$recordKey
][
$relationClassName
]
=
$relationValue
;
}
else
{
// skip single primary keys, we need to maintain composite primary keys
$keys
=
$record
->
getTable
()
->
getIdentifier
();
if
(
!
is_array
(
$keys
))
{
$keys
=
array
(
$keys
);
}
if
(
count
(
$keys
)
<=
1
&&
in_array
(
$key
,
$keys
))
{
continue
;
}
}
else
{
$preparedData
[
$className
][
$recordKey
][
$key
]
=
$value
;
}
}
...
...
lib/Doctrine/Import/Builder.php
View file @
94bf9a4c
...
...
@@ -193,7 +193,7 @@ END;
}
if
(
!
empty
(
$ret
))
{
return
"
\n\t
\t
public function setTableDefinition()"
.
"
\n\t\t
{\n"
.
implode
(
"
\n
"
,
$ret
)
.
"
\n\t
\t
}"
;
return
"
\n\t
public function setTableDefinition()"
.
"
\n\t
{\n"
.
implode
(
"
\n
"
,
$ret
)
.
"
\n
\t
}"
;
}
}
public
function
buildSetUp
(
array
$options
,
array
$columns
,
array
$relations
)
...
...
@@ -264,7 +264,7 @@ END;
}
if
(
!
empty
(
$ret
))
{
return
"
\n\t
\t
public function setUp()
\n\t\t
{\n"
.
implode
(
"
\n
"
,
$ret
)
.
"
\n\t
\t
}"
;
return
"
\n\t
public function setUp()
\n\t
{\n"
.
implode
(
"
\n
"
,
$ret
)
.
"
\n
\t
}"
;
}
}
...
...
@@ -311,11 +311,14 @@ END;
if
(
$this
->
generateBaseClasses
())
{
// We only want to generate this one if it doesn't already exist
if
(
!
file_exists
(
$options
[
'fileName'
]))
{
if
(
file_exists
(
$options
[
'fileName'
]))
{
$optionsBak
=
$options
;
unset
(
$options
[
'tableName'
]);
$options
[
'inheritance'
][
'extends'
]
=
'Base'
.
$options
[
'className'
];
$options
[
'requires'
]
=
array
(
$this
->
baseClassesDirectory
.
DIRECTORY_SEPARATOR
.
$options
[
'inheritance'
][
'extends'
]
.
$this
->
suffix
);
$options
[
'no_definition'
]
=
true
;
$this
->
writeDefinition
(
$options
,
array
(),
array
());
$options
=
$optionsBak
;
...
...
@@ -341,7 +344,21 @@ END;
{
$content
=
$this
->
buildDefinition
(
$options
,
$columns
,
$relations
);
$bytes
=
file_put_contents
(
$options
[
'fileName'
],
'<?php'
.
PHP_EOL
.
$content
);
$code
=
"<?php
\n
"
;
if
(
isset
(
$options
[
'requires'
]))
{
if
(
!
is_array
(
$options
[
'requires'
]))
{
$options
[
'requires'
]
=
array
(
$options
[
'requires'
]);
}
foreach
(
$options
[
'requires'
]
as
$require
)
{
$code
.=
"require_once('"
.
$require
.
"');"
;
}
}
$code
.=
PHP_EOL
.
$content
;
$bytes
=
file_put_contents
(
$options
[
'fileName'
],
$code
);
if
(
$bytes
===
false
)
{
throw
new
Doctrine_Import_Builder_Exception
(
"Couldn't write file "
.
$options
[
'fileName'
]);
...
...
playground/index.php
View file @
94bf9a4c
...
...
@@ -4,9 +4,9 @@ require_once('playground.php');
$dbh
=
new
PDO
(
'mysql:host=localhost;dbname=test'
,
'jwage'
,
'elite1baller'
);
$conn
=
Doctrine_Manager
::
connection
(
$dbh
);
$manager
=
Doctrine_Manager
::
getInstance
();
$manager
->
setAttribute
(
Doctrine
::
ATTR_EXPORT
,
Doctrine
::
EXPORT_ALL
);
//
Doctrine::loadModels('test_models');
Doctrine
::
loadModels
(
'test_models'
);
$import
=
new
Doctrine_Import_Schema
();
$import
->
generateBaseClasses
(
true
);
$import
->
importSchema
(
'schema.yml'
,
'yml'
,
'test_models'
);
\ No newline at end of file
$data
=
new
Doctrine_Data
();
$data
->
importData
(
'fixtures.yml'
);
\ No newline at end of file
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