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
b41259b0
Commit
b41259b0
authored
Sep 19, 2007
by
Jonathan.Wage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
340dbf77
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
130 additions
and
82 deletions
+130
-82
Doctrine.php
lib/Doctrine.php
+90
-1
UnitOfWork.php
lib/Doctrine/Connection/UnitOfWork.php
+2
-2
Migration.php
lib/Doctrine/Migration.php
+6
-9
Process.php
lib/Doctrine/Migration/Process.php
+24
-19
index.php
playground/index.php
+5
-2
playground.php
playground/playground.php
+1
-49
run.php
tests/run.php
+2
-0
No files found.
lib/Doctrine.php
View file @
b41259b0
...
...
@@ -431,6 +431,95 @@ final class Doctrine
Doctrine
::
autoload
(
$class
);
}
}
/**
* loadModels
*
* Recursively load all models from a directory or array of directories
*
* @param string $directory Path to directory of models or array of directory paths
* @return void
* @author Jonathan H. Wage
*/
public
static
function
loadModels
(
$directory
)
{
$declared
=
get_declared_classes
();
if
(
$directory
!==
null
)
{
foreach
((
array
)
$directory
as
$dir
)
{
$it
=
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$dir
),
RecursiveIteratorIterator
::
LEAVES_ONLY
);
foreach
(
$it
as
$file
)
{
$e
=
explode
(
'.'
,
$file
->
getFileName
());
if
(
end
(
$e
)
===
'php'
&&
strpos
(
$file
->
getFileName
(),
'.inc'
)
===
false
)
{
require_once
$file
->
getPathName
();
}
}
}
$declared
=
array_diff
(
get_declared_classes
(),
$declared
);
}
return
self
::
getLoadedModels
(
$declared
);
}
/**
* getLoadedModels
*
* @package default
* @author Jonathan H. Wage
*/
public
static
function
getLoadedModels
(
$classes
=
null
)
{
if
(
$classes
===
null
)
{
$classes
=
get_declared_classes
();
}
$parent
=
new
ReflectionClass
(
'Doctrine_Record'
);
$loadedModels
=
array
();
// we iterate trhough the diff of previously declared classes
// and currently declared classes
foreach
(
$classes
as
$name
)
{
$class
=
new
ReflectionClass
(
$name
);
$conn
=
Doctrine_Manager
::
getInstance
()
->
getConnectionForComponent
(
$name
);
// check if class is an instance of Doctrine_Record and not abstract
// class must have method setTableDefinition (to avoid non-Record subclasses like symfony's sfDoctrineRecord)
// we have to recursively iterate through the class parents just to be sure that the classes using for example
// column aggregation inheritance are properly exported to database
while
(
$class
->
isAbstract
()
||
!
$class
->
isSubclassOf
(
$parent
)
||
!
$class
->
hasMethod
(
'setTableDefinition'
)
||
(
$class
->
hasMethod
(
'setTableDefinition'
)
&&
$class
->
getMethod
(
'setTableDefinition'
)
->
getDeclaringClass
()
->
getName
()
!==
$class
->
getName
()))
{
$class
=
$class
->
getParentClass
();
if
(
$class
===
false
)
{
break
;
}
}
if
(
$class
===
false
)
{
continue
;
}
$loadedModels
[]
=
$name
;
}
return
$loadedModels
;
}
public
function
getConnectionByTableName
(
$tableName
)
{
$loadedModels
=
Doctrine
::
getLoadedModels
();
foreach
(
$loadedModels
AS
$name
)
{
$model
=
new
$model
();
$table
=
$model
->
getTable
();
if
(
$table
->
getTableName
()
==
$tableName
)
{
return
$table
->
getConnection
();
}
}
}
/**
* importSchema
* method for importing existing schema to Doctrine_Record classes
...
...
@@ -568,4 +657,4 @@ final class Doctrine
return
true
;
}
}
}
\ No newline at end of file
lib/Doctrine/Connection/UnitOfWork.php
View file @
b41259b0
...
...
@@ -194,8 +194,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
if
(
$record
->
hasReference
(
$alias
))
{
$obj
=
$record
->
$alias
;
// check that the related object is
not Doctrine_Null
if
(
$obj
instanceof
Doctrine_Record
)
{
// check that the related object is
either an instance of Doctrine_Record or an instance of Doctrine_Collection
if
(
$obj
instanceof
Doctrine_Record
||
$obj
instanceof
Doctrine_Collection
)
{
$obj
->
save
(
$conn
);
}
}
...
...
lib/Doctrine/Migration.php
View file @
b41259b0
...
...
@@ -45,15 +45,12 @@ class Doctrine_Migration
static
public
function
migration
(
$directory
,
$from
,
$to
)
{
if
(
$from
===
$to
OR
$from
===
0
)
{
if
(
$from
===
$to
||
$from
===
0
)
{
throw
new
Doctrine_Migration_Exception
(
'You specified an invalid migration path. The from and to cannot be the same and from cannot be zero.'
);
}
$direction
=
$from
>
$to
?
'down'
:
'up'
;
$fromPath
=
$directory
.
DIRECTORY_SEPARATOR
;
$toPath
=
$directory
.
DIRECTORY_SEPARATOR
;
if
(
$direction
===
'up'
)
{
for
(
$i
=
$from
+
1
;
$i
<=
$to
;
$i
++
)
{
self
::
doDirectionStep
(
$directory
,
$direction
,
$i
);
...
...
@@ -67,9 +64,9 @@ class Doctrine_Migration
public
static
function
doDirectionStep
(
$directory
,
$direction
,
$num
)
{
$className
=
'Migration'
.
$num
;
$fileName
=
$className
.
'.class.php'
;
$filePath
=
$directory
.
DIRECTORY_SEPARATOR
.
$fileName
;
$className
=
'Migration'
.
$num
;
$fileName
=
$className
.
'.class.php'
;
$filePath
=
$directory
.
DIRECTORY_SEPARATOR
.
$fileName
;
if
(
file_exists
(
$filePath
))
{
require_once
(
$filePath
);
...
...
@@ -94,7 +91,7 @@ class Doctrine_Migration
{
foreach
(
$this
->
changes
as
$type
=>
$changes
)
{
$process
=
new
Doctrine_Migration_Process
();
$funcName
=
'process'
.
Doctrine
::
classify
(
$type
);
$funcName
=
'process'
.
Doctrine
::
classify
(
$type
);
$process
->
$funcName
(
$changes
);
}
}
...
...
@@ -125,7 +122,7 @@ class Doctrine_Migration
$this
->
addChange
(
'renamed_tables'
,
$options
);
}
public
function
addColumn
(
$tableName
,
$columnName
,
$type
,
$options
=
array
())
public
function
addColumn
(
$tableName
,
$columnName
,
$type
,
array
$options
=
array
())
{
$options
=
get_defined_vars
();
...
...
lib/Doctrine/Migration/Process.php
View file @
b41259b0
...
...
@@ -31,38 +31,43 @@
*/
class
Doctrine_Migration_Process
{
public
function
processCreatedTables
(
$tables
)
public
function
getConnection
(
$tableName
)
{
$conn
=
Doctrine_Manager
::
connection
();
return
Doctrine
::
getConnectionByTableName
(
$tableName
);
}
public
function
processCreatedTables
(
$tables
)
{
foreach
(
$tables
as
$table
)
{
$conn
=
$this
->
getConnection
(
$table
[
'tableName'
]);
$conn
->
export
->
createTable
(
$table
[
'tableName'
],
$table
[
'fields'
],
$table
[
'options'
]);
}
}
public
function
processDroppedTables
(
$tables
)
{
$conn
=
Doctrine_Manager
::
connection
();
foreach
(
$tables
as
$table
)
{
$conn
=
$this
->
getConnection
(
$table
[
'tableName'
]);
$conn
->
export
->
dropTable
(
$table
[
'tableName'
]);
}
}
public
function
processRenamedTables
(
$tables
)
{
$conn
=
Doctrine_Manager
::
connection
();
foreach
(
$tables
as
$table
)
{
$conn
=
$this
->
getConnection
(
$table
[
'newTableName'
]);
$conn
->
export
->
alterTable
(
$table
[
'oldTableName'
],
array
(
'name'
=>
$table
[
'newTableName'
]),
true
);
}
}
public
function
processAddedColumns
(
$columns
)
{
$conn
=
Doctrine_Manager
::
connection
();
foreach
(
$columns
as
$column
)
{
$conn
=
$this
->
getConnection
(
$column
[
'tableName'
]);
$options
=
array
();
$options
=
$column
[
'options'
];
$options
[
'type'
]
=
$column
[
'type'
];
...
...
@@ -73,18 +78,18 @@ class Doctrine_Migration_Process
public
function
processRenamedColumns
(
$columns
)
{
$conn
=
Doctrine_Manager
::
connection
();
foreach
(
$columns
as
$column
)
{
$conn
=
$this
->
getConnection
(
$column
[
'tableName'
]);
$conn
->
export
->
alterTable
(
$column
[
'tableName'
],
array
(
'rename'
=>
array
(
$column
[
'oldColumnName'
]
=>
array
(
'name'
=>
$column
[
'newColumnName'
]))),
true
);
}
}
public
function
processChangedColumns
(
$columns
)
{
$conn
=
Doctrine_Manager
::
connection
();
foreach
(
$columns
as
$column
)
{
$conn
=
$this
->
getConnection
(
$column
[
'tableName'
]);
$options
=
array
();
$options
=
$column
[
'options'
];
$options
[
'type'
]
=
$column
[
'type'
];
...
...
@@ -95,27 +100,27 @@ class Doctrine_Migration_Process
public
function
processRemovedColumns
(
$columns
)
{
$conn
=
Doctrine_Manager
::
connection
();
foreach
(
$columns
as
$column
)
{
$conn
=
$this
->
getConnection
(
$column
[
'tableName'
]);
$conn
->
export
->
alterTable
(
$column
[
'tableName'
],
array
(
'remove'
=>
array
(
$column
[
'columnName'
]
=>
array
())));
}
}
public
function
processAddedIndexes
(
$indexes
)
{
$conn
=
Doctrine_Manager
::
connection
();
foreach
(
$indexes
as
$index
)
{
$conn
=
$this
->
getConnection
(
$index
[
'tableName'
]);
$conn
->
export
->
createIndex
(
$index
[
'tableName'
],
$index
[
'indexName'
],
$index
[
'definition'
]);
}
}
public
function
processRemovedIndexes
(
$indexes
)
{
$conn
=
Doctrine_Manager
::
connection
();
foreach
(
$indexes
as
$index
)
{
$conn
=
$this
->
getConnection
(
$index
[
'tableName'
]);
$conn
->
export
->
dropIndex
(
$index
[
'tableName'
],
$index
[
'indexName'
]);
}
}
...
...
playground/index.php
View file @
b41259b0
<?php
define
(
'LOAD_MODELS'
,
false
);
require_once
(
'playground.php'
);
require_once
(
'connection.php'
);
require_once
(
'models.php'
);
require_once
(
'playground.php'
);
\ No newline at end of file
Doctrine_Migration
::
migration
(
'migration'
,
1
,
3
);
Doctrine_Migration
::
migration
(
'migration'
,
3
,
1
);
playground/playground.php
View file @
b41259b0
<?php
ini_set
(
'max_execution_time'
,
900
);
// include doctrine, and register it's autoloader
require_once
dirname
(
__FILE__
)
.
DIRECTORY_SEPARATOR
.
'doctrine/Doctrine.php'
;
spl_autoload_register
(
array
(
'Doctrine'
,
'autoload'
));
if
(
constant
(
'LOAD_MODELS'
))
{
$modelsPath
=
dirname
(
__FILE__
)
.
DIRECTORY_SEPARATOR
.
'models'
;
// include the models
$models
=
new
DirectoryIterator
(
$modelsPath
);
foreach
(
$models
as
$key
=>
$file
)
{
if
(
$file
->
isFile
()
&&
!
$file
->
isDot
())
{
$e
=
explode
(
'.'
,
$file
->
getFileName
());
if
(
end
(
$e
)
===
'php'
)
{
require_once
$file
->
getPathname
();
}
}
}
}
error_reporting
(
E_ALL
|
E_STRICT
);
$dbh
=
new
PDO
(
'sqlite::memory:'
);
$conn
=
Doctrine_Manager
::
connection
(
$dbh
);
$manager
=
Doctrine_Manager
::
getInstance
();
if
(
constant
(
'LOAD_MODELS'
))
{
$manager
->
setAttribute
(
Doctrine
::
ATTR_EXPORT
,
Doctrine
::
EXPORT_ALL
);
$tables
=
array
(
'entity'
,
'entityReference'
,
'email'
,
'phonenumber'
,
'groupuser'
,
'album'
,
'song'
,
'element'
,
'error'
,
'description'
,
'address'
,
'account'
,
'task'
,
'resource'
,
'assignment'
,
'resourceType'
,
'resourceReference'
);
$conn
->
export
->
exportClasses
(
$tables
);
require_once
(
'data.php'
);
}
\ No newline at end of file
error_reporting
(
E_ALL
|
E_STRICT
);
\ No newline at end of file
tests/run.php
View file @
b41259b0
...
...
@@ -337,6 +337,8 @@ $test->addTestCase($cache);
$test
->
addTestCase
(
new
Doctrine_Query_ApplyInheritance_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Migration_TestCase
());
class
CliReporter
extends
HtmlReporter
{
public
function
paintHeader
(){
echo
"Doctrine UnitTests
\n
"
;
...
...
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