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
49bcc69f
Commit
49bcc69f
authored
Oct 30, 2009
by
guilhermeblanco
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] Moved EntityManager creation to be always available in CLI Tasks
parent
10e3407e
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
109 additions
and
61 deletions
+109
-61
AbstractFileDriver.php
lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php
+4
-3
Cli.php
lib/Doctrine/ORM/Tools/Cli.php
+43
-1
AbstractTask.php
lib/Doctrine/ORM/Tools/Cli/Tasks/AbstractTask.php
+24
-30
ClearCacheTask.php
lib/Doctrine/ORM/Tools/Cli/Tasks/ClearCacheTask.php
+1
-1
ConvertMappingTask.php
lib/Doctrine/ORM/Tools/Cli/Tasks/ConvertMappingTask.php
+3
-2
EnsureProductionSettingsTask.php
...rine/ORM/Tools/Cli/Tasks/EnsureProductionSettingsTask.php
+6
-1
GenerateProxiesTask.php
lib/Doctrine/ORM/Tools/Cli/Tasks/GenerateProxiesTask.php
+10
-10
HelpTask.php
lib/Doctrine/ORM/Tools/Cli/Tasks/HelpTask.php
+1
-0
RunDqlTask.php
lib/Doctrine/ORM/Tools/Cli/Tasks/RunDqlTask.php
+1
-1
RunSqlTask.php
lib/Doctrine/ORM/Tools/Cli/Tasks/RunSqlTask.php
+4
-2
SchemaToolTask.php
lib/Doctrine/ORM/Tools/Cli/Tasks/SchemaToolTask.php
+8
-8
VersionTask.php
lib/Doctrine/ORM/Tools/Cli/Tasks/VersionTask.php
+1
-1
cli-config.php
tools/sandbox/cli-config.php
+3
-1
No files found.
lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php
View file @
49bcc69f
...
...
@@ -40,6 +40,7 @@ abstract class AbstractFileDriver implements Driver
* adhere to the convention of 1 mapping file per class and the file names of
* the mapping files must correspond to the full class name, including namespace,
* with the namespace delimiters '\', replaced by dots '.'.
* This is the default behavior.
*
* Example:
* Class: My\Project\Model\User
...
...
@@ -51,8 +52,8 @@ abstract class AbstractFileDriver implements Driver
/**
* The PRELOAD mode is an operating mode of the FileDriver where it loads
* all mapping files in advance.
This is the default behavior. It does not
*
require a naming convention
or the convention of 1 class per mapping file.
* all mapping files in advance.
It does not require a naming convention
* or the convention of 1 class per mapping file.
*
* @var integer
*/
...
...
@@ -95,7 +96,7 @@ abstract class AbstractFileDriver implements Driver
*/
public
function
__construct
(
$paths
,
$mode
=
self
::
FILE_PER_CLASS
)
{
$this
->
_paths
=
$paths
;
$this
->
_paths
=
(
array
)
$paths
;
$this
->
_mode
=
$mode
;
}
...
...
lib/Doctrine/ORM/Tools/Cli.php
View file @
49bcc69f
...
...
@@ -157,7 +157,7 @@ class Cli
try
{
$this
->
_printer
->
writeln
(
'Doctrine Command Line Interface'
.
PHP_EOL
,
'HEADER'
);
// Handle possible multiple tasks on a single command
foreach
(
$processedArgs
as
$taskData
)
{
// Retrieve the task name and arguments
...
...
@@ -166,9 +166,13 @@ class Cli
// Check if task exists
if
(
isset
(
$this
->
_tasks
[
$taskName
])
&&
class_exists
(
$this
->
_tasks
[
$taskName
],
true
))
{
// Initializing EntityManager
$em
=
$this
->
_initializeEntityManager
(
$processedArgs
);
// Instantiate and execute the task
$task
=
new
$this
->
_tasks
[
$taskName
]();
$task
->
setAvailableTasks
(
$this
->
_tasks
);
$task
->
setEntityManager
(
$em
);
$task
->
setPrinter
(
$this
->
_printer
);
$task
->
setArguments
(
$taskArguments
);
...
...
@@ -311,4 +315,42 @@ class Cli
// required and optional arguments here?
return
$task
->
validate
();
}
/**
* Initialized Entity Manager for Tasks
*
* @param array CLI Task arguments
* @return EntityManager
*/
private
function
_initializeEntityManager
(
&
$args
)
{
// Initialize EntityManager
$configFile
=
(
!
isset
(
$args
[
'config'
]))
?
'./cli-config.php'
:
$args
[
'config'
];
if
(
file_exists
(
$configFile
))
{
// Including configuration file
require
$configFile
;
// Check existance of EntityManager
if
(
!
isset
(
$em
))
{
throw
new
\Doctrine\Common\DoctrineException
(
'No EntityManager created in configuration'
);
}
// Check for gloal argument options here
if
(
isset
(
$globalArguments
))
{
// Merge arguments. Values specified via the CLI take preference.
$args
=
array_merge
(
$globalArguments
,
$args
);
}
return
$em
;
}
else
{
throw
new
\Doctrine\Common\DoctrineException
(
'Requested configuration file ['
.
$configFile
.
'] does not exist'
);
}
return
null
;
}
}
\ No newline at end of file
lib/Doctrine/ORM/Tools/Cli/Tasks/AbstractTask.php
View file @
49bcc69f
...
...
@@ -60,6 +60,9 @@ abstract class AbstractTask
*/
protected
$_availableTasks
;
/**
* @var EntityManager The EntityManager instance
*/
protected
$_em
;
/**
...
...
@@ -122,6 +125,26 @@ abstract class AbstractTask
return
$this
->
_availableTasks
;
}
/**
* Defines the EntityManager
*
* @param EntityManager The EntityManager instance
*/
public
function
setEntityManager
(
$em
)
{
$this
->
_em
=
$em
;
}
/**
* Retrieves current EntityManager
*
* @return EntityManager
*/
public
function
getEntityManager
()
{
return
$this
->
_em
;
}
/**
* Expose to CLI Output Printer the extended help of the given task.
* This means it should detail all parameters, options and the meaning
...
...
@@ -159,27 +182,7 @@ abstract class AbstractTask
*
* @return boolean
*/
public
function
validate
()
{
if
(
!
isset
(
$this
->
_arguments
[
'config'
]))
{
if
(
file_exists
(
'./cli-config.php'
))
{
require
'./cli-config.php'
;
}
}
else
{
require
$this
->
_arguments
[
'config'
];
}
// $em and $args come from the config
if
(
isset
(
$em
))
{
$this
->
_em
=
$em
;
}
if
(
isset
(
$args
))
{
// Merge arguments. Values specified via the CLI take preference.
$this
->
_arguments
=
array_merge
(
$args
,
$this
->
_arguments
);
}
return
true
;
}
abstract
public
function
validate
();
/**
* Safely execution of task.
...
...
@@ -187,13 +190,4 @@ abstract class AbstractTask
* what is supposed to do.
*/
abstract
public
function
run
();
protected
function
_requireEntityManager
()
{
if
(
!
isset
(
$this
->
_em
))
{
$this
->
_printer
->
writeln
(
'No EntityManager created in configuration but required by task '
.
get_class
(
$this
),
'ERROR'
);
return
false
;
}
return
true
;
}
}
\ No newline at end of file
lib/Doctrine/ORM/Tools/Cli/Tasks/ClearCacheTask.php
View file @
49bcc69f
...
...
@@ -120,7 +120,7 @@ class ClearCacheTask extends AbstractTask
$all
=
true
;
}
$configuration
=
$this
->
_em
->
getConfiguration
();
$configuration
=
$this
->
getEntityManager
()
->
getConfiguration
();
if
(
$query
||
$all
)
{
$this
->
_doDelete
(
...
...
lib/Doctrine/ORM/Tools/Cli/Tasks/ConvertMappingTask.php
View file @
49bcc69f
...
...
@@ -111,8 +111,9 @@ class ConvertMappingTask extends AbstractTask
return
false
;
}
if
(
$args
[
'from'
][
0
]
==
'database'
)
{
$config
=
$this
->
_em
->
getConfiguration
();
$config
->
setMetadataDriverImpl
(
new
\Doctrine\ORM\Mapping\Driver\DatabaseDriver
(
$this
->
_em
->
getConnection
()
->
getSchemaManager
()));
$em
=
$this
->
getEntityManager
();
$config
=
$em
->
getConfiguration
();
$config
->
setMetadataDriverImpl
(
new
\Doctrine\ORM\Mapping\Driver\DatabaseDriver
(
$em
->
getConnection
()
->
getSchemaManager
()));
}
return
true
;
}
...
...
lib/Doctrine/ORM/Tools/Cli/Tasks/EnsureProductionSettingsTask.php
View file @
49bcc69f
...
...
@@ -56,12 +56,17 @@ class EnsureProductionSettingsTask extends AbstractTask
{
$printer
->
writeln
(
'ensure-production-settings'
,
'KEYWORD'
);
}
public
function
validate
()
{
return
true
;
}
public
function
run
()
{
$printer
=
$this
->
getPrinter
();
try
{
$this
->
_em
->
getConfiguration
()
->
ensureProductionSettings
();
$this
->
getEntityManager
()
->
getConfiguration
()
->
ensureProductionSettings
();
}
catch
(
\Doctrine\Common\DoctrineException
$e
)
{
$printer
->
writeln
(
$e
->
getMessage
(),
'ERROR'
);
}
...
...
lib/Doctrine/ORM/Tools/Cli/Tasks/GenerateProxiesTask.php
View file @
49bcc69f
...
...
@@ -59,11 +59,8 @@ class GenerateProxiesTask extends AbstractTask
$args
=
$this
->
getArguments
();
$printer
=
$this
->
getPrinter
();
if
(
!
$this
->
_requireEntityManager
())
{
return
false
;
}
$metadataDriver
=
$this
->
getEntityManager
()
->
getConfiguration
()
->
getMetadataDriverImpl
();
$metadataDriver
=
$this
->
_em
->
getConfiguration
()
->
getMetadataDriverImpl
();
if
(
$metadataDriver
instanceof
\Doctrine\ORM\Mapping\Driver\AnnotationDriver
)
{
if
(
!
isset
(
$args
[
'class-dir'
]))
{
$printer
->
writeln
(
"The supplied configuration uses the annotation metadata driver."
...
...
@@ -84,17 +81,19 @@ class GenerateProxiesTask extends AbstractTask
{
$args
=
$this
->
getArguments
();
$cmf
=
$this
->
_em
->
getMetadataFactory
();
$driver
=
$this
->
_em
->
getConfiguration
()
->
getMetadataDriverImpl
();
$em
=
$this
->
getEntityManager
();
$cmf
=
$em
->
getMetadataFactory
();
$driver
=
$em
->
getConfiguration
()
->
getMetadataDriverImpl
();
$classes
=
array
();
$preloadedClasses
=
$driver
->
preload
(
true
);
foreach
(
$preloadedClasses
as
$className
)
{
$classes
[]
=
$cmf
->
getMetadataFor
(
$className
);
}
$printer
=
$this
->
getPrinter
();
$factory
=
$
this
->
_
em
->
getProxyFactory
();
$factory
=
$em
->
getProxyFactory
();
if
(
empty
(
$classes
))
{
$printer
->
writeln
(
'No classes to process.'
,
'INFO'
);
...
...
@@ -103,8 +102,9 @@ class GenerateProxiesTask extends AbstractTask
$factory
->
generateProxyClasses
(
$classes
,
isset
(
$args
[
'to-dir'
])
?
$args
[
'to-dir'
]
:
null
);
$printer
->
writeln
(
'Proxy classes generated to: '
.
(
isset
(
$args
[
'to-dir'
])
?
$args
[
'to-dir'
]
:
$this
->
_em
->
getConfiguration
()
->
getProxyDir
())
);
$printer
->
writeln
(
'Proxy classes generated to: '
.
(
isset
(
$args
[
'to-dir'
])
?
$args
[
'to-dir'
]
:
$em
->
getConfiguration
()
->
getProxyDir
())
);
}
}
\ No newline at end of file
lib/Doctrine/ORM/Tools/Cli/Tasks/HelpTask.php
View file @
49bcc69f
...
...
@@ -80,6 +80,7 @@ class HelpTask extends AbstractTask
$task
=
new
$taskClass
();
$task
->
setAvailableTasks
(
$availableTasks
);
$task
->
setEntityManager
(
$this
->
getEntityManager
());
$task
->
setPrinter
(
$this
->
getPrinter
());
$task
->
setArguments
(
$this
->
getArguments
());
...
...
lib/Doctrine/ORM/Tools/Cli/Tasks/RunDqlTask.php
View file @
49bcc69f
...
...
@@ -101,7 +101,7 @@ class RunDqlTask extends AbstractTask
$args
=
$this
->
getArguments
();
try
{
$query
=
$this
->
_em
->
createQuery
(
$args
[
'dql'
]);
$query
=
$this
->
getEntityManager
()
->
createQuery
(
$args
[
'dql'
]);
$resultSet
=
$query
->
getResult
();
$maxDepth
=
isset
(
$args
[
'depth'
])
?
$args
[
'depth'
]
:
7
;
...
...
lib/Doctrine/ORM/Tools/Cli/Tasks/RunSqlTask.php
View file @
49bcc69f
...
...
@@ -113,11 +113,13 @@ class RunSqlTask extends AbstractTask
if
(
isset
(
$args
[
'file'
]))
{
//TODO
}
else
if
(
isset
(
$args
[
'sql'
]))
{
$conn
=
$this
->
getEntityManager
()
->
getConnection
();
if
(
preg_match
(
'/^select/i'
,
$args
[
'sql'
]))
{
$stmt
=
$
this
->
_em
->
getConnection
()
->
execute
(
$args
[
'sql'
]);
$stmt
=
$
conn
->
execute
(
$args
[
'sql'
]);
$resultSet
=
$stmt
->
fetchAll
(
\Doctrine\DBAL\Connection
::
FETCH_ASSOC
);
}
else
{
$resultSet
=
$
this
->
_em
->
getConnection
()
->
executeUpdate
(
$args
[
'sql'
]);
$resultSet
=
$
conn
->
executeUpdate
(
$args
[
'sql'
]);
}
$maxDepth
=
isset
(
$args
[
'depth'
])
?
$args
[
'depth'
]
:
7
;
...
...
lib/Doctrine/ORM/Tools/Cli/Tasks/SchemaToolTask.php
View file @
49bcc69f
...
...
@@ -106,10 +106,6 @@ class SchemaToolTask extends AbstractTask
$args
=
$this
->
getArguments
();
$printer
=
$this
->
getPrinter
();
if
(
!
$this
->
_requireEntityManager
())
{
return
false
;
}
if
(
array_key_exists
(
're-create'
,
$args
))
{
$args
[
'drop'
]
=
true
;
$args
[
'create'
]
=
true
;
...
...
@@ -130,7 +126,8 @@ class SchemaToolTask extends AbstractTask
return
false
;
}
$metadataDriver
=
$this
->
_em
->
getConfiguration
()
->
getMetadataDriverImpl
();
$metadataDriver
=
$this
->
getEntityManager
()
->
getConfiguration
()
->
getMetadataDriverImpl
();
if
(
$metadataDriver
instanceof
\Doctrine\ORM\Mapping\Driver\AnnotationDriver
)
{
if
(
!
isset
(
$args
[
'class-dir'
]))
{
$printer
->
writeln
(
"The supplied configuration uses the annotation metadata driver."
...
...
@@ -155,23 +152,26 @@ class SchemaToolTask extends AbstractTask
$isDrop
=
isset
(
$args
[
'drop'
]);
$isUpdate
=
isset
(
$args
[
'update'
]);
$cmf
=
$this
->
_em
->
getMetadataFactory
();
$driver
=
$this
->
_em
->
getConfiguration
()
->
getMetadataDriverImpl
();
$em
=
$this
->
getEntityManager
();
$cmf
=
$em
->
getMetadataFactory
();
$driver
=
$em
->
getConfiguration
()
->
getMetadataDriverImpl
();
$classes
=
array
();
$preloadedClasses
=
$driver
->
preload
(
true
);
foreach
(
$preloadedClasses
as
$className
)
{
$classes
[]
=
$cmf
->
getMetadataFor
(
$className
);
}
$printer
=
$this
->
getPrinter
();
$tool
=
new
SchemaTool
(
$this
->
_em
);
if
(
empty
(
$classes
))
{
$printer
->
writeln
(
'No classes to process.'
,
'INFO'
);
return
;
}
$tool
=
new
SchemaTool
(
$em
);
if
(
$isDrop
)
{
if
(
isset
(
$args
[
'dump-sql'
]))
{
foreach
(
$tool
->
getDropSchemaSql
(
$classes
)
as
$sql
)
{
...
...
lib/Doctrine/ORM/Tools/Cli/Tasks/VersionTask.php
View file @
49bcc69f
...
...
@@ -77,6 +77,6 @@ class VersionTask extends AbstractTask
*/
public
function
run
()
{
$this
->
getPrinter
()
->
writeln
(
'You are currently running Doctrine 2.0.0 Alpha
1
'
,
'INFO'
);
$this
->
getPrinter
()
->
writeln
(
'You are currently running Doctrine 2.0.0 Alpha
3
'
,
'INFO'
);
}
}
\ No newline at end of file
tools/sandbox/cli-config.php
View file @
49bcc69f
...
...
@@ -33,7 +33,9 @@ $connectionOptions = array(
'path'
=>
'database.sqlite'
);
// These are required named variables (names can't change!)
$em
=
\Doctrine\ORM\EntityManager
::
create
(
$connectionOptions
,
$config
);
$args
=
array
(
$globalArguments
=
array
(
'class-dir'
=>
'./Entities'
);
\ 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