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(); $pollsBySlug = []; $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' ); while ( $d = $res_Poll->fetch( \PDO::FETCH_OBJ ) ) { echo " "; echo "
migration du sondage $d->title , $d->id , "; var_dump($d); $newPoll = new Poll(); $owner = new Owner(); $owner->setEmail( $d->admin_mail ) ->setPseudo( $d->admin_name ); $owner->addPoll($newPoll); $newPoll ->setOwner( $owner ) ->setCustomURL( $d->id ) // ->setKind( $d->id === 'D' ? 'date' : 'text' ) ->setHideResults( ! $d->results_publicly_visible ) ->setAdminKey( $d->admin_id ) ->setTitle( $d->title ) // ->setVotesAllowed( $d->receiveNewVotes ) // ->setCommentsAllowed( $d->receiveNewComments ) ->setChoicesMax( $d->ValueMax ) ->setPassword( $d->password_hash ) ->setDescription( $d->description ) ->setCreationDate( date_create( $d->creation_date ) ); $pollsBySlug[ $d->id ] = $newPoll; // $em->persist( $owner ); // $em->persist( $newPoll ); } // get choices, slots and link them with poll by their slug $res_slots = $bdd->query( 'SELECT * FROM fd_slot' ); while ( $d = $res_slots->fetch( \PDO::FETCH_OBJ ) ) { $pollSlug = $d->poll_id; $poll = $pollsBySlug[$pollSlug]; $moments = explode(',' , $d->moments); foreach ( $moments as $moment ) { $newChoice = new Choice(); $newChoice ->setPoll($poll) ->setDateTime($d->title) ->setName($moment); $poll->addChoice($newChoice); // $em->persist( $newChoice ); // $em->persist( $newPoll ); } } // get choices, slots and link them with poll by their slug $res_votes = $bdd->query( 'SELECT * FROM fd_vote' ); while ( $d = $res_votes->fetch( \PDO::FETCH_OBJ ) ) { $pollSlug = $d->poll_id; $poll = $pollsBySlug[ $pollSlug ]; $newStack = new StackOfVotes(); $newStack->setPoll($poll) ->setPseudo($d->name) ; // each choice answer is encoded in a value : // space character : no answer, 0 : no , 1 : maybe , 2 : yes $voteCodes = explode( '', $d->moments ); // get choices of the poll and answer accordingly $ii=0; foreach ( $voteCodes as $vote_code ) { if($vote_code !== ' '){ // TODO // $newStack->addVote($newVote); } $ii++; } $poll->addStackOfVotes($newStack); } // $em->flush(); // 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, ], 200 ); } }