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

Remove deprecated tail-cursor command and deprecated DoctrineODMCommand methods #795

Merged
merged 1 commit into from
Dec 9, 2023
Merged
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
157 changes: 2 additions & 155 deletions Command/DoctrineODMCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,8 @@

use Doctrine\Bundle\MongoDBBundle\ManagerRegistry;
use Doctrine\ODM\MongoDB\Tools\Console\Helper\DocumentManagerHelper;
use Doctrine\Persistence\ObjectManager;
use InvalidArgumentException;
use LogicException;
use RuntimeException;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Bundle\Bundle;

use function assert;
use function sprintf;
use function str_replace;
use function strtolower;
use function trigger_deprecation;

use const DIRECTORY_SEPARATOR;

/**
* Base class for Doctrine ODM console commands to extend.
Expand All @@ -30,59 +16,9 @@
*/
abstract class DoctrineODMCommand extends Command
{
/** @var ContainerInterface|null */
protected $container;

private ?ManagerRegistry $managerRegistry;

public function __construct(?ManagerRegistry $registry = null)
public function __construct(private ManagerRegistry $registry)
{
parent::__construct();

$this->managerRegistry = $registry;
}

/** @deprecated since version 4.4 */
public function setContainer(?ContainerInterface $container = null)
{
trigger_deprecation(
'doctrine/mongodb-odm-bundle',
'4.4',
'The "%s" method is deprecated and will be dropped in DoctrineMongoDBBundle 5.0.',
__METHOD__
);

$this->container = $container;
}

/**
* @deprecated since version 4.4
*
* @return ContainerInterface
*
* @throws LogicException
*/
protected function getContainer()
{
trigger_deprecation(
'doctrine/mongodb-odm-bundle',
'4.4',
'The "%s" method is deprecated and will be dropped in DoctrineMongoDBBundle 5.0.',
__METHOD__
);

if ($this->container === null) {
$application = $this->getApplication();
if ($application === null) {
throw new LogicException('The container cannot be retrieved as the application instance is not yet set.');
}

assert($application instanceof Application);

$this->container = $application->getKernel()->getContainer();
}

return $this->container;
}

/** @param string $dmName */
Expand All @@ -93,102 +29,13 @@ public static function setApplicationDocumentManager(Application $application, $
$helperSet->set(new DocumentManagerHelper($dm), 'dm');
}

/**
* @deprecated since version 4.4
*
* @return ObjectManager[]
*/
protected function getDoctrineDocumentManagers()
{
trigger_deprecation(
'doctrine/mongodb-odm-bundle',
'4.4',
'The "%s" method is deprecated and will be dropped in DoctrineMongoDBBundle 5.0.',
__METHOD__
);

return $this->getManagerRegistry()->getManagers();
}

/**
* @internal
*
* @return ManagerRegistry
*/
protected function getManagerRegistry()
{
if ($this->managerRegistry === null) {
$this->managerRegistry = $this->container->get('doctrine_mongodb');
assert($this->managerRegistry instanceof ManagerRegistry);
}

return $this->managerRegistry;
}

/**
* @deprecated since version 4.4
*
* @param string $bundleName
*
* @return Bundle
*/
protected function findBundle($bundleName)
{
trigger_deprecation(
'doctrine/mongodb-odm-bundle',
'4.4',
'The "%s" method is deprecated and will be dropped in DoctrineMongoDBBundle 5.0.',
__METHOD__
);

$foundBundle = false;

$application = $this->getApplication();

assert($application instanceof Application);

foreach ($application->getKernel()->getBundles() as $bundle) {
assert($bundle instanceof Bundle);
if (strtolower($bundleName) === strtolower($bundle->getName())) {
$foundBundle = $bundle;

break;
}
}

if (! $foundBundle) {
throw new InvalidArgumentException('No bundle ' . $bundleName . ' was found.');
}

return $foundBundle;
}

/**
* Transform classname to a path $foundBundle substract it to get the destination
*
* @deprecated since version 4.4
*
* @param Bundle $bundle
*
* @return string
*/
protected function findBasePathForBundle($bundle)
{
trigger_deprecation(
'doctrine/mongodb-odm-bundle',
'4.4',
'The "%s" method is deprecated and will be dropped in DoctrineMongoDBBundle 5.0.',
__METHOD__
);

$path = str_replace('\\', DIRECTORY_SEPARATOR, $bundle->getNamespace());
$search = str_replace('\\', DIRECTORY_SEPARATOR, $bundle->getPath());
$destination = str_replace(DIRECTORY_SEPARATOR . $path, '', $search, $c);

if ($c !== 1) {
throw new RuntimeException(sprintf('Can\'t find base path for bundle (path: "%s", destination: "%s").', $path, $destination));
}

return $destination;
return $this->registry;
}
}
122 changes: 0 additions & 122 deletions Command/TailCursorDoctrineODMCommand.php

This file was deleted.

16 changes: 0 additions & 16 deletions Cursor/TailableCursorProcessorInterface.php

This file was deleted.

3 changes: 0 additions & 3 deletions Resources/config/mongodb.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@
<service id="Doctrine\Bundle\MongoDBBundle\Command\ShardDoctrineODMCommand" class="Doctrine\Bundle\MongoDBBundle\Command\ShardDoctrineODMCommand">
<tag name="console.command" command="doctrine:mongodb:schema:shard"/>
</service>
<service id="Doctrine\Bundle\MongoDBBundle\Command\TailCursorDoctrineODMCommand" class="Doctrine\Bundle\MongoDBBundle\Command\TailCursorDoctrineODMCommand">
<tag name="console.command" command="doctrine:mongodb:tail-cursor"/>
</service>
<service id="Doctrine\Bundle\MongoDBBundle\Command\UpdateSchemaDoctrineODMCommand" class="Doctrine\Bundle\MongoDBBundle\Command\UpdateSchemaDoctrineODMCommand">
<tag name="console.command" command="doctrine:mongodb:schema:update"/>
</service>
Expand Down
5 changes: 0 additions & 5 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@
<code>protected function execute(InputInterface $input, OutputInterface $output)</code>
</MethodSignatureMismatch>
</file>
<file src="Command/TailCursorDoctrineODMCommand.php">
<InvalidReturnType>
<code>int</code>
</InvalidReturnType>
</file>
<file src="Command/UpdateSchemaDoctrineODMCommand.php">
<MethodSignatureMismatch>
<code>protected function execute(InputInterface $input, OutputInterface $output)</code>
Expand Down
1 change: 0 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<directory name="APM"/>
<directory name="CacheWarmer"/>
<directory name="Command"/>
<directory name="Cursor"/>
<directory name="DataCollector"/>
<directory name="DependencyInjection"/>
<directory name="EventSubscriber"/>
Expand Down