2020-04-21 17:59:22 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
|
|
|
use App\Entity\Poll;
|
|
|
|
use FOS\RestBundle\Controller\Annotations\Get;
|
|
|
|
use FOS\RestBundle\Controller\Annotations\Route;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class DefaultController
|
|
|
|
* @package App\Controller
|
|
|
|
* @Route("/admin",name="admin_homepage")
|
|
|
|
*/
|
2021-04-21 11:02:24 +02:00
|
|
|
class AdminController extends EmailsController {
|
2020-04-21 17:59:22 +02:00
|
|
|
/**
|
|
|
|
* @Get(path ="/",
|
|
|
|
* name = "_get_default")
|
|
|
|
*/
|
|
|
|
public function indexAction() {
|
|
|
|
|
|
|
|
return $this->json( [ "message" => "welcome to the framadate admin api, ask /api/v1/doc.json for endpoints" ],
|
|
|
|
200 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete all expired polls and their children
|
|
|
|
* @Get(
|
|
|
|
* path = "/polls/clean/{token}",
|
|
|
|
* name = "_clean_expired_polls",
|
|
|
|
* )
|
|
|
|
* token is set up in the main env file
|
|
|
|
*/
|
|
|
|
public
|
|
|
|
function cleanExpiredPolls(
|
|
|
|
string $token
|
|
|
|
) {
|
2020-05-23 16:31:59 +02:00
|
|
|
if ( $this->getParameter( 'admin_token' ) !== $token ) {
|
2020-04-21 17:59:22 +02:00
|
|
|
return $this->json( [
|
|
|
|
'message' => 'clean routine can NOT be done, your admin token is bad, and you should feel bad.',
|
|
|
|
],
|
|
|
|
403 );
|
|
|
|
}
|
|
|
|
$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();
|
|
|
|
|
|
|
|
$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 );
|
|
|
|
}
|
|
|
|
|
2020-06-11 16:21:44 +02:00
|
|
|
/**
|
|
|
|
* Delete all expired polls and their children
|
|
|
|
* @Get(
|
|
|
|
* path = "/polls/migrate",
|
|
|
|
* name = "_migrate_framadate",
|
|
|
|
* )
|
|
|
|
* token is set up in the main env file
|
|
|
|
*/
|
|
|
|
public
|
|
|
|
function runMigrationFromOldFramadate(
|
|
|
|
string $token
|
|
|
|
) {
|
|
|
|
// TODO
|
|
|
|
// fetch old polls and store their properties in new poll objects
|
|
|
|
|
|
|
|
$foundPolls = [];
|
|
|
|
$database_name = 'symfony';
|
|
|
|
|
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$emPoll = $this->getDoctrine()->getRepository( Poll::class );
|
|
|
|
|
|
|
|
return $this->json( [
|
|
|
|
'message' => 'migration done for: ' . count( $foundPolls ). ' - this feature is not ready to work YET.',
|
|
|
|
'data' => [
|
|
|
|
'count' => count( $foundPolls ),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
200 );
|
|
|
|
}
|
2020-04-21 17:59:22 +02:00
|
|
|
}
|