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
a7d07fcd
Commit
a7d07fcd
authored
Apr 10, 2010
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DDC-502, DDC-507 - Refactored SchemaTool Commands
parent
cb616956
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
139 additions
and
164 deletions
+139
-164
AbstractCommand.php
.../ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php
+88
-0
CreateCommand.php
...ne/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php
+11
-54
DropCommand.php
...rine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php
+11
-54
UpdateCommand.php
...ne/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php
+12
-55
EntityManagerHelper.php
...Doctrine/ORM/Tools/Console/Helper/EntityManagerHelper.php
+17
-1
No files found.
lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php
0 → 100644
View file @
a7d07fcd
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace
Doctrine\ORM\Tools\Console\Command\SchemaTool
;
use
Symfony\Components\Console\Input\InputArgument
,
Symfony\Components\Console\Input\InputOption
,
Symfony\Components\Console\Input\InputInterface
,
Symfony\Components\Console\Output\OutputInterface
,
Symfony\Components\Console\Command\Command
,
Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper
,
Doctrine\ORM\Tools\SchemaTool
;
abstract
class
AbstractCommand
extends
Command
{
/**
* @param InputInterface $input
* @param OutputInterface $output
* @param SchemaTool $schemaTool
* @param array $metadatas
*/
abstract
protected
function
executeSchemaCommand
(
InputInterface
$input
,
OutputInterface
$output
,
SchemaTool
$schemaTool
,
array
$metadatas
);
/**
* @see Console\Command\Command
*/
protected
function
execute
(
InputInterface
$input
,
OutputInterface
$output
)
{
$emHelper
=
$this
->
getHelper
(
'em'
);
/* @var $em \Doctrine\ORM\EntityManager */
$em
=
$emHelper
->
getEntityManager
();
$reader
=
new
\Doctrine\ORM\Tools\ClassMetadataReader
();
$reader
->
setEntityManager
(
$em
);
$reader
->
addMappingSource
(
$em
->
getConfiguration
()
->
getMetadataDriverImpl
());
// Process source directories
if
(
$emHelper
->
hasAdditionalMappingPathInformation
())
{
foreach
(
$emHelper
->
getMappingPaths
()
as
$dirName
)
{
$dirName
=
realpath
(
$dirName
);
if
(
!
file_exists
(
$dirName
))
{
throw
new
\InvalidArgumentException
(
sprintf
(
"Mapping directory '<info>%s</info>' does not exist."
,
$dirName
)
);
}
else
if
(
!
is_readable
(
$dirName
))
{
throw
new
\InvalidArgumentException
(
sprintf
(
"Mapping directory '<info>%s</info>' does not have read permissions."
,
$dirName
)
);
}
$reader
->
addMappingSource
(
$dirName
);
}
}
// Retrieving ClassMetadatas
$metadatas
=
$reader
->
getMetadatas
();
if
(
!
empty
(
$metadatas
))
{
// Create SchemaTool
$tool
=
new
\Doctrine\ORM\Tools\SchemaTool
(
$em
);
$this
->
executeSchemaCommand
(
$input
,
$output
,
$tool
,
$metadatas
);
}
else
{
$output
->
write
(
'No Metadata Classes to process.'
.
PHP_EOL
);
}
}
}
\ No newline at end of file
lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php
View file @
a7d07fcd
...
@@ -23,7 +23,9 @@ namespace Doctrine\ORM\Tools\Console\Command\SchemaTool;
...
@@ -23,7 +23,9 @@ namespace Doctrine\ORM\Tools\Console\Command\SchemaTool;
use
Symfony\Components\Console\Input\InputArgument
,
use
Symfony\Components\Console\Input\InputArgument
,
Symfony\Components\Console\Input\InputOption
,
Symfony\Components\Console\Input\InputOption
,
Symfony\Components\Console
;
Symfony\Components\Console\Input\InputInterface
,
Symfony\Components\Console\Output\OutputInterface
,
Doctrine\ORM\Tools\SchemaTool
;
/**
/**
* Command to create the database schema for a set of classes based on their mappings.
* Command to create the database schema for a set of classes based on their mappings.
...
@@ -37,7 +39,7 @@ use Symfony\Components\Console\Input\InputArgument,
...
@@ -37,7 +39,7 @@ use Symfony\Components\Console\Input\InputArgument,
* @author Jonathan Wage <jonwage@gmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
* @author Roman Borschel <roman@code-factory.org>
*/
*/
class
CreateCommand
extends
Console\Command\
Command
class
CreateCommand
extends
Abstract
Command
{
{
/**
/**
* @see Console\Command\Command
* @see Console\Command\Command
...
@@ -50,14 +52,6 @@ class CreateCommand extends Console\Command\Command
...
@@ -50,14 +52,6 @@ class CreateCommand extends Console\Command\Command
'Processes the schema and either create it directly on EntityManager Storage Connection or generate the SQL output.'
'Processes the schema and either create it directly on EntityManager Storage Connection or generate the SQL output.'
)
)
->
setDefinition
(
array
(
->
setDefinition
(
array
(
new
InputArgument
(
'from-path'
,
InputArgument
::
REQUIRED
,
'The path of mapping information.'
),
new
InputOption
(
'from'
,
null
,
InputOption
::
PARAMETER_REQUIRED
|
InputOption
::
PARAMETER_IS_ARRAY
,
'Optional paths of mapping information.'
,
array
()
),
new
InputOption
(
new
InputOption
(
'dump-sql'
,
null
,
InputOption
::
PARAMETER_NONE
,
'dump-sql'
,
null
,
InputOption
::
PARAMETER_NONE
,
'Instead of try to apply generated SQLs into EntityManager Storage Connection, output them.'
'Instead of try to apply generated SQLs into EntityManager Storage Connection, output them.'
...
@@ -69,52 +63,15 @@ EOT
...
@@ -69,52 +63,15 @@ EOT
);
);
}
}
/**
protected
function
executeSchemaCommand
(
InputInterface
$input
,
OutputInterface
$output
,
SchemaTool
$schemaTool
,
array
$metadatas
)
* @see Console\Command\Command
*/
protected
function
execute
(
Console\Input\InputInterface
$input
,
Console\Output\OutputInterface
$output
)
{
{
$em
=
$this
->
getHelper
(
'em'
)
->
getEntityManager
();
if
(
$input
->
getOption
(
'dump-sql'
)
===
true
)
{
$sqls
=
$schemaTool
->
getCreateSchemaSql
(
$metadatas
);
$reader
=
new
\Doctrine\ORM\Tools\ClassMetadataReader
();
$output
->
write
(
implode
(
';'
.
PHP_EOL
,
$sqls
)
.
PHP_EOL
);
$reader
->
setEntityManager
(
$em
);
// Process source directories
$fromPaths
=
array_merge
(
array
(
$input
->
getArgument
(
'from-path'
)),
$input
->
getOption
(
'from'
));
foreach
(
$fromPaths
as
$dirName
)
{
$dirName
=
realpath
(
$dirName
);
if
(
!
file_exists
(
$dirName
))
{
throw
new
\InvalidArgumentException
(
sprintf
(
"Mapping directory '<info>%s</info>' does not exist."
,
$dirName
)
);
}
else
if
(
!
is_readable
(
$dirName
))
{
throw
new
\InvalidArgumentException
(
sprintf
(
"Mapping directory '<info>%s</info>' does not have read permissions."
,
$dirName
)
);
}
$reader
->
addMappingSource
(
$dirName
);
}
// Retrieving ClassMetadatas
$metadatas
=
$reader
->
getMetadatas
();
if
(
!
empty
(
$metadatas
))
{
// Create SchemaTool
$tool
=
new
\Doctrine\ORM\Tools\SchemaTool
(
$em
);
if
(
$input
->
getOption
(
'dump-sql'
)
===
null
)
{
$sqls
=
$tool
->
getCreateSchemaSql
(
$metadatas
);
$output
->
write
(
implode
(
';'
.
PHP_EOL
,
$sqls
));
}
else
{
$output
->
write
(
'Creating database schema...'
.
PHP_EOL
);
$tool
->
createSchema
(
$metadatas
);
$output
->
write
(
'Database schema created successfully!'
.
PHP_EOL
);
}
}
else
{
}
else
{
$output
->
write
(
'No Metadata Classes to process.'
.
PHP_EOL
);
$output
->
write
(
'Creating database schema...'
.
PHP_EOL
);
$schemaTool
->
createSchema
(
$metadatas
);
$output
->
write
(
'Database schema created successfully!'
.
PHP_EOL
);
}
}
}
}
}
}
\ No newline at end of file
lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php
View file @
a7d07fcd
...
@@ -23,7 +23,9 @@ namespace Doctrine\ORM\Tools\Console\Command\SchemaTool;
...
@@ -23,7 +23,9 @@ namespace Doctrine\ORM\Tools\Console\Command\SchemaTool;
use
Symfony\Components\Console\Input\InputArgument
,
use
Symfony\Components\Console\Input\InputArgument
,
Symfony\Components\Console\Input\InputOption
,
Symfony\Components\Console\Input\InputOption
,
Symfony\Components\Console
;
Symfony\Components\Console\Input\InputInterface
,
Symfony\Components\Console\Output\OutputInterface
,
Doctrine\ORM\Tools\SchemaTool
;
/**
/**
* Command to drop the database schema for a set of classes based on their mappings.
* Command to drop the database schema for a set of classes based on their mappings.
...
@@ -37,7 +39,7 @@ use Symfony\Components\Console\Input\InputArgument,
...
@@ -37,7 +39,7 @@ use Symfony\Components\Console\Input\InputArgument,
* @author Jonathan Wage <jonwage@gmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
* @author Roman Borschel <roman@code-factory.org>
*/
*/
class
DropCommand
extends
Console\Command\
Command
class
DropCommand
extends
Abstract
Command
{
{
/**
/**
* @see Console\Command\Command
* @see Console\Command\Command
...
@@ -50,14 +52,6 @@ class DropCommand extends Console\Command\Command
...
@@ -50,14 +52,6 @@ class DropCommand extends Console\Command\Command
'Processes the schema and either drop the database schema of EntityManager Storage Connection or generate the SQL output.'
'Processes the schema and either drop the database schema of EntityManager Storage Connection or generate the SQL output.'
)
)
->
setDefinition
(
array
(
->
setDefinition
(
array
(
new
InputArgument
(
'from-path'
,
InputArgument
::
REQUIRED
,
'The path of mapping information.'
),
new
InputOption
(
'from'
,
null
,
InputOption
::
PARAMETER_REQUIRED
|
InputOption
::
PARAMETER_IS_ARRAY
,
'Optional paths of mapping information.'
,
array
()
),
new
InputOption
(
new
InputOption
(
'dump-sql'
,
null
,
InputOption
::
PARAMETER_NONE
,
'dump-sql'
,
null
,
InputOption
::
PARAMETER_NONE
,
'Instead of try to apply generated SQLs into EntityManager Storage Connection, output them.'
'Instead of try to apply generated SQLs into EntityManager Storage Connection, output them.'
...
@@ -70,52 +64,15 @@ EOT
...
@@ -70,52 +64,15 @@ EOT
);
);
}
}
/**
protected
function
executeSchemaCommand
(
InputInterface
$input
,
OutputInterface
$output
,
SchemaTool
$schemaTool
,
array
$metadatas
)
* @see Console\Command\Command
*/
protected
function
execute
(
Console\Input\InputInterface
$input
,
Console\Output\OutputInterface
$output
)
{
{
$em
=
$this
->
getHelper
(
'em'
)
->
getEntityManager
();
if
(
$input
->
getOption
(
'dump-sql'
)
===
true
)
{
$sqls
=
$schemaTool
->
getDropSchemaSql
(
$metadatas
);
$reader
=
new
\Doctrine\ORM\Tools\ClassMetadataReader
();
$output
->
write
(
implode
(
';'
.
PHP_EOL
,
$sqls
)
.
PHP_EOL
);
$reader
->
setEntityManager
(
$em
);
// Process source directories
$fromPaths
=
array_merge
(
array
(
$input
->
getArgument
(
'from-path'
)),
$input
->
getOption
(
'from'
));
foreach
(
$fromPaths
as
$dirName
)
{
$dirName
=
realpath
(
$dirName
);
if
(
!
file_exists
(
$dirName
))
{
throw
new
\InvalidArgumentException
(
sprintf
(
"Mapping directory '<info>%s</info>' does not exist."
,
$dirName
)
);
}
else
if
(
!
is_readable
(
$dirName
))
{
throw
new
\InvalidArgumentException
(
sprintf
(
"Mapping directory '<info>%s</info>' does not have read permissions."
,
$dirName
)
);
}
$reader
->
addMappingSource
(
$dirName
);
}
// Retrieving ClassMetadatas
$metadatas
=
$reader
->
getMetadatas
();
if
(
!
empty
(
$metadatas
))
{
// Create SchemaTool
$tool
=
new
\Doctrine\ORM\Tools\SchemaTool
(
$em
);
if
(
$input
->
getOption
(
'dump-sql'
)
===
null
)
{
$sqls
=
$tool
->
getDropSchemaSql
(
$metadatas
);
$output
->
write
(
implode
(
';'
.
PHP_EOL
,
$sqls
));
}
else
{
$output
->
write
(
'Dropping database schema...'
.
PHP_EOL
);
$tool
->
dropSchema
(
$metadatas
);
$output
->
write
(
'Database schema dropped successfully!'
.
PHP_EOL
);
}
}
else
{
}
else
{
$output
->
write
(
'No Metadata Classes to process.'
.
PHP_EOL
);
$output
->
write
(
'Dropping database schema...'
.
PHP_EOL
);
$schemaTool
->
dropSchema
(
$metadatas
);
$output
->
write
(
'Database schema dropped successfully!'
.
PHP_EOL
);
}
}
}
}
}
}
\ No newline at end of file
lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php
View file @
a7d07fcd
...
@@ -23,7 +23,9 @@ namespace Doctrine\ORM\Tools\Console\Command\SchemaTool;
...
@@ -23,7 +23,9 @@ namespace Doctrine\ORM\Tools\Console\Command\SchemaTool;
use
Symfony\Components\Console\Input\InputArgument
,
use
Symfony\Components\Console\Input\InputArgument
,
Symfony\Components\Console\Input\InputOption
,
Symfony\Components\Console\Input\InputOption
,
Symfony\Components\Console
;
Symfony\Components\Console\Input\InputInterface
,
Symfony\Components\Console\Output\OutputInterface
,
Doctrine\ORM\Tools\SchemaTool
;
/**
/**
* Command to update the database schema for a set of classes based on their mappings.
* Command to update the database schema for a set of classes based on their mappings.
...
@@ -37,7 +39,7 @@ use Symfony\Components\Console\Input\InputArgument,
...
@@ -37,7 +39,7 @@ use Symfony\Components\Console\Input\InputArgument,
* @author Jonathan Wage <jonwage@gmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
* @author Roman Borschel <roman@code-factory.org>
*/
*/
class
UpdateCommand
extends
Console\Command\
Command
class
UpdateCommand
extends
Abstract
Command
{
{
/**
/**
* @see Console\Command\Command
* @see Console\Command\Command
...
@@ -50,14 +52,6 @@ class UpdateCommand extends Console\Command\Command
...
@@ -50,14 +52,6 @@ class UpdateCommand extends Console\Command\Command
'Processes the schema and either update the database schema of EntityManager Storage Connection or generate the SQL output.'
'Processes the schema and either update the database schema of EntityManager Storage Connection or generate the SQL output.'
)
)
->
setDefinition
(
array
(
->
setDefinition
(
array
(
new
InputArgument
(
'from-path'
,
InputArgument
::
REQUIRED
,
'The path of mapping information.'
),
new
InputOption
(
'from'
,
null
,
InputOption
::
PARAMETER_REQUIRED
|
InputOption
::
PARAMETER_IS_ARRAY
,
'Optional paths of mapping information.'
,
array
()
),
new
InputOption
(
new
InputOption
(
'complete'
,
null
,
InputOption
::
PARAMETER_NONE
,
'complete'
,
null
,
InputOption
::
PARAMETER_NONE
,
'If defined, all assets of the database which are not relevant to the current metadata will be dropped.'
'If defined, all assets of the database which are not relevant to the current metadata will be dropped.'
...
@@ -75,55 +69,18 @@ EOT
...
@@ -75,55 +69,18 @@ EOT
);
);
}
}
/**
protected
function
executeSchemaCommand
(
InputInterface
$input
,
OutputInterface
$output
,
SchemaTool
$schemaTool
,
array
$metadatas
)
* @see Console\Command\Command
*/
protected
function
execute
(
Console\Input\InputInterface
$input
,
Console\Output\OutputInterface
$output
)
{
{
$em
=
$this
->
getHelper
(
'em'
)
->
getEntityManager
();
$reader
=
new
\Doctrine\ORM\Tools\ClassMetadataReader
();
$reader
->
setEntityManager
(
$em
);
// Process source directories
$fromPaths
=
array_merge
(
array
(
$input
->
getArgument
(
'from-path'
)),
$input
->
getOption
(
'from'
));
foreach
(
$fromPaths
as
$dirName
)
{
$dirName
=
realpath
(
$dirName
);
if
(
!
file_exists
(
$dirName
))
{
throw
new
\InvalidArgumentException
(
sprintf
(
"Mapping directory '<info>%s</info>' does not exist."
,
$dirName
)
);
}
else
if
(
!
is_readable
(
$dirName
))
{
throw
new
\InvalidArgumentException
(
sprintf
(
"Mapping directory '<info>%s</info>' does not have read permissions."
,
$dirName
)
);
}
$reader
->
addMappingSource
(
$dirName
);
}
// Defining if update is complete or not (--complete not defined means $saveMode = true)
// Defining if update is complete or not (--complete not defined means $saveMode = true)
$saveMode
=
(
$input
->
getOption
(
'complete'
)
===
null
);
$saveMode
=
(
$input
->
getOption
(
'complete'
)
===
true
);
// Retrieving ClassMetadatas
$metadatas
=
$reader
->
getMetadatas
();
if
(
!
empty
(
$metadatas
))
{
// Create SchemaTool
$tool
=
new
\Doctrine\ORM\Tools\SchemaTool
(
$em
);
if
(
$input
->
getOption
(
'dump-sql'
)
===
null
)
{
if
(
$input
->
getOption
(
'dump-sql'
)
===
true
)
{
$sqls
=
$tool
->
getUpdateSchemaSql
(
$metadatas
,
$saveMode
);
$sqls
=
$schemaTool
->
getUpdateSchemaSql
(
$metadatas
,
$saveMode
);
$output
->
write
(
implode
(
';'
.
PHP_EOL
,
$sqls
));
$output
->
write
(
implode
(
';'
.
PHP_EOL
,
$sqls
)
.
PHP_EOL
);
}
else
{
$output
->
write
(
'Updating database schema...'
.
PHP_EOL
);
$tool
->
updateSchema
(
$metadatas
,
$saveMode
);
$output
->
write
(
'Database schema updated successfully!'
.
PHP_EOL
);
}
}
else
{
}
else
{
$output
->
write
(
'No Metadata Classes to process.'
.
PHP_EOL
);
$output
->
write
(
'Updating database schema...'
.
PHP_EOL
);
$schemaTool
->
updateSchema
(
$metadatas
,
$saveMode
);
$output
->
write
(
'Database schema updated successfully!'
.
PHP_EOL
);
}
}
}
}
}
}
\ No newline at end of file
lib/Doctrine/ORM/Tools/Console/Helper/EntityManagerHelper.php
View file @
a7d07fcd
...
@@ -44,14 +44,20 @@ class EntityManagerHelper extends Helper
...
@@ -44,14 +44,20 @@ class EntityManagerHelper extends Helper
*/
*/
protected
$_em
;
protected
$_em
;
/**
* @var array
*/
protected
$_mappingPaths
=
array
();
/**
/**
* Constructor
* Constructor
*
*
* @param Connection $connection Doctrine Database Connection
* @param Connection $connection Doctrine Database Connection
*/
*/
public
function
__construct
(
EntityManager
$em
)
public
function
__construct
(
EntityManager
$em
,
$mappingPaths
=
array
()
)
{
{
$this
->
_em
=
$em
;
$this
->
_em
=
$em
;
$this
->
_mappingPaths
=
$mappingPaths
;
}
}
/**
/**
...
@@ -64,6 +70,16 @@ class EntityManagerHelper extends Helper
...
@@ -64,6 +70,16 @@ class EntityManagerHelper extends Helper
return
$this
->
_em
;
return
$this
->
_em
;
}
}
public
function
hasAdditionalMappingPathInformation
()
{
return
count
(
$this
->
_mappingPaths
);
}
public
function
getMappingPaths
()
{
return
$this
->
_mappingPaths
;
}
/**
/**
* @see Helper
* @see Helper
*/
*/
...
...
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