mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-11-19 23:00:36 +01:00
command remove zero followups
This commit is contained in:
parent
be97910177
commit
44b4f49289
2 changed files with 57 additions and 0 deletions
38
src/Command/DeleteZeroCityFollowUpCommand.php
Normal file
38
src/Command/DeleteZeroCityFollowUpCommand.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Entity\CityFollowUp;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'app:delete-zero-cityfollowup',
|
||||
description: 'Supprime tous les CityFollowUp dont la mesure vaut 0.'
|
||||
)]
|
||||
class DeleteZeroCityFollowUpCommand extends Command
|
||||
{
|
||||
public function __construct(private EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$repo = $this->em->getRepository(CityFollowUp::class);
|
||||
$toDelete = $repo->createQueryBuilder('c')
|
||||
->where('c.measure = 0')
|
||||
->getQuery()
|
||||
->getResult();
|
||||
$count = count($toDelete);
|
||||
foreach ($toDelete as $entity) {
|
||||
$this->em->remove($entity);
|
||||
}
|
||||
$this->em->flush();
|
||||
$output->writeln("$count CityFollowUp supprimés (mesure = 0)");
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue