mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
⚡ routine deletion
This commit is contained in:
parent
e2846a6c73
commit
2c113e9e23
@ -151,6 +151,42 @@ class DefaultController extends AbstractController {
|
|||||||
200 );
|
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(
|
* @Put(
|
||||||
* path = "/poll/{id}",
|
* path = "/poll/{id}",
|
||||||
|
@ -30,18 +30,18 @@ class Owner {
|
|||||||
*/
|
*/
|
||||||
private $email;
|
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")
|
* @Serializer\Type("App\Entity\Poll")
|
||||||
*/
|
*/
|
||||||
private $polls;
|
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;
|
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;
|
private $stackOfVotes;
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ class Poll {
|
|||||||
*/
|
*/
|
||||||
public $choices;
|
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")
|
* @Serializer\Type("App\Entity\Comment")
|
||||||
*/
|
*/
|
||||||
public $comments;
|
public $comments;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user