routine deletion

This commit is contained in:
Baptiste Lemoine 2019-11-20 11:24:54 +01:00
parent e2846a6c73
commit 2c113e9e23
3 changed files with 61 additions and 25 deletions

View File

@ -151,6 +151,42 @@ class DefaultController extends AbstractController {
200 );
}
/**
* Delete all expired polls and their children
* @Get(
* path = "/clean-polls",
* name = "clean_expired_polls",
* )
*/
public function cleanExpiredPolls() {
$em = $this->getDoctrine()->getManager();
$emPoll = $this->getDoctrine()->getRepository( Poll::class );
$queryFind = $em->createQuery(
'SELECT p
FROM App\Entity\Poll p
WHERE p.expiracyDate < CURRENT_DATE()'
);
$queryDelete = $em->createQuery(
'DELETE
FROM App\Entity\Poll p
WHERE p.expiracyDate < CURRENT_DATE()'
);
$foundPolls = $queryFind->getResult();
var_dump( count( $foundPolls ) );
$em->flush();
return $this->json( [
'message' => 'clean routine has been done, here are the numbers of polls deleted: ' . count( $foundPolls ),
'data' => [
'count' => count( $foundPolls ),
],
],
200 );
}
/**
* @Put(
* path = "/poll/{id}",

View File

@ -30,18 +30,18 @@ class Owner {
*/
private $email;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Poll", mappedBy="owner",cascade={"persist","remove"})
* @ORM\OneToMany(targetEntity="App\Entity\Poll", mappedBy="owner",cascade={"persist","remove"},orphanRemoval=true)
* @Serializer\Type("App\Entity\Poll")
*/
private $polls;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="owner", cascade={"persist","remove"})
* @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="owner", cascade={"persist","remove"},orphanRemoval=true)
*/
private $comments;
/**
* @ORM\OneToMany(targetEntity="App\Entity\StackOfVotes", mappedBy="owner", cascade={"persist","remove"})
* @ORM\OneToMany(targetEntity="App\Entity\StackOfVotes", mappedBy="owner", cascade={"persist","remove"},orphanRemoval=true)
*/
private $stackOfVotes;

View File

@ -110,7 +110,7 @@ class Poll {
*/
public $choices;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="poll")
* @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="poll", orphanRemoval=true,cascade={"persist", "remove"})
* @Serializer\Type("App\Entity\Comment")
*/
public $comments;