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
a6b194b9
Commit
a6b194b9
authored
Jan 25, 2008
by
jwage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work on migrations diff and fixes.
parent
ddefc7f9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
171 additions
and
3 deletions
+171
-3
Doctrine.php
lib/Doctrine.php
+16
-0
Lib.php
lib/Doctrine/Lib.php
+32
-0
Diff.php
lib/Doctrine/Migration/Diff.php
+121
-1
Dql.php
lib/Doctrine/Task/Dql.php
+2
-2
No files found.
lib/Doctrine.php
View file @
a6b194b9
...
@@ -596,6 +596,8 @@ final class Doctrine
...
@@ -596,6 +596,8 @@ final class Doctrine
*/
*/
private
static
$_loadedModelFiles
=
array
();
private
static
$_loadedModelFiles
=
array
();
private
static
$_pathModels
=
array
();
/**
/**
* __construct
* __construct
*
*
...
@@ -606,7 +608,17 @@ final class Doctrine
...
@@ -606,7 +608,17 @@ final class Doctrine
{
{
throw
new
Doctrine_Exception
(
'Doctrine is static class. No instances can be created.'
);
throw
new
Doctrine_Exception
(
'Doctrine is static class. No instances can be created.'
);
}
}
public
static
function
getLoadedModelFiles
()
{
return
self
::
$_loadedModelFiles
;
}
public
static
function
getPathModels
()
{
return
self
::
$_pathModels
;
}
/**
/**
* getPath
* getPath
* returns the doctrine root
* returns the doctrine root
...
@@ -646,6 +658,8 @@ final class Doctrine
...
@@ -646,6 +658,8 @@ final class Doctrine
if
(
$manager
->
getAttribute
(
Doctrine
::
ATTR_MODEL_LOADING
)
===
Doctrine
::
MODEL_LOADING_CONSERVATIVE
)
{
if
(
$manager
->
getAttribute
(
Doctrine
::
ATTR_MODEL_LOADING
)
===
Doctrine
::
MODEL_LOADING_CONSERVATIVE
)
{
self
::
$_loadedModelFiles
[
$e
[
0
]]
=
$file
->
getPathName
();
self
::
$_loadedModelFiles
[
$e
[
0
]]
=
$file
->
getPathName
();
self
::
$_pathModels
[
$file
->
getPathName
()][
$e
[
0
]]
=
$e
[
0
];
$loadedModels
[]
=
$e
[
0
];
$loadedModels
[]
=
$e
[
0
];
}
else
{
}
else
{
$declaredBefore
=
get_declared_classes
();
$declaredBefore
=
get_declared_classes
();
...
@@ -658,6 +672,8 @@ final class Doctrine
...
@@ -658,6 +672,8 @@ final class Doctrine
foreach
(
$foundClasses
as
$className
)
{
foreach
(
$foundClasses
as
$className
)
{
if
(
self
::
isValidModelClass
(
$className
)
&&
!
in_array
(
$className
,
$loadedModels
))
{
if
(
self
::
isValidModelClass
(
$className
)
&&
!
in_array
(
$className
,
$loadedModels
))
{
$loadedModels
[]
=
$className
;
$loadedModels
[]
=
$className
;
self
::
$_pathModels
[
$file
->
getPathName
()][
$className
]
=
$className
;
}
}
}
}
}
}
...
...
lib/Doctrine/Lib.php
View file @
a6b194b9
...
@@ -396,6 +396,38 @@ class Doctrine_Lib
...
@@ -396,6 +396,38 @@ class Doctrine_Lib
}
}
}
}
public
static
function
copyDirectory
(
$source
,
$dest
)
{
// Simple copy for a file
if
(
is_file
(
$source
))
{
return
copy
(
$source
,
$dest
);
}
// Make destination directory
if
(
!
is_dir
(
$dest
))
{
mkdir
(
$dest
);
}
// Loop through the folder
$dir
=
dir
(
$source
);
while
(
false
!==
$entry
=
$dir
->
read
())
{
// Skip pointers
if
(
$entry
==
'.'
||
$entry
==
'..'
)
{
continue
;
}
// Deep copy directories
if
(
$dest
!==
"
$source
/
$entry
"
)
{
self
::
copyDirectory
(
"
$source
/
$entry
"
,
"
$dest
/
$entry
"
);
}
}
// Clean up
$dir
->
close
();
return
true
;
}
/**
/**
* isValidClassName
* isValidClassName
*
*
...
...
lib/Doctrine/Migration/Diff.php
View file @
a6b194b9
...
@@ -31,5 +31,125 @@
...
@@ -31,5 +31,125 @@
* @author Jonathan H. Wage <jonwage@gmail.com>
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
*/
class
Doctrine_Migration_Diff
class
Doctrine_Migration_Diff
{
{
protected
$_from
,
$_to
,
$_changes
=
array
(),
$_migrationsPath
;
public
function
__construct
(
$from
=
null
,
$to
=
null
)
{
$this
->
_from
=
$from
;
$this
->
_to
=
$to
;
}
protected
function
getUniqueId
()
{
return
md5
(
$this
->
_from
.
$this
->
_to
);
}
public
function
setMigrationsPath
(
$migrationsPath
)
{
$this
->
_migrationsPath
=
$migrationsPath
;
}
public
function
generate
()
{
$from
=
$this
->
_generateModels
(
'From'
,
$this
->
_from
);
$to
=
$this
->
_generateModels
(
'To'
,
$this
->
_to
);
$differences
=
$this
->
_diff
(
$from
,
$to
);
print_r
(
$differences
);
}
protected
function
_diff
(
$from
,
$to
)
{
$fromTmpPath
=
sys_get_temp_dir
()
.
$this
->
getUniqueId
()
.
'_from'
;
$toTmpPath
=
sys_get_temp_dir
()
.
$this
->
getUniqueId
()
.
'_to'
;
if
(
!
file_exists
(
$fromTmpPath
))
{
$fromModels
=
Doctrine
::
loadModels
(
$from
);
$fromInfo
=
$this
->
_buildModelInformation
(
$fromModels
);
file_put_contents
(
$fromTmpPath
,
serialize
(
$fromInfo
));
}
else
{
if
(
!
file_exists
(
$toTmpPath
))
{
$toModels
=
Doctrine
::
loadModels
(
$to
);
$toInfo
=
$this
->
_buildModelInformation
(
$toModels
);
file_put_contents
(
$toTmpPath
,
serialize
(
$toInfo
));
}
else
{
$fromInfo
=
unserialize
(
file_get_contents
(
$fromTmpPath
));
$toInfo
=
unserialize
(
file_get_contents
(
$toTmpPath
));
$this
->
_buildChanges
(
$fromInfo
,
$toInfo
);
// clean up
unlink
(
$fromTmpPath
);
unlink
(
$toTmpPath
);
Doctrine_Lib
::
removeDirectories
(
sys_get_temp_dir
()
.
'from_doctrine_tmp_dirs'
);
Doctrine_Lib
::
removeDirectories
(
sys_get_temp_dir
()
.
'to_doctrine_tmp_dirs'
);
}
}
}
protected
function
_buildChanges
(
$from
,
$to
)
{
foreach
(
$to
as
$key
=>
$model
)
{
$columns
=
$model
[
'columns'
];
foreach
(
$columns
as
$columnKey
=>
$column
)
{
//if (isset($to[$key]['columns'][$columnKey]))
}
}
}
protected
function
_buildModelInformation
(
array
$models
)
{
$info
=
array
();
foreach
(
$models
as
$key
=>
$model
)
{
$info
[
$model
]
=
Doctrine
::
getTable
(
$model
)
->
getExportableFormat
();
}
return
$info
;
}
protected
function
_generateModels
(
$prefix
,
$item
)
{
$path
=
sys_get_temp_dir
()
.
$prefix
.
'_doctrine_tmp_dirs'
;
if
(
is_dir
(
$item
))
{
$files
=
glob
(
$item
.
DIRECTORY_SEPARATOR
.
'*.*'
);
if
(
isset
(
$files
[
0
]))
{
$pathInfo
=
pathinfo
(
$files
[
0
]);
$extension
=
$pathInfo
[
'extension'
];
}
if
(
$extension
===
'yml'
)
{
Doctrine
::
generateModelsFromYaml
(
$item
,
$path
);
return
$path
;
}
else
if
(
$extension
===
'php'
)
{
Doctrine_Lib
::
copyDirectory
(
$item
,
$path
);
return
$path
;
}
else
{
throw
new
Doctrine_Migration_Exception
(
'No php or yml files found at path: "'
.
$item
.
'"'
);
}
}
else
{
try
{
$connection
=
Doctrine_Manager
::
getInstance
()
->
getConnection
(
$item
);
Doctrine
::
generateModelsFromDb
(
$path
,
array
(
$item
));
return
$path
;
}
catch
(
Exception
$e
)
{
throw
new
Doctrine_Migration_Exception
(
'Could not generate models from connection: '
.
$e
->
getMessage
());
}
}
}
}
}
\ No newline at end of file
lib/Doctrine/Task/Dql.php
View file @
a6b194b9
...
@@ -51,10 +51,10 @@ class Doctrine_Task_Dql extends Doctrine_Task
...
@@ -51,10 +51,10 @@ class Doctrine_Task_Dql extends Doctrine_Task
$results
=
$query
->
query
(
$dql
,
$params
);
$results
=
$query
->
query
(
$dql
,
$params
);
$this
->
printResults
(
$results
);
$this
->
_
printResults
(
$results
);
}
}
protected
function
printResults
(
$data
)
protected
function
_
printResults
(
$data
)
{
{
$array
=
$data
->
toArray
(
true
);
$array
=
$data
->
toArray
(
true
);
...
...
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