Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow newer propel betas #16

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
211 changes: 74 additions & 137 deletions Command/AbstractCommand.php

Large diffs are not rendered by default.

136 changes: 0 additions & 136 deletions Command/AclInitCommand.php

This file was deleted.

10 changes: 6 additions & 4 deletions Command/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Propel\Bundle\PropelBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -19,12 +19,12 @@
/**
* @author Kévin Gomez <[email protected]>
*/
class BuildCommand extends ContainerAwareCommand
class BuildCommand extends Command
{
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this
->setName('propel:build')
Expand All @@ -44,7 +44,7 @@ protected function configure()
*
* @throws \InvalidArgumentException When the target directory does not exist
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
if (!$input->getOption('sql')) {
$in = new ArrayInput(array(
Expand Down Expand Up @@ -76,5 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$cmd = $this->getApplication()->find('propel:sql:insert');
$cmd->run($in, $output);
}

return 0;
}
}
22 changes: 6 additions & 16 deletions Command/BundleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,17 @@
*/
trait BundleTrait
{
/**
* @return ContainerInterface
*/
protected abstract function getContainer();
abstract protected function getContainer(): ContainerInterface;

/**
* Returns the selected bundle.
* If no bundle argument is set, the user will get ask for it.
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @return BundleInterface
*/
protected function getBundle(InputInterface $input, OutputInterface $output)
protected function getBundle(InputInterface $input, OutputInterface $output): BundleInterface
{
$kernel = $this
->getContainer()
->get('kernel');
$kernel = $this->getContainer()->get('kernel');

if ($input->hasArgument('bundle') && '@' === substr($input->getArgument('bundle'), 0, 1)) {
if ($input->hasArgument('bundle') && str_starts_with($input->getArgument('bundle'), '@')) {
return $kernel->getBundle(substr($input->getArgument('bundle'), 1));
}

Expand All @@ -54,12 +44,12 @@ protected function getBundle(InputInterface $input, OutputInterface $output)

$bundleName = $this->getHelperSet()->get('question')->ask($input, $output, $question);

if (in_array($bundleName, $bundleNames)) {
if (in_array($bundleName, $bundleNames, true)) {
break;
}
$output->writeln(sprintf('<bg=red>Bundle "%s" does not exist.</bg>', $bundleName));
} while (true);

return $kernel->getBundle($bundleName);
}
}
}
22 changes: 11 additions & 11 deletions Command/DatabaseCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Propel\Runtime\Connection\ConnectionManagerSingle;
use Propel\Runtime\Propel;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -27,7 +28,7 @@ class DatabaseCreateCommand extends AbstractCommand
/**
* @see Command
*/
protected function configure()
protected function configure(): void
{
$this
->setName('propel:database:create')
Expand All @@ -42,43 +43,42 @@ protected function configure()
*
* @throws \InvalidArgumentException When the target directory does not exist
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$connectionName = $input->getOption('connection') ?: $this->getDefaultConnection();
$config = $this->getConnectionData($connectionName);
$dbName = $this->parseDbName($config['dsn']);

if (null === $dbName) {
return $output->writeln('<error>No database name found.</error>');
} else {
$query = 'CREATE DATABASE '. $dbName .';';
$output->writeln('<error>No database name found.</error>');
return 1;
}

$manager = new ConnectionManagerSingle();
$manager = new ConnectionManagerSingle($connectionName);
$manager->setConfiguration($this->getTemporaryConfiguration($config));

$serviceContainer = Propel::getServiceContainer();
$serviceContainer->setAdapterClass($connectionName, $config['adapter']);
$serviceContainer->setConnectionManager($connectionName, $manager);
$serviceContainer->setConnectionManager($manager);

$connection = Propel::getConnection($connectionName);

$query = 'CREATE DATABASE '. $dbName .';';
$statement = $connection->prepare($query);
$statement->execute();

$output->writeln(sprintf('<info>Database <comment>%s</comment> has been created.</info>', $dbName));

return 0;
}

/**
* Create a temporary configuration to connect to the database in order
* to create a given database. This idea comes from Doctrine1.
*
* @see https://github.com/doctrine/doctrine1/blob/master/lib/Doctrine/Connection.php#L1491
*
* @param array $config A Propel connection configuration.
* @return array
*/
private function getTemporaryConfiguration($config)
private function getTemporaryConfiguration(array $config): array
{
$dbName = $this->parseDbName($config['dsn']);

Expand Down
30 changes: 14 additions & 16 deletions Command/DatabaseDropCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Propel\Bundle\PropelBundle\Command;

use Propel\Runtime\Propel;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -27,7 +28,7 @@ class DatabaseDropCommand extends AbstractCommand
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this
->setName('propel:database:drop')
Expand All @@ -51,61 +52,58 @@ protected function configure()
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
if (!$input->getOption('force')) {
$output->writeln('<error>You have to use the "--force" option to drop the database.</error>');

return;
return 1;
}

if ('prod' === $this->getApplication()->getKernel()->getEnvironment()) {
if ('prod' === $this->getKernel()->getEnvironment()) {
$this->writeSection($output, 'WARNING: you are about to drop a database in production !', 'bg=red;fg=white');

if (false === $this->askConfirmation($input, $output, 'Are you sure ? (y/n) ', false)) {
$output->writeln('Aborted, nice decision !');

return -2;
return 1;
}
}

$connectionName = $input->getOption('connection') ?: $this->getDefaultConnection();
$config = $this->getConnectionData($connectionName);
$connection = Propel::getConnection($connectionName);
$dbName = $this->parseDbName($config['dsn']);

if (null === $dbName) {
return $output->writeln('<error>No database name found.</error>');
} else {
$query = 'DROP DATABASE '. $dbName .';';
$output->writeln('<error>No database name found.</error>');
return 1;
}


$manager = new ConnectionManagerSingle();
$manager = new ConnectionManagerSingle($connectionName);
$manager->setConfiguration($this->getTemporaryConfiguration($config));

$serviceContainer = Propel::getServiceContainer();
$serviceContainer->setAdapterClass($connectionName, $config['adapter']);
$serviceContainer->setConnectionManager($connectionName, $manager);
$serviceContainer->setConnectionManager($manager);

$connection = Propel::getConnection($connectionName);

$query = 'DROP DATABASE '. $dbName .';';
$statement = $connection->prepare($query);
$statement->execute();

$output->writeln(sprintf('<info>Database <comment>%s</comment> has been dropped.</info>', $dbName));

return 0;
}

/**
* Create a temporary configuration to connect to the database in order
* to create a given database. This idea comes from Doctrine1.
*
* @see https://github.com/doctrine/doctrine1/blob/master/lib/Doctrine/Connection.php#L1491
*
* @param array $config A Propel connection configuration.
* @return array
*/
private function getTemporaryConfiguration($config)
private function getTemporaryConfiguration(array $config): array
{
$dbName = $this->parseDbName($config['dsn']);

Expand Down
Loading
Loading