Skip to content

Commit af3704b

Browse files
committed
Link new command as service
1 parent 83c63a0 commit af3704b

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/Command/CleanOrphanedCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Silverback\ApiComponentsBundle\Command;
44

5-
use Doctrine\ORM\EntityManagerInterface;
5+
use Doctrine\Persistence\ManagerRegistry;
66
use Silverback\ApiComponentsBundle\Entity\Core\AbstractComponent;
77
use Silverback\ApiComponentsBundle\Entity\Core\ComponentGroup;
88
use Silverback\ApiComponentsBundle\Helper\OrphanedResourceHelper;
@@ -15,7 +15,7 @@
1515
#[AsCommand(name: 'silverback:api-components:clean-orphaned')]
1616
class CleanOrphanedCommand extends Command
1717
{
18-
public function __construct(private readonly OrphanedResourceHelper $orphanedResourceHelper, private readonly EntityManagerInterface $entityManager)
18+
public function __construct(private readonly OrphanedResourceHelper $orphanedResourceHelper, private readonly ManagerRegistry $registry)
1919
{
2020
parent::__construct();
2121
}
@@ -30,7 +30,7 @@ protected function configure(): void
3030
protected function execute(InputInterface $input, OutputInterface $output): int
3131
{
3232
$count = 0;
33-
$componentGroupRepository = $this->entityManager->getRepository(ComponentGroup::class);
33+
$componentGroupRepository = $this->registry->getRepository(ComponentGroup::class);
3434
$componentGroups = $componentGroupRepository->findAll();
3535
$groupsProgressBar = new ProgressBar($output, count($componentGroups));
3636
$groupsProgressBar->start();
@@ -42,7 +42,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4242
}
4343
$groupsProgressBar->finish();
4444

45-
$componentRepository = $this->entityManager->getRepository(AbstractComponent::class);
45+
$componentRepository = $this->registry->getRepository(AbstractComponent::class);
4646
$components = $componentRepository->findAll();
4747
$componentsProgressBar = new ProgressBar($output, count($componentGroups));
4848
$componentsProgressBar->start();

src/Resources/config/services.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
use Silverback\ApiComponentsBundle\AttributeReader\PublishableAttributeReader;
4444
use Silverback\ApiComponentsBundle\AttributeReader\TimestampedAttributeReader;
4545
use Silverback\ApiComponentsBundle\AttributeReader\UploadableAttributeReader;
46+
use Silverback\ApiComponentsBundle\Command\CleanOrphanedCommand;
4647
use Silverback\ApiComponentsBundle\Command\FormCachePurgeCommand;
4748
use Silverback\ApiComponentsBundle\Command\RefreshTokensExpireCommand;
4849
use Silverback\ApiComponentsBundle\Command\UserCreateCommand;
@@ -1150,6 +1151,16 @@
11501151
]
11511152
);
11521153

1154+
$services
1155+
->set(CleanOrphanedCommand::class)
1156+
->tag('console.command')
1157+
->args(
1158+
[
1159+
new Reference('silverback.helper.orphaned_resource_helper'),
1160+
new Reference(ManagerRegistry::class)
1161+
]
1162+
);
1163+
11531164
$services
11541165
->set(UserStateProvider::class)
11551166
->args(

0 commit comments

Comments
 (0)