example migration pdo from other project
This commit is contained in:
parent
e1ee9c9ac8
commit
4ce426b52b
@ -3,8 +3,6 @@
|
|||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
use App\Entity\Poll;
|
use App\Entity\Poll;
|
||||||
use FOS\RestBundle\Controller\Annotations\Get;
|
|
||||||
use FOS\RestBundle\Controller\Annotations\Route;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class DefaultController
|
* Class DefaultController
|
||||||
@ -16,16 +14,46 @@ class MigrationController extends FramadateController {
|
|||||||
* @Get(path ="/{unique_key}",
|
* @Get(path ="/{unique_key}",
|
||||||
* name = "_migrate_from_v1")
|
* name = "_migrate_from_v1")
|
||||||
*/
|
*/
|
||||||
public function indexAction() {
|
public function indexAction( $unique_key ) {
|
||||||
// get env vars
|
// get env vars
|
||||||
// check uniq key is good
|
// check uniq key is good
|
||||||
// fetch old Database
|
// 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();
|
||||||
|
|
||||||
// gather objects
|
// gather objects
|
||||||
// create new polls
|
// create new polls
|
||||||
// success
|
// success
|
||||||
// failure notice
|
// failure notice
|
||||||
|
|
||||||
return $this->json( [ "message" => "welcome to the framadate migration endpoint, it has yet to be done" ],
|
return $this->json( [
|
||||||
|
"message" => "welcome to the framadate migration endpoint, it has yet to be done",
|
||||||
|
"debug" => $debug,
|
||||||
|
],
|
||||||
200 );
|
200 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user