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;
@ -147,7 +147,7 @@ class Poll {
public function setTitle( string $title ): self {
$this->title = $title;
return $this;
}
@ -157,13 +157,13 @@ class Poll {
public function setCreationDate( DateTimeInterface $creationDate ): self {
$this->creationDate = $creationDate;
return $this;
}
public function setExpiracyDate( DateTimeInterface $expiracyDate ): self {
$this->expiracyDate = $expiracyDate;
return $this;
}
@ -173,7 +173,7 @@ class Poll {
public function setOwner( ?Owner $owner ): self {
$this->owner = $owner;
return $this;
}
@ -191,7 +191,7 @@ class Poll {
public function setAdminKey( string $adminKey ): self {
$this->adminKey = $adminKey;
return $this;
}
@ -201,7 +201,7 @@ class Poll {
public function setDescription( string $description ): self {
$this->description = $description;
return $this;
}
@ -211,7 +211,7 @@ class Poll {
public function setKind( string $kind ): self {
$this->kind = $kind;
return $this;
}
@ -221,7 +221,7 @@ class Poll {
public function setCustomUrl( string $customUrl ): self {
$this->customUrl = $customUrl;
return $this;
}
@ -231,7 +231,7 @@ class Poll {
public function setPassword( string $password ): self {
$this->password = $password;
return $this;
}
@ -241,7 +241,7 @@ class Poll {
public function setModificationPolicy( string $modificationPolicy ): self {
$this->modificationPolicy = $modificationPolicy;
return $this;
}
@ -251,7 +251,7 @@ class Poll {
public function setMailOnComment( bool $mailOnComment ): self {
$this->mailOnComment = $mailOnComment;
return $this;
}
@ -261,7 +261,7 @@ class Poll {
public function setMailOnVote( bool $mailOnVote ): self {
$this->mailOnVote = $mailOnVote;
return $this;
}
@ -271,7 +271,7 @@ class Poll {
public function setHideResults( bool $hideResults ): self {
$this->hideResults = $hideResults;
return $this;
}
@ -281,7 +281,7 @@ class Poll {
public function setShowResultEvenIfPasswords( bool $showResultEvenIfPasswords ): self {
$this->showResultEvenIfPasswords = $showResultEvenIfPasswords;
return $this;
}
@ -298,7 +298,7 @@ class Poll {
$this->comments[] = $comment;
$comment->setPoll( $this );
}
return $this;
}
@ -310,7 +310,7 @@ class Poll {
$comment->setPoll( null );
}
}
return $this;
}
@ -320,7 +320,7 @@ class Poll {
public function setStacksOfVotes( ?StackOfVotes $stacksOfVotes ): self {
$this->stacksOfVotes = $stacksOfVotes;
return $this;
}
@ -336,7 +336,7 @@ class Poll {
$this->stackOfVotes[] = $stackOfVote;
$stackOfVote->setPoll( $this );
}
return $this;
}
@ -348,7 +348,7 @@ class Poll {
$stackOfVote->setPoll( null );
}
}
return $this;
}
@ -361,7 +361,7 @@ class Poll {
$this->votes[] = $vote;
$vote->setPoll( $this );
}
return $this;
}
@ -373,7 +373,7 @@ class Poll {
$vote->setPoll( null );
}
}
return $this;
}