welcome back to dyb-tech
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Command;
|
||||
|
||||
use Doctrine\DBAL\DriverManager;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Throwable;
|
||||
|
||||
use function in_array;
|
||||
use function method_exists;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Database tool allows you to easily create your configured databases.
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class CreateDatabaseDoctrineCommand extends DoctrineCommand
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->setName('doctrine:database:create')
|
||||
->setDescription('Creates the configured database')
|
||||
->addOption('connection', 'c', InputOption::VALUE_OPTIONAL, 'The connection to use for this command')
|
||||
->addOption('if-not-exists', null, InputOption::VALUE_NONE, 'Don\'t trigger an error, when the database already exists')
|
||||
->setHelp(<<<'EOT'
|
||||
The <info>%command.name%</info> command creates the default connections database:
|
||||
|
||||
<info>php %command.full_name%</info>
|
||||
|
||||
You can also optionally specify the name of a connection to create the database for:
|
||||
|
||||
<info>php %command.full_name% --connection=default</info>
|
||||
EOT);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$connectionName = $input->getOption('connection');
|
||||
if (empty($connectionName)) {
|
||||
$connectionName = $this->getDoctrine()->getDefaultConnectionName();
|
||||
}
|
||||
|
||||
$connection = $this->getDoctrineConnection($connectionName);
|
||||
|
||||
$ifNotExists = $input->getOption('if-not-exists');
|
||||
|
||||
$params = $connection->getParams();
|
||||
|
||||
if (isset($params['primary'])) {
|
||||
$params = $params['primary'];
|
||||
}
|
||||
|
||||
$hasPath = isset($params['path']);
|
||||
$name = $hasPath ? $params['path'] : ($params['dbname'] ?? false);
|
||||
if (! $name) {
|
||||
throw new InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be created.");
|
||||
}
|
||||
|
||||
// Need to get rid of _every_ occurrence of dbname from connection configuration and we have already extracted all relevant info from url
|
||||
unset($params['dbname'], $params['path'], $params['url']);
|
||||
|
||||
$tmpConnection = DriverManager::getConnection($params, $connection->getConfiguration());
|
||||
|
||||
$schemaManager = method_exists($tmpConnection, 'createSchemaManager')
|
||||
? $tmpConnection->createSchemaManager()
|
||||
: $tmpConnection->getSchemaManager();
|
||||
$shouldNotCreateDatabase = $ifNotExists && in_array($name, $schemaManager->listDatabases());
|
||||
|
||||
// Only quote if we don't have a path
|
||||
if (! $hasPath) {
|
||||
$name = $tmpConnection->getDatabasePlatform()->quoteSingleIdentifier($name);
|
||||
}
|
||||
|
||||
$error = false;
|
||||
try {
|
||||
if ($shouldNotCreateDatabase) {
|
||||
$output->writeln(sprintf('<info>Database <comment>%s</comment> for connection named <comment>%s</comment> already exists. Skipped.</info>', $name, $connectionName));
|
||||
} else {
|
||||
$schemaManager->createDatabase($name);
|
||||
$output->writeln(sprintf('<info>Created database <comment>%s</comment> for connection named <comment>%s</comment></info>', $name, $connectionName));
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
$output->writeln(sprintf('<error>Could not create database <comment>%s</comment> for connection named <comment>%s</comment></error>', $name, $connectionName));
|
||||
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
|
||||
$error = true;
|
||||
}
|
||||
|
||||
$tmpConnection->close();
|
||||
|
||||
return $error ? 1 : 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Command;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\Tools\EntityGenerator;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
/**
|
||||
* Base class for Doctrine console commands to extend from.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
abstract class DoctrineCommand extends Command
|
||||
{
|
||||
private ManagerRegistry $doctrine;
|
||||
|
||||
public function __construct(ManagerRegistry $doctrine)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->doctrine = $doctrine;
|
||||
}
|
||||
|
||||
/**
|
||||
* get a doctrine entity generator
|
||||
*
|
||||
* @return EntityGenerator
|
||||
*/
|
||||
protected function getEntityGenerator()
|
||||
{
|
||||
$entityGenerator = new EntityGenerator();
|
||||
$entityGenerator->setGenerateAnnotations(false);
|
||||
$entityGenerator->setGenerateStubMethods(true);
|
||||
$entityGenerator->setRegenerateEntityIfExists(false);
|
||||
$entityGenerator->setUpdateEntityIfExists(true);
|
||||
$entityGenerator->setNumSpaces(4);
|
||||
$entityGenerator->setAnnotationPrefix('ORM\\');
|
||||
|
||||
return $entityGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a doctrine entity manager by symfony name.
|
||||
*
|
||||
* @param string $name
|
||||
* @param int|null $shardId
|
||||
*
|
||||
* @return EntityManager
|
||||
*/
|
||||
protected function getEntityManager($name, $shardId = null)
|
||||
{
|
||||
$manager = $this->getDoctrine()->getManager($name);
|
||||
|
||||
if ($shardId !== null) {
|
||||
throw new InvalidArgumentException('Shards are not supported anymore using doctrine/dbal >= 3');
|
||||
}
|
||||
|
||||
return $manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a doctrine dbal connection by symfony name.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return Connection
|
||||
*/
|
||||
protected function getDoctrineConnection($name)
|
||||
{
|
||||
return $this->getDoctrine()->getConnection($name);
|
||||
}
|
||||
|
||||
/** @return ManagerRegistry */
|
||||
protected function getDoctrine()
|
||||
{
|
||||
return $this->doctrine;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Command;
|
||||
|
||||
use Doctrine\DBAL\DriverManager;
|
||||
use Doctrine\DBAL\Schema\SqliteSchemaManager;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Throwable;
|
||||
|
||||
use function file_exists;
|
||||
use function in_array;
|
||||
use function method_exists;
|
||||
use function sprintf;
|
||||
use function unlink;
|
||||
|
||||
/**
|
||||
* Database tool allows you to easily drop your configured databases.
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class DropDatabaseDoctrineCommand extends DoctrineCommand
|
||||
{
|
||||
public const RETURN_CODE_NOT_DROP = 1;
|
||||
|
||||
public const RETURN_CODE_NO_FORCE = 2;
|
||||
|
||||
/** @return void */
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('doctrine:database:drop')
|
||||
->setDescription('Drops the configured database')
|
||||
->addOption('connection', 'c', InputOption::VALUE_OPTIONAL, 'The connection to use for this command')
|
||||
->addOption('if-exists', null, InputOption::VALUE_NONE, 'Don\'t trigger an error, when the database doesn\'t exist')
|
||||
->addOption('force', 'f', InputOption::VALUE_NONE, 'Set this parameter to execute this action')
|
||||
->setHelp(<<<'EOT'
|
||||
The <info>%command.name%</info> command drops the default connections database:
|
||||
|
||||
<info>php %command.full_name%</info>
|
||||
|
||||
The <info>--force</info> parameter has to be used to actually drop the database.
|
||||
|
||||
You can also optionally specify the name of a connection to drop the database for:
|
||||
|
||||
<info>php %command.full_name% --connection=default</info>
|
||||
|
||||
<error>Be careful: All data in a given database will be lost when executing this command.</error>
|
||||
EOT);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$connectionName = $input->getOption('connection');
|
||||
if (empty($connectionName)) {
|
||||
$connectionName = $this->getDoctrine()->getDefaultConnectionName();
|
||||
}
|
||||
|
||||
$connection = $this->getDoctrineConnection($connectionName);
|
||||
|
||||
$ifExists = $input->getOption('if-exists');
|
||||
|
||||
$params = $connection->getParams();
|
||||
|
||||
if (isset($params['primary'])) {
|
||||
$params = $params['primary'];
|
||||
}
|
||||
|
||||
$name = $params['path'] ?? ($params['dbname'] ?? false);
|
||||
if (! $name) {
|
||||
throw new InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be dropped.");
|
||||
}
|
||||
|
||||
unset($params['dbname'], $params['url']);
|
||||
|
||||
if (! $input->getOption('force')) {
|
||||
$output->writeln('<error>ATTENTION:</error> This operation should not be executed in a production environment.');
|
||||
$output->writeln('');
|
||||
$output->writeln(sprintf('<info>Would drop the database <comment>%s</comment> for connection named <comment>%s</comment>.</info>', $name, $connectionName));
|
||||
$output->writeln('Please run the operation with --force to execute');
|
||||
$output->writeln('<error>All data will be lost!</error>');
|
||||
|
||||
return self::RETURN_CODE_NO_FORCE;
|
||||
}
|
||||
|
||||
// Reopen connection without database name set
|
||||
// as some vendors do not allow dropping the database connected to.
|
||||
$connection->close();
|
||||
$connection = DriverManager::getConnection($params, $connection->getConfiguration());
|
||||
$schemaManager = method_exists($connection, 'createSchemaManager')
|
||||
? $connection->createSchemaManager()
|
||||
: $connection->getSchemaManager();
|
||||
$shouldDropDatabase = ! $ifExists || in_array($name, $schemaManager->listDatabases());
|
||||
|
||||
// Only quote if we don't have a path
|
||||
if (! isset($params['path'])) {
|
||||
$name = $connection->getDatabasePlatform()->quoteSingleIdentifier($name);
|
||||
}
|
||||
|
||||
try {
|
||||
if ($shouldDropDatabase) {
|
||||
if ($schemaManager instanceof SqliteSchemaManager) {
|
||||
// dropDatabase() is deprecated for Sqlite
|
||||
$connection->close();
|
||||
if (file_exists($name)) {
|
||||
unlink($name);
|
||||
}
|
||||
} else {
|
||||
$schemaManager->dropDatabase($name);
|
||||
}
|
||||
|
||||
$output->writeln(sprintf('<info>Dropped database <comment>%s</comment> for connection named <comment>%s</comment></info>', $name, $connectionName));
|
||||
} else {
|
||||
$output->writeln(sprintf('<info>Database <comment>%s</comment> for connection named <comment>%s</comment> doesn\'t exist. Skipped.</info>', $name, $connectionName));
|
||||
}
|
||||
|
||||
return 0;
|
||||
} catch (Throwable $e) {
|
||||
$output->writeln(sprintf('<error>Could not drop database <comment>%s</comment> for connection named <comment>%s</comment></error>', $name, $connectionName));
|
||||
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
|
||||
|
||||
return self::RETURN_CODE_NOT_DROP;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Command;
|
||||
|
||||
use Doctrine\ORM\Mapping\Driver\DatabaseDriver;
|
||||
use Doctrine\ORM\Tools\Console\MetadataFilter;
|
||||
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
|
||||
use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use function chmod;
|
||||
use function dirname;
|
||||
use function file_put_contents;
|
||||
use function is_dir;
|
||||
use function mkdir;
|
||||
use function sprintf;
|
||||
use function str_replace;
|
||||
|
||||
/**
|
||||
* Import Doctrine ORM metadata mapping information from an existing database.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class ImportMappingDoctrineCommand extends DoctrineCommand
|
||||
{
|
||||
/** @var string[] */
|
||||
private array $bundles;
|
||||
|
||||
/** @param string[] $bundles */
|
||||
public function __construct(ManagerRegistry $doctrine, array $bundles)
|
||||
{
|
||||
parent::__construct($doctrine);
|
||||
|
||||
$this->bundles = $bundles;
|
||||
}
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->setName('doctrine:mapping:import')
|
||||
->addArgument('name', InputArgument::REQUIRED, 'The bundle or namespace to import the mapping information to')
|
||||
->addArgument('mapping-type', InputArgument::OPTIONAL, 'The mapping type to export the imported mapping information to')
|
||||
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command')
|
||||
->addOption('filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match entities that should be mapped.')
|
||||
->addOption('force', null, InputOption::VALUE_NONE, 'Force to overwrite existing mapping files.')
|
||||
->addOption('path', null, InputOption::VALUE_REQUIRED, 'The path where the files would be generated (not used when a bundle is passed).')
|
||||
->setDescription('Imports mapping information from an existing database')
|
||||
->setHelp(<<<'EOT'
|
||||
The <info>%command.name%</info> command imports mapping information
|
||||
from an existing database:
|
||||
|
||||
Generate annotation mappings into the src/ directory using App as the namespace:
|
||||
<info>php %command.full_name% App\\Entity annotation --path=src/Entity</info>
|
||||
|
||||
Generate xml mappings into the config/doctrine/ directory using App as the namespace:
|
||||
<info>php %command.full_name% App\\Entity xml --path=config/doctrine</info>
|
||||
|
||||
Generate XML mappings into a bundle:
|
||||
<info>php %command.full_name% "MyCustomBundle" xml</info>
|
||||
|
||||
You can also optionally specify which entity manager to import from with the
|
||||
<info>--em</info> option:
|
||||
|
||||
<info>php %command.full_name% "MyCustomBundle" xml --em=default</info>
|
||||
|
||||
If you don't want to map every entity that can be found in the database, use the
|
||||
<info>--filter</info> option. It will try to match the targeted mapped entity with the
|
||||
provided pattern string.
|
||||
|
||||
<info>php %command.full_name% "MyCustomBundle" xml --filter=MyMatchedEntity</info>
|
||||
|
||||
Use the <info>--force</info> option, if you want to override existing mapping files:
|
||||
|
||||
<info>php %command.full_name% "MyCustomBundle" xml --force</info>
|
||||
EOT);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$type = $input->getArgument('mapping-type') ?: 'xml';
|
||||
if ($type === 'yaml') {
|
||||
$type = 'yml';
|
||||
}
|
||||
|
||||
$namespaceOrBundle = $input->getArgument('name');
|
||||
if (isset($this->bundles[$namespaceOrBundle])) {
|
||||
$bundle = $this->getApplication()->getKernel()->getBundle($namespaceOrBundle);
|
||||
$namespace = $bundle->getNamespace() . '\Entity';
|
||||
|
||||
$destPath = $bundle->getPath();
|
||||
if ($type === 'annotation') {
|
||||
$destPath .= '/Entity';
|
||||
} else {
|
||||
$destPath .= '/Resources/config/doctrine';
|
||||
}
|
||||
} else {
|
||||
// assume a namespace has been passed
|
||||
$namespace = $namespaceOrBundle;
|
||||
$destPath = $input->getOption('path');
|
||||
if ($destPath === null) {
|
||||
throw new InvalidArgumentException('The --path option is required when passing a namespace (e.g. --path=src). If you intended to pass a bundle name, check your spelling.');
|
||||
}
|
||||
}
|
||||
|
||||
$cme = new ClassMetadataExporter();
|
||||
$exporter = $cme->getExporter($type);
|
||||
$exporter->setOverwriteExistingFiles($input->getOption('force'));
|
||||
|
||||
if ($type === 'annotation') {
|
||||
$entityGenerator = $this->getEntityGenerator();
|
||||
$exporter->setEntityGenerator($entityGenerator);
|
||||
}
|
||||
|
||||
$em = $this->getEntityManager($input->getOption('em'));
|
||||
|
||||
$databaseDriver = new DatabaseDriver($em->getConnection()->getSchemaManager());
|
||||
$em->getConfiguration()->setMetadataDriverImpl($databaseDriver);
|
||||
|
||||
$emName = $input->getOption('em');
|
||||
$emName = $emName ? $emName : 'default';
|
||||
|
||||
$cmf = new DisconnectedClassMetadataFactory();
|
||||
$cmf->setEntityManager($em);
|
||||
$metadata = $cmf->getAllMetadata();
|
||||
$metadata = MetadataFilter::filter($metadata, $input->getOption('filter'));
|
||||
if ($metadata) {
|
||||
$output->writeln(sprintf('Importing mapping information from "<info>%s</info>" entity manager', $emName));
|
||||
foreach ($metadata as $class) {
|
||||
$className = $class->name;
|
||||
$class->name = $namespace . '\\' . $className;
|
||||
if ($type === 'annotation') {
|
||||
$path = $destPath . '/' . str_replace('\\', '.', $className) . '.php';
|
||||
} else {
|
||||
$path = $destPath . '/' . str_replace('\\', '.', $className) . '.orm.' . $type;
|
||||
}
|
||||
|
||||
$output->writeln(sprintf(' > writing <comment>%s</comment>', $path));
|
||||
$code = $exporter->exportClassMetadata($class);
|
||||
$dir = dirname($path);
|
||||
if (! is_dir($dir)) {
|
||||
mkdir($dir, 0775, true);
|
||||
}
|
||||
|
||||
file_put_contents($path, $code);
|
||||
chmod($path, 0664);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$output->writeln('Database does not have any mapping information.');
|
||||
$output->writeln('');
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
/**
|
||||
* Command to clear the metadata cache of the various cache drivers.
|
||||
*
|
||||
* @deprecated use Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand instead
|
||||
*/
|
||||
class ClearMetadataCacheDoctrineCommand extends MetadataCommand
|
||||
{
|
||||
use OrmProxyCommand;
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('doctrine:cache:clear-metadata')
|
||||
->setDescription('Clears all metadata cache for an entity manager');
|
||||
|
||||
if ($this->getDefinition()->hasOption('em')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
/**
|
||||
* Command to clear the query cache of the various cache drivers.
|
||||
*
|
||||
* @deprecated use Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand instead
|
||||
*/
|
||||
class ClearQueryCacheDoctrineCommand extends QueryCommand
|
||||
{
|
||||
use OrmProxyCommand;
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('doctrine:cache:clear-query')
|
||||
->setDescription('Clears all query cache for an entity manager');
|
||||
|
||||
if ($this->getDefinition()->hasOption('em')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
/**
|
||||
* Command to clear the result cache of the various cache drivers.
|
||||
*
|
||||
* @deprecated use Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand instead
|
||||
*/
|
||||
class ClearResultCacheDoctrineCommand extends ResultCommand
|
||||
{
|
||||
use OrmProxyCommand;
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('doctrine:cache:clear-result')
|
||||
->setDescription('Clears result cache for an entity manager');
|
||||
|
||||
if ($this->getDefinition()->hasOption('em')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\Command\ClearCache\CollectionRegionCommand;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
/**
|
||||
* Command to clear a collection cache region.
|
||||
*
|
||||
* @deprecated use Doctrine\ORM\Tools\Console\Command\ClearCache\CollectionRegionCommand instead
|
||||
*/
|
||||
class CollectionRegionDoctrineCommand extends CollectionRegionCommand
|
||||
{
|
||||
use OrmProxyCommand;
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('doctrine:cache:clear-collection-region');
|
||||
|
||||
if ($this->getDefinition()->hasOption('em')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand;
|
||||
use Doctrine\ORM\Tools\Export\Driver\AbstractExporter;
|
||||
use Doctrine\ORM\Tools\Export\Driver\XmlExporter;
|
||||
use Doctrine\ORM\Tools\Export\Driver\YamlExporter;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
use function assert;
|
||||
|
||||
/**
|
||||
* Convert Doctrine ORM metadata mapping information between the various supported
|
||||
* formats.
|
||||
*
|
||||
* @deprecated use Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand instead
|
||||
*/
|
||||
class ConvertMappingDoctrineCommand extends ConvertMappingCommand
|
||||
{
|
||||
use OrmProxyCommand;
|
||||
|
||||
/** @return void */
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('doctrine:mapping:convert');
|
||||
|
||||
if ($this->getDefinition()->hasOption('em')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $toType
|
||||
* @param string $destPath
|
||||
*
|
||||
* @return AbstractExporter
|
||||
*/
|
||||
protected function getExporter($toType, $destPath)
|
||||
{
|
||||
$exporter = parent::getExporter($toType, $destPath);
|
||||
assert($exporter instanceof AbstractExporter);
|
||||
if ($exporter instanceof XmlExporter) {
|
||||
$exporter->setExtension('.orm.xml');
|
||||
} elseif ($exporter instanceof YamlExporter) {
|
||||
$exporter->setExtension('.orm.yml');
|
||||
}
|
||||
|
||||
return $exporter;
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
/**
|
||||
* Command to execute the SQL needed to generate the database schema for
|
||||
* a given entity manager.
|
||||
*
|
||||
* @deprecated use Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand instead
|
||||
*/
|
||||
class CreateSchemaDoctrineCommand extends CreateCommand
|
||||
{
|
||||
use OrmProxyCommand;
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('doctrine:schema:create')
|
||||
->setDescription('Executes (or dumps) the SQL needed to generate the database schema');
|
||||
|
||||
if ($this->getDefinition()->hasOption('em')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Tools\Console\EntityManagerProvider;
|
||||
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
|
||||
use function assert;
|
||||
use function trigger_deprecation;
|
||||
|
||||
/**
|
||||
* Provides some helper and convenience methods to configure doctrine commands in the context of bundles
|
||||
* and multiple connections/entity managers.
|
||||
*
|
||||
* @deprecated since DoctrineBundle 2.7 and will be removed in 3.0
|
||||
*/
|
||||
abstract class DoctrineCommandHelper
|
||||
{
|
||||
/**
|
||||
* Convenience method to push the helper sets of a given entity manager into the application.
|
||||
*
|
||||
* @param string $emName
|
||||
*/
|
||||
public static function setApplicationEntityManager(Application $application, $emName)
|
||||
{
|
||||
$em = $application->getKernel()->getContainer()->get('doctrine')->getManager($emName);
|
||||
assert($em instanceof EntityManagerInterface);
|
||||
$helperSet = $application->getHelperSet();
|
||||
$helperSet->set(new EntityManagerHelper($em), 'em');
|
||||
|
||||
trigger_deprecation(
|
||||
'doctrine/doctrine-bundle',
|
||||
'2.7',
|
||||
'Providing an EntityManager using "%s" is deprecated. Use an instance of "%s" instead.',
|
||||
EntityManagerHelper::class,
|
||||
EntityManagerProvider::class,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
/**
|
||||
* Command to drop the database schema for a set of classes based on their mappings.
|
||||
*
|
||||
* @deprecated use Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand instead
|
||||
*/
|
||||
class DropSchemaDoctrineCommand extends DropCommand
|
||||
{
|
||||
use OrmProxyCommand;
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('doctrine:schema:drop')
|
||||
->setDescription('Executes (or dumps) the SQL needed to drop the current database schema');
|
||||
|
||||
if ($this->getDefinition()->hasOption('em')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
/**
|
||||
* Ensure the Doctrine ORM is configured properly for a production environment.
|
||||
*
|
||||
* @deprecated use Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand instead
|
||||
*/
|
||||
class EnsureProductionSettingsDoctrineCommand extends EnsureProductionSettingsCommand
|
||||
{
|
||||
use OrmProxyCommand;
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('doctrine:ensure-production-settings');
|
||||
|
||||
if ($this->getDefinition()->hasOption('em')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\Command\ClearCache\EntityRegionCommand;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
/**
|
||||
* Command to clear a entity cache region.
|
||||
*
|
||||
* @deprecated use Doctrine\ORM\Tools\Console\Command\ClearCache\EntityRegionCommand instead
|
||||
*/
|
||||
class EntityRegionCacheDoctrineCommand extends EntityRegionCommand
|
||||
{
|
||||
use OrmProxyCommand;
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('doctrine:cache:clear-entity-region');
|
||||
|
||||
if ($this->getDefinition()->hasOption('em')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\Command\InfoCommand;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
/**
|
||||
* Show information about mapped entities
|
||||
*
|
||||
* @deprecated use Doctrine\ORM\Tools\Console\Command\InfoCommand instead
|
||||
*/
|
||||
class InfoDoctrineCommand extends InfoCommand
|
||||
{
|
||||
use OrmProxyCommand;
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->setName('doctrine:mapping:info');
|
||||
|
||||
if ($this->getDefinition()->hasOption('em')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\EntityManagerProvider;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use function trigger_deprecation;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @deprecated
|
||||
*/
|
||||
trait OrmProxyCommand
|
||||
{
|
||||
private ?EntityManagerProvider $entityManagerProvider;
|
||||
|
||||
public function __construct(?EntityManagerProvider $entityManagerProvider = null)
|
||||
{
|
||||
parent::__construct($entityManagerProvider);
|
||||
|
||||
$this->entityManagerProvider = $entityManagerProvider;
|
||||
|
||||
trigger_deprecation(
|
||||
'doctrine/doctrine-bundle',
|
||||
'2.8',
|
||||
'Class "%s" is deprecated. Use "%s" instead.',
|
||||
self::class,
|
||||
parent::class,
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
if (! $this->entityManagerProvider) {
|
||||
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
|
||||
}
|
||||
|
||||
return parent::execute($input, $output);
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\Command\ClearCache\QueryRegionCommand;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
/**
|
||||
* Command to clear a query cache region.
|
||||
*
|
||||
* @deprecated use Doctrine\ORM\Tools\Console\Command\ClearCache\QueryRegionCommand instead
|
||||
*/
|
||||
class QueryRegionCacheDoctrineCommand extends QueryRegionCommand
|
||||
{
|
||||
use OrmProxyCommand;
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('doctrine:cache:clear-query-region');
|
||||
|
||||
if ($this->getDefinition()->hasOption('em')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\Command\RunDqlCommand;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
/**
|
||||
* Execute a Doctrine DQL query and output the results.
|
||||
*
|
||||
* @deprecated use Doctrine\ORM\Tools\Console\Command\RunDqlCommand instead
|
||||
*/
|
||||
class RunDqlDoctrineCommand extends RunDqlCommand
|
||||
{
|
||||
use OrmProxyCommand;
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('doctrine:query:dql')
|
||||
->setHelp(<<<'EOT'
|
||||
The <info>%command.name%</info> command executes the given DQL query and
|
||||
outputs the results:
|
||||
|
||||
<info>php %command.full_name% "SELECT u FROM UserBundle:User u"</info>
|
||||
|
||||
You can also optional specify some additional options like what type of
|
||||
hydration to use when executing the query:
|
||||
|
||||
<info>php %command.full_name% "SELECT u FROM UserBundle:User u" --hydrate=array</info>
|
||||
|
||||
Additionally you can specify the first result and maximum amount of results to
|
||||
show:
|
||||
|
||||
<info>php %command.full_name% "SELECT u FROM UserBundle:User u" --first-result=0 --max-result=30</info>
|
||||
EOT);
|
||||
|
||||
if ($this->getDefinition()->hasOption('em')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
|
||||
|
||||
use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use function trigger_deprecation;
|
||||
|
||||
/**
|
||||
* Execute a SQL query and output the results.
|
||||
*
|
||||
* @deprecated use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand instead
|
||||
*/
|
||||
class RunSqlDoctrineCommand extends RunSqlCommand
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('doctrine:query:sql')
|
||||
->setHelp(<<<'EOT'
|
||||
The <info>%command.name%</info> command executes the given SQL query and
|
||||
outputs the results:
|
||||
|
||||
<info>php %command.full_name% "SELECT * FROM users"</info>
|
||||
EOT);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
trigger_deprecation(
|
||||
'doctrine/doctrine-bundle',
|
||||
'2.2',
|
||||
'The "%s" (doctrine:query:sql) is deprecated, use dbal:run-sql command instead.',
|
||||
self::class,
|
||||
);
|
||||
|
||||
return parent::execute($input, $output);
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
/**
|
||||
* Command to generate the SQL needed to update the database schema to match
|
||||
* the current mapping information.
|
||||
*
|
||||
* @deprecated use Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand instead
|
||||
*/
|
||||
class UpdateSchemaDoctrineCommand extends UpdateCommand
|
||||
{
|
||||
use OrmProxyCommand;
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('doctrine:schema:update');
|
||||
|
||||
if ($this->getDefinition()->hasOption('em')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand as DoctrineValidateSchemaCommand;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
/**
|
||||
* Command to run Doctrine ValidateSchema() on the current mappings.
|
||||
*
|
||||
* @deprecated use Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand instead
|
||||
*/
|
||||
class ValidateSchemaCommand extends DoctrineValidateSchemaCommand
|
||||
{
|
||||
use OrmProxyCommand;
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('doctrine:schema:validate');
|
||||
|
||||
if ($this->getDefinition()->hasOption('em')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user