Merge branch 'maxailloud_all'
This commit is contained in:
commit
2b3e2f0b3f
|
@ -43,10 +43,11 @@ class DatabaseCreateCommand extends PhingCommand
|
|||
\Propel::setConfiguration($this->getTemporaryConfiguration($name, $config));
|
||||
$connection = \Propel::getConnection();
|
||||
|
||||
$statement = $connection->prepare($query);
|
||||
$statement = $connection->prepare($query);
|
||||
$statement->execute();
|
||||
|
||||
$output->writeln(sprintf('<info><comment>%s</comment> has been created.</info>', $dbName));
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln(sprintf('<error>An error has occured: %s</error>', $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,9 +25,9 @@ class DatabaseDropCommand extends PhingCommand
|
|||
->addOption('force', null, InputOption::VALUE_NONE, 'Set this parameter to execute this action.')
|
||||
->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'Set this parameter to define a connection to use')
|
||||
->setHelp(<<<EOT
|
||||
The <info>propel:database:drop</info> command will drop your database.</comment>.
|
||||
The <info>propel:database:drop</info> command will drop your database.
|
||||
|
||||
<info>php app/console propel:insert-sql</info>
|
||||
<info>php app/console propel:database:drop</info>
|
||||
|
||||
The <info>--force</info> parameter has to be used to actually drop the database.
|
||||
The <info>--connection</info> parameter allows you to change the connection to use.
|
||||
|
@ -47,6 +47,7 @@ EOT
|
|||
if ($input->getOption('force')) {
|
||||
if ('prod' === $this->getApplication()->getKernel()->getEnvironment()) {
|
||||
$this->writeSection($output, 'WARNING: you are about to drop a database in production !', 'bg=red;fg=white');
|
||||
|
||||
if (false === $this->askConfirmation($output, 'Are you sure ? (y/n) ', false)) {
|
||||
$output->writeln('Aborted, nice decision !');
|
||||
return -2;
|
||||
|
@ -63,8 +64,9 @@ EOT
|
|||
$connection = \Propel::getConnection($name);
|
||||
$statement = $connection->prepare($query);
|
||||
$statement->execute();
|
||||
|
||||
$output->writeln(sprintf('<info><comment>%s</comment> has been dropped.</info>', $dbName));
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln(sprintf('<error>An error has occured: %s</error>', $e->getMessage()));
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -11,7 +11,7 @@ use Symfony\Component\Finder\Finder;
|
|||
use Symfony\Component\HttpKernel\Util\Filesystem;
|
||||
|
||||
/**
|
||||
* LoadFixturesCommand : loads XML fixtures files.
|
||||
* LoadFixturesCommand
|
||||
*
|
||||
* @author William DURAND <william.durand1@gmail.com>
|
||||
*/
|
||||
|
@ -21,12 +21,10 @@ class LoadFixturesCommand extends PhingCommand
|
|||
* Default fixtures directory.
|
||||
*/
|
||||
private $defaultFixturesDir = 'propel/fixtures';
|
||||
|
||||
/**
|
||||
* Absolute path for fixtures directory
|
||||
*/
|
||||
private $absoluteFixturesPath = '';
|
||||
|
||||
/**
|
||||
* Filesystem for manipulating files
|
||||
*/
|
||||
|
@ -38,10 +36,10 @@ class LoadFixturesCommand extends PhingCommand
|
|||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setDescription('Load fixtures')
|
||||
->setDescription('Load XML fixtures')
|
||||
->addOption('dir', 'd', InputOption::VALUE_OPTIONAL, 'The directory where XML or/and SQL fixtures files are located', $this->defaultFixturesDir)
|
||||
->addOption('xml', '', InputOption::VALUE_NONE, 'Load xml fixtures')
|
||||
->addOption('sql', '', InputOption::VALUE_NONE, 'Load sql fixtures')
|
||||
->addOption('xml', '', InputOption::VALUE_NONE, 'Load XML fixtures')
|
||||
->addOption('sql', '', InputOption::VALUE_NONE, 'Load SQL fixtures')
|
||||
->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'Set this parameter to define a connection to use')
|
||||
->setHelp(<<<EOT
|
||||
The <info>propel:load-fixtures</info> loads <info>XML</info> and/or <info>SQL</info> fixtures.
|
||||
|
@ -56,8 +54,8 @@ The <info>--dir</info> parameter allows you to change the directory that contain
|
|||
The <info>--xml</info> parameter allows you to load only <info>XML</info> fixtures.
|
||||
The <info>--sql</info> parameter allows you to load only <info>SQL</info> fixtures.
|
||||
|
||||
You can mix <info>--xml</info> parameter and <info>--sql</info> parameter to load XML and SQL fixtures.
|
||||
If none of this parameter are set all files, XML and SQL, in the directory will be load.
|
||||
You can mix <info>--xml</info> and <info>--sql</info> parameters to load both XML and SQL fixtures.
|
||||
If none of this parameter is set, all XML and SQL files in the directory will be load.
|
||||
|
||||
XML fixtures files are the same XML files you can get with the command <info>propel:data-dump</info>:
|
||||
<comment>
|
||||
|
@ -113,6 +111,7 @@ EOT
|
|||
// Create a "datadb.map" file
|
||||
$datadbContent = '';
|
||||
$datas = $finder->name('*.xml')->in($this->absoluteFixturesPath);
|
||||
|
||||
foreach($datas as $data) {
|
||||
$output->writeln(sprintf('Loaded fixtures from <comment>%s</comment>.', $data));
|
||||
|
||||
|
@ -139,7 +138,6 @@ EOT
|
|||
$insertCommand->execute($input, $output);
|
||||
|
||||
$this->removeTemporaryFiles();
|
||||
|
||||
$this->filesystem->remove($datadbFile);
|
||||
}
|
||||
|
||||
|
@ -161,7 +159,6 @@ EOT
|
|||
$datas = $finder->name('*.sql')->in($this->absoluteFixturesPath);
|
||||
foreach($datas as $data) {
|
||||
$output->writeln(sprintf('Loaded fixtures from <comment>%s</comment>.', $data));
|
||||
|
||||
$sqldbContent .= $data->getFilename() . '=default' . PHP_EOL;
|
||||
}
|
||||
|
||||
|
|
|
@ -214,7 +214,7 @@ EOT
|
|||
'%dsn%' => $datasource['connection']['dsn'],
|
||||
'%username%' => $datasource['connection']['user'],
|
||||
'%password%' => $datasource['connection']['password'],
|
||||
'%charset%' => $container->getParameter('propel.charset'),
|
||||
'%charset%' => $datasource['connection']['settings']['charset']['value'],
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -330,8 +330,9 @@ EOT;
|
|||
*/
|
||||
protected function checkConfiguration()
|
||||
{
|
||||
$parameters = $this->getContainer()->get('propel.configuration')->getParameters();
|
||||
if (!isset($parameters['datasources']) ||0 === count($parameters['datasources'])) {
|
||||
$parameters = $this->container->get('propel.configuration')->getParameters();
|
||||
|
||||
if (!isset($parameters['datasources']) || 0 === count($parameters['datasources'])) {
|
||||
throw new \RuntimeException('Propel should be configured (no database configuration found).');
|
||||
}
|
||||
}
|
||||
|
|
110
Command/TableDropCommand.php
Normal file
110
Command/TableDropCommand.php
Normal file
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
|
||||
namespace Propel\PropelBundle\Command;
|
||||
|
||||
use Propel\PropelBundle\Command\PhingCommand;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
/**
|
||||
* TableDropCommand class.
|
||||
* Useful to drop table in a database.
|
||||
*
|
||||
* @author Maxime AILLOUD
|
||||
*/
|
||||
class TableDropCommand extends PhingCommand
|
||||
{
|
||||
/**
|
||||
* @see Command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setDescription('Drop a given table or all tables in the database.')
|
||||
->addArgument('table', InputArgument::IS_ARRAY, 'Set this parameter to défine which table to delete (default all the table in the database.')
|
||||
->addOption('force', null, InputOption::VALUE_NONE, 'Set this parameter to execute this action.')
|
||||
->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'Set this parameter to define a connection to use')
|
||||
->setHelp(<<<EOT
|
||||
The <info>propel:table:drop</info> command will drop one or several table.
|
||||
|
||||
<info>php app/console propel:table:drop</info>
|
||||
|
||||
The <info>table</info> arguments define the list of table which has to be delete <comment>(default: all table)</comment>.
|
||||
The <info>--force</info> parameter has to be used to actually drop the table.
|
||||
The <info>--connection</info> parameter allows you to change the connection to use.
|
||||
The default connection is the active connection (propel.dbal.default_connection).
|
||||
EOT
|
||||
)
|
||||
->setName('propel:table:drop');
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Command
|
||||
*
|
||||
* @throws \InvalidArgumentException When the target directory does not exist
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$tablesToDelete = $input->getArgument('table');
|
||||
|
||||
if ($input->getOption('force')) {
|
||||
$nbTable = count($tablesToDelete);
|
||||
$tablePlural = (($nbTable > 1 || $nbTable == 0) ? 's' : '' );
|
||||
|
||||
if ('prod' === $this->getApplication()->getKernel()->getEnvironment()) {
|
||||
$this->writeSection($output, 'WARNING: you are about to drop ' . (count($input->getArgument('table')) ?: 'all') . ' table' . $tablePlural . ' in production !', 'bg=red;fg=white');
|
||||
|
||||
if (false === $this->askConfirmation($output, 'Are you sure ? (y/n) ', false)) {
|
||||
$output->writeln('Aborted, nice decision !');
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
$this->writeSection($output, '[Propel] You are running the command: propel:table:drop');
|
||||
|
||||
try {
|
||||
list($name, $config) = $this->getConnection($input, $output);
|
||||
$connection = \Propel::getConnection($name);
|
||||
|
||||
$showStatement = $connection->prepare('SHOW TABLES;');
|
||||
$showStatement->execute();
|
||||
|
||||
$allTables = $showStatement->fetchAll(\PDO::FETCH_COLUMN);
|
||||
|
||||
if ($nbTable) {
|
||||
foreach ($tablesToDelete as $tableToDelete) {
|
||||
if(!array_search($tableToDelete, $allTables)) {
|
||||
throw new \InvalidArgumentException(sprintf('Table %s doesn\'t exist in the database.', $tableToDelete));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$tablesToDelete = $allTables;
|
||||
}
|
||||
|
||||
$connection->exec('SET FOREIGN_KEY_CHECKS = 0;');
|
||||
|
||||
$tablesToDelete = join(', ', $tablesToDelete);
|
||||
|
||||
if ('' !== $tablesToDelete) {
|
||||
$connection->exec('DROP TABLE ' . $tablesToDelete . ' ;');
|
||||
|
||||
$output->writeln(sprintf('Table' . $tablePlural . ' <info><comment>%s</comment> has been dropped.</info>', $tablesToDelete));
|
||||
}
|
||||
else {
|
||||
$output->writeln('No table <info>has been dropped</info>');
|
||||
}
|
||||
|
||||
$connection->exec('SET FOREIGN_KEY_CHECKS = 1;');
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$output->writeln(sprintf('<error>An error has occured: %s</error>', $e->getMessage()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$output->writeln('<error>You have to use --force to drop some table.</error>');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,7 +20,7 @@ class PropelBundle extends Bundle
|
|||
require_once $this->container->getParameter('propel.path').'/runtime/lib/Propel.php';
|
||||
|
||||
if (0 === strncasecmp(PHP_SAPI, 'cli', 3)) {
|
||||
set_include_path($this->container->getParameter('propel.phing_path').'/classes'.PATH_SEPARATOR.get_include_path());
|
||||
set_include_path($this->container->getParameter('kernel.root_dir').'/..'.PATH_SEPARATOR.$this->container->getParameter('propel.phing_path').'/classes'.PATH_SEPARATOR.get_include_path());
|
||||
}
|
||||
|
||||
if (!\Propel::isInit()) {
|
||||
|
|
Loading…
Reference in a new issue