2021-04-08 16:41:54 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
2021-04-08 17:16:41 +02:00
|
|
|
use App\Entity\Poll;
|
2021-04-17 15:30:07 +02:00
|
|
|
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")
|
|
|
|
*/
|
2021-04-08 17:41:52 +02:00
|
|
|
public function indexAction( $unique_key ) {
|
2021-04-17 15:30:07 +02:00
|
|
|
|
2021-04-08 17:16:41 +02:00
|
|
|
// get env vars
|
2021-04-17 15:30:07 +02:00
|
|
|
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
|
2021-04-08 17:41:52 +02:00
|
|
|
// connec
|
|
|
|
|
|
|
|
$debug = '';
|
|
|
|
|
2021-04-17 15:30:07 +02:00
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$pollsByID = [];
|
|
|
|
|
2021-04-08 17:41:52 +02:00
|
|
|
$pdo_options[ \PDO::ATTR_ERRMODE ] = \PDO::ERRMODE_EXCEPTION;
|
2021-04-17 15:30:07 +02:00
|
|
|
$bdd = new \PDO( 'mysql:host=localhost;dbname=' . $this->getParameter( 'OLD_DATABASE_NAME' ),
|
|
|
|
$this->getParameter( 'OLD_DATABASE_USER' ),
|
|
|
|
$this->getParameter( 'OLD_DATABASE_PASS' ),
|
2021-04-08 17:41:52 +02:00
|
|
|
$pdo_options );
|
2021-04-17 15:30:07 +02:00
|
|
|
$res_Poll = $bdd->query( 'SELECT * FROM fd_poll' );
|
2021-04-08 17:41:52 +02:00
|
|
|
//boucler pour ranger
|
2021-04-17 15:30:07 +02:00
|
|
|
while ( $d = $res_Poll->fetch( \PDO::FETCH_OBJ ) ) {
|
|
|
|
echo "<br> migration du sondage $d->title , $d->id";
|
|
|
|
|
2021-04-08 17:41:52 +02:00
|
|
|
$u = new Poll();
|
|
|
|
|
2021-04-17 15:30:07 +02:00
|
|
|
$u
|
|
|
|
->setCustomURL( $d->id )
|
|
|
|
->setAdminKey( $d->admin_id )
|
|
|
|
->setTitle( $d->title )
|
|
|
|
->setDescription( $d->description )
|
|
|
|
->setCreationDate( date_create( $d->creation_date ) );
|
|
|
|
|
|
|
|
$pollsByID[ $d->id ] = $u;
|
|
|
|
|
2021-04-08 17:41:52 +02:00
|
|
|
// $u->setPseudo($d->pseudo)
|
|
|
|
// ->setIp($d->ip)
|
|
|
|
// ->setAge($d->age)
|
|
|
|
// ->setsondage($s);
|
2021-04-17 15:30:07 +02:00
|
|
|
// $em->persist( $u );
|
2021-04-08 17:41:52 +02:00
|
|
|
}
|
|
|
|
|
2021-04-17 15:30:07 +02:00
|
|
|
// $em->flush();
|
2021-04-08 17:41:52 +02:00
|
|
|
|
2021-04-08 17:16:41 +02:00
|
|
|
// gather objects
|
|
|
|
// create new polls
|
|
|
|
// success
|
|
|
|
// failure notice
|
|
|
|
|
2021-04-08 17:41:52 +02:00
|
|
|
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
|
|
|
|
|
|
|
}
|