add env params to connect for migration

This commit is contained in:
Tykayn 2021-04-17 15:30:07 +02:00 committed by tykayn
parent ae7fc029d5
commit 56126c6649
3 changed files with 35 additions and 16 deletions

4
.env
View File

@ -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

View File

@ -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:

View File

@ -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 "<br> 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