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
956c5dfe
Commit
956c5dfe
authored
Oct 05, 2007
by
Jonathan.Wage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes for exporting sql to correct connections.
parent
d2d52a63
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
36 deletions
+55
-36
Export.php
lib/Doctrine/Export.php
+34
-30
Builder.php
lib/Doctrine/Import/Builder.php
+21
-6
No files found.
lib/Doctrine/Export.php
View file @
956c5dfe
...
...
@@ -976,23 +976,10 @@ class Doctrine_Export extends Doctrine_Connection_Module
* @return void
*/
public
function
exportSchema
(
$directory
=
null
)
{
$sql
=
$this
->
exportSql
(
$directory
);
$this
->
conn
->
beginTransaction
();
foreach
(
$sql
as
$query
)
{
try
{
$this
->
conn
->
exec
(
$query
);
}
catch
(
Doctrine_Connection_Exception
$e
)
{
// we only want to silence table already exists errors
if
(
$e
->
getPortableCode
()
!==
Doctrine
::
ERR_ALREADY_EXISTS
)
{
$this
->
conn
->
rollback
();
throw
$e
;
}
}
}
$this
->
conn
->
commit
();
{
$models
=
Doctrine
::
loadModels
(
$directory
);
$this
->
exportClasses
(
$models
);
}
/**
* exportClasses
...
...
@@ -1005,22 +992,38 @@ class Doctrine_Export extends Doctrine_Connection_Module
*/
public
function
exportClasses
(
array
$classes
)
{
$sql
=
$this
->
exportClassesSql
(
$classes
);
$this
->
conn
->
beginTransaction
();
foreach
(
$sql
as
$query
)
{
try
{
$this
->
conn
->
exec
(
$query
);
}
catch
(
Doctrine_Connection_Exception
$e
)
{
// we only want to silence table already exists errors
if
(
$e
->
getPortableCode
()
!==
Doctrine
::
ERR_ALREADY_EXISTS
)
{
$this
->
conn
->
rollback
();
throw
$e
;
$connections
=
array
();
foreach
(
$classes
as
$class
)
{
$record
=
new
$class
();
$connection
=
$record
->
getTable
()
->
getConnection
();
$connectionName
=
Doctrine_Manager
::
getInstance
()
->
getConnectionName
(
$connection
);
if
(
!
isset
(
$connections
[
$connectionName
]))
{
$connections
[
$connectionName
]
=
array
();
}
$connections
[
$connectionName
]
=
array_merge
(
$connections
[
$connectionName
],
$this
->
exportClassesSql
(
array
(
$class
)));
}
foreach
(
$connections
as
$connectionName
=>
$sql
)
{
$connection
=
Doctrine_Manager
::
getInstance
()
->
getConnection
(
$connectionName
);
$connection
->
beginTransaction
();
foreach
(
$sql
as
$query
)
{
try
{
$connection
->
exec
(
$query
);
}
catch
(
Doctrine_Connection_Exception
$e
)
{
// we only want to silence table already exists errors
if
(
$e
->
getPortableCode
()
!==
Doctrine
::
ERR_ALREADY_EXISTS
)
{
$connection
->
rollback
();
throw
$e
;
}
}
}
$connection
->
commit
();
}
$this
->
conn
->
commit
();
}
/**
* exportClassesSql
...
...
@@ -1050,6 +1053,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
}
else
{
$sql
[]
=
$query
;
}
if
(
$table
->
getAttribute
(
Doctrine
::
ATTR_EXPORT
)
&
Doctrine
::
EXPORT_PLUGINS
)
{
$sql
=
array_merge
(
$sql
,
$this
->
exportPluginsSql
(
$table
));
}
...
...
lib/Doctrine/Import/Builder.php
View file @
956c5dfe
...
...
@@ -134,6 +134,11 @@ END;
$i
=
0
;
if
(
isset
(
$options
[
'inheritance'
][
'extends'
])
&&
!
isset
(
$options
[
'override_parent'
]))
{
$ret
[
$i
]
=
"
\t\t\t\t
parent::setTableDefinition();"
;
$i
++
;
}
if
(
isset
(
$options
[
'tableName'
])
&&
!
empty
(
$options
[
'tableName'
]))
{
$ret
[
$i
]
=
str_repeat
(
' '
,
8
)
.
'$this->setTableName(\''
.
$options
[
'tableName'
]
.
'\');'
;
...
...
@@ -188,7 +193,7 @@ END;
}
if
(
!
empty
(
$ret
))
{
return
"
\n\t\t
public function setTableDefinition()"
.
"
\n\t\t
{\n
\t\t\t\t
parent::setTableDefinition();
\n
"
.
implode
(
"
\n
"
,
$ret
)
.
"
\n\t\t
}"
;
return
"
\n\t\t
public function setTableDefinition()"
.
"
\n\t\t
{\n"
.
implode
(
"
\n
"
,
$ret
)
.
"
\n\t\t
}"
;
}
}
public
function
buildSetUp
(
array
$options
,
array
$columns
,
array
$relations
)
...
...
@@ -197,6 +202,11 @@ END;
$i
=
0
;
if
(
isset
(
$options
[
'inheritance'
][
'extends'
])
&&
!
isset
(
$options
[
'override_parent'
]))
{
$ret
[
$i
]
=
"
\t\t\t\t
parent::setUp();"
;
$i
++
;
}
foreach
(
$relations
as
$name
=>
$relation
)
{
$alias
=
(
isset
(
$relation
[
'alias'
])
&&
$relation
[
'alias'
]
!==
$name
)
?
' as '
.
$relation
[
'alias'
]
:
''
;
...
...
@@ -253,7 +263,7 @@ END;
}
if
(
!
empty
(
$ret
))
{
return
"
\n\t\t
public function setUp()
\n\t\t
{\n
\t\t\t\t
parent::setUp();
\n\t\t\t\t
"
.
implode
(
"
\n
"
,
$ret
)
.
"
\n\t\t
}"
;
return
"
\n\t\t
public function setUp()
\n\t\t
{\n"
.
implode
(
"
\n
"
,
$ret
)
.
"
\n\t\t
}"
;
}
}
...
...
@@ -266,8 +276,13 @@ END;
$className
=
$options
[
'className'
];
$extends
=
isset
(
$options
[
'inheritance'
][
'extends'
])
?
$options
[
'inheritance'
][
'extends'
]
:
'Doctrine_Record'
;
$definition
=
$this
->
buildTableDefinition
(
$options
,
$columns
,
$relations
);
$setUp
=
$this
->
buildSetUp
(
$options
,
$columns
,
$relations
);
if
(
!
isset
(
$options
[
'no_definition'
]))
{
$definition
=
$this
->
buildTableDefinition
(
$options
,
$columns
,
$relations
);
$setUp
=
$this
->
buildSetUp
(
$options
,
$columns
,
$relations
);
}
else
{
$definition
=
null
;
$setUp
=
null
;
}
$content
=
sprintf
(
self
::
$tpl
,
$className
,
$extends
,
...
...
@@ -298,7 +313,7 @@ END;
if
(
$this
->
generateBaseClasses
())
{
if
(
!
file_exists
(
$options
[
'fileName'
]))
{
//
if (!file_exists($options['fileName'])) {
$optionsBak
=
$options
;
unset
(
$options
[
'tableName'
]);
...
...
@@ -306,7 +321,7 @@ END;
$this
->
writeDefinition
(
$options
,
array
(),
array
());
$options
=
$optionsBak
;
}
//
}
$generatedPath
=
$this
->
path
.
DIRECTORY_SEPARATOR
.
$this
->
baseClassesDirectory
;
...
...
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