From 56126c6649eb42474891b7782d85354488059067 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Sat, 17 Apr 2021 15:30:07 +0200 Subject: [PATCH] add env params to connect for migration --- .env | 4 +-- config/services.yaml | 5 ++- src/Controller/MigrationController.php | 42 ++++++++++++++++++-------- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/.env b/.env index 073e40e..ca57cda 100644 --- a/.env +++ b/.env @@ -51,7 +51,7 @@ MAILER_DSN=smtp://localhost ###< symfony/mailer ### ## Migration from v1 OLD_DATABASE_NAME=framadate -OLD_DATABASE_USER=framadate -OLD_DATABASE_PASS=framadate +OLD_DATABASE_USER=framadate-admin +OLD_DATABASE_PASS=framadate-admin-password ### UNIQ_INSTALL_KEY must be really unique UNIQ_INSTALL_KEY=superCaliFragilistiExpialidousiousse diff --git a/config/services.yaml b/config/services.yaml index c7296dd..f21d5b9 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -4,7 +4,10 @@ # Put parameters here that don't need to change on each machine where the app is deployed # https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration parameters: - + OLD_DATABASE_NAME: '%env(OLD_DATABASE_NAME)%' + OLD_DATABASE_USER: '%env(OLD_DATABASE_USER)%' + OLD_DATABASE_PASS: '%env(OLD_DATABASE_PASS)%' + UNIQ_INSTALL_KEY: '%env(UNIQ_INSTALL_KEY)%' services: # default configuration for services in *this* file _defaults: diff --git a/src/Controller/MigrationController.php b/src/Controller/MigrationController.php index d3d68a3..793f091 100755 --- a/src/Controller/MigrationController.php +++ b/src/Controller/MigrationController.php @@ -3,9 +3,8 @@ namespace App\Controller; use App\Entity\Poll; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\HttpFoundation\JsonResponse; -use FOS\RestBundle\Controller\Annotations\Get; /** * Class DefaultController * @package App\Controller @@ -17,35 +16,52 @@ class MigrationController extends FramadateController { * name = "_migrate_from_v1") */ public function indexAction( $unique_key ) { + // get env vars + if ( $unique_key !== $this->getParameter( 'UNIQ_INSTALL_KEY' ) ) { + return new JsonResponse( [ + 'error' => 'NOPE! veuillez vérifier votre fichier .env', + ] ); + }; + // check uniq key is good // fetch old Database // connec $debug = ''; - $em = $this->getDoctrine()->getManager(); + $em = $this->getDoctrine()->getManager(); + $pollsByID = []; + $pdo_options[ \PDO::ATTR_ERRMODE ] = \PDO::ERRMODE_EXCEPTION; - $bdd = new \PDO( 'mysql:host=localhost;dbname=framadate', - 'useur', - 'le_pass', + $bdd = new \PDO( 'mysql:host=localhost;dbname=' . $this->getParameter( 'OLD_DATABASE_NAME' ), + $this->getParameter( 'OLD_DATABASE_USER' ), + $this->getParameter( 'OLD_DATABASE_PASS' ), $pdo_options ); - $reponse = $bdd->query( 'SELECT * FROM les_sondages ORDER BY id ASC LIMIT 0, 450' ); + $res_Poll = $bdd->query( 'SELECT * FROM fd_poll' ); //boucler pour ranger - while ( $d = $reponse->fetch( \PDO::FETCH_OBJ ) ) { + while ( $d = $res_Poll->fetch( \PDO::FETCH_OBJ ) ) { + echo "
migration du sondage $d->title , $d->id"; + $u = new Poll(); - if ( $d->pseudo == 'PSEUDOOOOOO' ) { - $d->pseudo = ""; - } + $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( $s ); +// $em->persist( $u ); } - $em->flush(); +// $em->flush(); // gather objects // create new polls