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

62 lines
1.4 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;
2021-04-08 17:48:31 +02:00
use Symfony\Component\Routing\Annotation\Route;
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
// check uniq key is good
// fetch old Database
// connec
$debug = '';
$em = $this->getDoctrine()->getManager();
$pdo_options[ \PDO::ATTR_ERRMODE ] = \PDO::ERRMODE_EXCEPTION;
$bdd = new \PDO( 'mysql:host=localhost;dbname=framadate',
'useur',
'le_pass',
$pdo_options );
$reponse = $bdd->query( 'SELECT * FROM les_sondages ORDER BY id ASC LIMIT 0, 450' );
//boucler pour ranger
while ( $d = $reponse->fetch( \PDO::FETCH_OBJ ) ) {
$u = new Poll();
if ( $d->pseudo == 'PSEUDOOOOOO' ) {
$d->pseudo = "";
}
// $u->setPseudo($d->pseudo)
// ->setIp($d->ip)
// ->setAge($d->age)
// ->setsondage($s);
$em->persist( $s );
}
$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
}