date-poll-sf5/src/Controller/MigrationController.php

79 lines
1.9 KiB
PHP
Raw Normal View History

2021-04-08 16:41:54 +02:00
<?php
namespace App\Controller;
2021-04-08 17:16:41 +02:00
use App\Entity\Poll;
use Symfony\Component\HttpFoundation\JsonResponse;
2021-04-08 17:16:41 +02:00
/**
* Class DefaultController
* @package App\Controller
* @Route("/migration-from-v1",name="admin_homepage")
*/
class MigrationController extends FramadateController {
/**
* @Get(path ="/{unique_key}",
* name = "_migrate_from_v1")
*/
public function indexAction( $unique_key ) {
2021-04-08 17:16:41 +02:00
// get env vars
if ( $unique_key !== $this->getParameter( 'UNIQ_INSTALL_KEY' ) ) {
return new JsonResponse( [
'error' => 'NOPE! veuillez vérifier votre fichier .env',
] );
};
2021-04-08 17:16:41 +02:00
// check uniq key is good
// fetch old Database
// connec
$debug = '';
$em = $this->getDoctrine()->getManager();
$pollsByID = [];
$pdo_options[ \PDO::ATTR_ERRMODE ] = \PDO::ERRMODE_EXCEPTION;
$bdd = new \PDO( 'mysql:host=localhost;dbname=' . $this->getParameter( 'OLD_DATABASE_NAME' ),
$this->getParameter( 'OLD_DATABASE_USER' ),
$this->getParameter( 'OLD_DATABASE_PASS' ),
$pdo_options );
$res_Poll = $bdd->query( 'SELECT * FROM fd_poll' );
//boucler pour ranger
while ( $d = $res_Poll->fetch( \PDO::FETCH_OBJ ) ) {
echo "<br> migration du sondage $d->title , $d->id";
$u = new Poll();
$u
->setCustomURL( $d->id )
->setAdminKey( $d->admin_id )
->setTitle( $d->title )
->setDescription( $d->description )
->setCreationDate( date_create( $d->creation_date ) );
$pollsByID[ $d->id ] = $u;
// $u->setPseudo($d->pseudo)
// ->setIp($d->ip)
// ->setAge($d->age)
// ->setsondage($s);
// $em->persist( $u );
}
// $em->flush();
2021-04-08 17:16:41 +02:00
// gather objects
// create new polls
// success
// failure notice
return $this->json( [
"message" => "welcome to the framadate migration endpoint, it has yet to be done",
"debug" => $debug,
],
2021-04-08 17:16:41 +02:00
200 );
}
2021-04-08 16:41:54 +02:00
}