Compare commits

..

2 Commits

Author SHA1 Message Date
b63b84d5bf emoji in migration 2021-04-19 23:35:18 +02:00
aff8d2a1ec migrate stuff and display a screen after all 2021-04-19 23:29:54 +02:00
8 changed files with 263 additions and 37 deletions

View File

@ -15,6 +15,7 @@
"friendsofsymfony/rest-bundle": "^3.0", "friendsofsymfony/rest-bundle": "^3.0",
"jms/serializer-bundle": "^3.9", "jms/serializer-bundle": "^3.9",
"sensio/framework-extra-bundle": "^6.1", "sensio/framework-extra-bundle": "^6.1",
"symfony/asset": "5.2.*",
"symfony/console": "5.2.*", "symfony/console": "5.2.*",
"symfony/dotenv": "5.2.*", "symfony/dotenv": "5.2.*",
"symfony/flex": "^1.3.1", "symfony/flex": "^1.3.1",

71
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "cbc3e39376e9371be37305d6cd955251", "content-hash": "8c0122c4e542f317501dd66ea0f62a40",
"packages": [ "packages": [
{ {
"name": "composer/package-versions-deprecated", "name": "composer/package-versions-deprecated",
@ -2521,6 +2521,75 @@
], ],
"time": "2021-03-09T12:30:35+00:00" "time": "2021-03-09T12:30:35+00:00"
}, },
{
"name": "symfony/asset",
"version": "v5.2.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/asset.git",
"reference": "54a42aa50f9359d1184bf7e954521b45ca3d5828"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/asset/zipball/54a42aa50f9359d1184bf7e954521b45ca3d5828",
"reference": "54a42aa50f9359d1184bf7e954521b45ca3d5828",
"shasum": ""
},
"require": {
"php": ">=7.2.5"
},
"require-dev": {
"symfony/http-client": "^4.4|^5.0",
"symfony/http-foundation": "^4.4|^5.0",
"symfony/http-kernel": "^4.4|^5.0"
},
"suggest": {
"symfony/http-foundation": ""
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\Asset\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/asset/tree/v5.2.4"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2021-01-27T10:01:46+00:00"
},
{ {
"name": "symfony/cache", "name": "symfony/cache",
"version": "v5.2.6", "version": "v5.2.6",

View File

@ -8,3 +8,8 @@ et pour mettre à jour le schéma en base de données
```bash ```bash
php bin/console doctrine:schema:update --force php bin/console doctrine:schema:update --force
``` ```
# Ressources
les types de champ Doctrine:
https://www.doctrine-project.org/projects/doctrine-orm/en/2.8/reference/basic-mapping.html#doctrine-mapping-types

View File

@ -6,6 +6,7 @@ namespace App\Controller;
use App\Entity\Choice; use App\Entity\Choice;
use App\Entity\Comment; use App\Entity\Comment;
use App\Entity\StackOfVotes; use App\Entity\StackOfVotes;
use App\Entity\Vote;
use App\Repository\PollRepository; use App\Repository\PollRepository;
use App\Service\MailService; use App\Service\MailService;
use FOS\RestBundle\Controller\Annotations\Get; use FOS\RestBundle\Controller\Annotations\Get;
@ -28,49 +29,49 @@ class MigrationController extends FramadateController {
public function indexAction( $unique_key ) { public function indexAction( $unique_key ) {
// get env vars // get env vars
// check uniq key is good
if ( $unique_key !== $this->getParameter( 'UNIQ_INSTALL_KEY' ) ) { if ( $unique_key !== $this->getParameter( 'UNIQ_INSTALL_KEY' ) ) {
return new JsonResponse( [ return new JsonResponse( [
'error' => 'NOPE! veuillez vérifier votre fichier .env', 'error' => 'NOPE! veuillez vérifier votre fichier .env',
] ); ] );
}; };
// check uniq key is good
// fetch old Database // fetch old Database
// connec
$debug = ''; $debug = '';
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$pollsBySlug = []; $pollsBySlug = [];
$pdo_options[ \PDO::ATTR_ERRMODE ] = \PDO::ERRMODE_EXCEPTION; $pdo_options[ \PDO::ATTR_ERRMODE ] = \PDO::ERRMODE_EXCEPTION;
$bdd = new \PDO( 'mysql:host=localhost;dbname=' . $this->getParameter( 'OLD_DATABASE_NAME' ), $bdd = new \PDO( 'mysql:host=localhost;dbname=' . $this->getParameter( 'OLD_DATABASE_NAME' ),
$this->getParameter( 'OLD_DATABASE_USER' ), $this->getParameter( 'OLD_DATABASE_USER' ),
$this->getParameter( 'OLD_DATABASE_PASS' ), $this->getParameter( 'OLD_DATABASE_PASS' ),
$pdo_options ); $pdo_options );
$res_Poll = $bdd->query( 'SELECT * FROM fd_poll' ); $res_polls = $bdd->query( 'SELECT * FROM fd_poll' );
while ( $d = $res_Poll->fetch( \PDO::FETCH_OBJ ) ) { while ( $d = $res_polls->fetch( \PDO::FETCH_OBJ ) ) {
echo "<html> <body> ";
echo "<br> migration du sondage $d->title , $d->id , "; $debug .= " <br> ajout de sondage : ".$d->title .' - '. $d->id ;
var_dump($d);
$newPoll = new Poll(); $newPoll = new Poll();
$owner = new Owner(); $owner = new Owner();
$owner->setEmail( $d->admin_mail ) $owner->setEmail( $d->admin_mail )
->setPseudo( $d->admin_name ); ->setPseudo( $d->admin_name )
$owner->addPoll($newPoll); ->addPoll($newPoll);
$newPoll $newPoll
->setOwner( $owner ) ->setOwner( $owner )
->setCustomURL( $d->id ) ->setCustomURL( $d->id )
// ->setKind( $d->id === 'D' ? 'date' : 'text' ) ->setKind( $d->id === 'D' ? 'date' : 'text' )
->setHideResults( ! $d->results_publicly_visible ) ->setHideResults( ! $d->results_publicly_visible )
->setAdminKey( $d->admin_id ) ->setAdminKey( $d->admin_id )
->setTitle( $d->title ) ->setTitle( $d->title )
// ->setVotesAllowed( $d->receiveNewVotes ) ->setVotesAllowed( $d->receiveNewVotes )
// ->setCommentsAllowed( $d->receiveNewComments ) ->setCommentsAllowed( $d->receiveNewComments )
->setChoicesMax( $d->ValueMax ) ->setChoicesMax( $d->ValueMax )
->setPassword( $d->password_hash ) ->setPassword( $d->password_hash )
->setDescription( $d->description ) ->setDescription( $d->description )
@ -79,13 +80,18 @@ class MigrationController extends FramadateController {
$pollsBySlug[ $d->id ] = $newPoll; $pollsBySlug[ $d->id ] = $newPoll;
// $em->persist( $owner ); $em->persist( $owner );
// $em->persist( $newPoll ); $em->persist( $newPoll );
} }
// get choices, slots and link them with poll by their slug // get choices, slots and link them with poll by their slug
$res_slots = $bdd->query( 'SELECT * FROM fd_slot' ); $res_slots = $bdd->query( 'SELECT * FROM fd_slot' );
$pollChoicesOrderedBySlug = [];
$choicesCreated = [];
while ( $d = $res_slots->fetch( \PDO::FETCH_OBJ ) ) { while ( $d = $res_slots->fetch( \PDO::FETCH_OBJ ) ) {
$debug .= " <br> ajout de slot, converti en choix de réponse : ".$d->poll_id. ' : '. $d->moments;
$pollSlug = $d->poll_id; $pollSlug = $d->poll_id;
$poll = $pollsBySlug[$pollSlug]; $poll = $pollsBySlug[$pollSlug];
@ -94,50 +100,78 @@ class MigrationController extends FramadateController {
$newChoice = new Choice(); $newChoice = new Choice();
$newChoice $newChoice
->setPoll($poll) ->setPoll($poll)
->setDateTime($d->title) ->setDateTime(date_create( strtotime( $d->title)))
->setName($moment); ->setName($moment);
$poll->addChoice($newChoice); $pollChoicesOrderedBySlug[$pollSlug][] = $newChoice;
$poll->addChoice($newChoice);
// $em->persist( $newChoice ); $em->persist( $newChoice );
// $em->persist( $newPoll ); $em->persist( $newPoll );
$choicesCreated[] = $newChoice;
} }
} }
// get choices, slots and link them with poll by their slug // get votes
$stacksOfVote = [];
$res_votes = $bdd->query( 'SELECT * FROM fd_vote' ); $res_votes = $bdd->query( 'SELECT * FROM fd_vote' );
while ( $d = $res_votes->fetch( \PDO::FETCH_OBJ ) ) { while ( $d = $res_votes->fetch( \PDO::FETCH_OBJ ) ) {
$debug .= " <br> ajout de stack de vote : ".$d->name;
$pollSlug = $d->poll_id; $pollSlug = $d->poll_id;
$poll = $pollsBySlug[ $pollSlug ]; $poll = $pollsBySlug[ $pollSlug ];
$newStack = new StackOfVotes(); $newStack = new StackOfVotes();
$newOwner = new Owner();
$newOwner
->setPseudo($d->name)
->setEmail('the_anonymous_email_from_@_migration_offramadate.org')
->setModifierToken($d->uniqId)
;
$newStack->setPoll($poll) $newStack->setPoll($poll)
->setOwner($newOwner)
->setPseudo($d->name) ->setPseudo($d->name)
; ;
// each choice answer is encoded in a value : // each choice answer is encoded in a value :
// space character : no answer, 0 : no , 1 : maybe , 2 : yes
$voteCodes = explode( '', $d->moments ); $voteCodes = str_split($d->choices);
// get choices of the poll and answer accordingly // get choices of the poll and answer accordingly
$ii=0; $ii=0;
foreach ( $voteCodes as $vote_code ) { foreach ( $voteCodes as $vote_code ) {
if($vote_code !== ' '){ if($vote_code !== ' '){
$choice = $pollChoicesOrderedBySlug[$pollSlug][$ii];
// TODO $newVote = new Vote();
// $newStack->addVote($newVote);
$newVote
->setChoice($choice)
->setStacksOfVotes($newStack)
->setPoll($poll)
->setValue( $this->mapAnswerNumberToWord($vote_code))
;
$newStack->addVote($newVote);
$em->persist( $newVote );
$votes[] = $newVote;
} }
$ii++; $ii++;
} }
$poll->addStackOfVotes($newStack); $poll->addStackOfVote($newStack);
$em->persist( $newStack );
$stacksOfVote[] = $newStack;
} }
$res_votes = $bdd->query( 'SELECT * FROM fd_comment' ); $comments = [];
while ( $d = $res_votes->fetch( \PDO::FETCH_OBJ ) ) { $res_comments = $bdd->query( 'SELECT * FROM fd_comment' );
while ( $d = $res_comments->fetch( \PDO::FETCH_OBJ ) ) {
$debug .= " <br> ajout de commentaire : ".$d->name. ' '. $d->comment;
$pollSlug = $d->poll_id; $pollSlug = $d->poll_id;
$poll = $pollsBySlug[ $pollSlug ]; $poll = $pollsBySlug[ $pollSlug ];
@ -146,25 +180,56 @@ class MigrationController extends FramadateController {
$newComment->setPoll($poll) $newComment->setPoll($poll)
->setCreatedAt( date_create($d->date)) ->setCreatedAt( date_create($d->date))
->setText( $d->comment); ->setText( $d->comment)
// TODO update entities // TODO update entities
// ->setPseudo( $d->pseudo) ->setPseudo( $d->name);
$em->persist( $newComment ); $em->persist( $newComment );
; $comments[] = $newComment;
} }
// $em->flush();
// gather objects // gather objects
// create new polls // create new polls
$em->flush();
// success // success
// failure notice // failure notice
$debug .= " <br> <br> ça c'est fait. ";
return $this->json( [ return $this->render('pages/migration.html.twig' , [
"message" => "welcome to the framadate migration endpoint, it has yet to be done", "message" => "welcome to the framadate migration endpoint, it has yet to be done",
"debug" => $debug, "debug" => $debug,
], "OLD_DATABASE_NAME" => $this->getParameter( 'OLD_DATABASE_NAME' ),
200 ); "OLD_DATABASE_USER" => $this->getParameter( 'OLD_DATABASE_USER' ),
"counters" =>[
'polls' => count($pollsBySlug),
'comments' => count($comments),
'choices' => count($choicesCreated),
'stacks_of_votes' => count($stacksOfVote),
'votes' => count($votes),
]
]);
}
/**
* @param $numberToConvert
* conversion of answer:
* space character : no answer, 0 : no , 1 : maybe , 2 : yes
* @return string
*/
public function mapAnswerNumberToWord($numberToConvert){
$word = '';
switch ($numberToConvert){
case 0:
$word = 'no';
break;
case 1:
$word = 'maybe';
break;
case 2:
$word = 'yes';
break;
default:
$word = 'no';
}
return $word;
} }
} }

View File

@ -162,6 +162,9 @@
"swiftmailer/swiftmailer": { "swiftmailer/swiftmailer": {
"version": "v6.2.7" "version": "v6.2.7"
}, },
"symfony/asset": {
"version": "v5.2.4"
},
"symfony/cache": { "symfony/cache": {
"version": "v5.2.6" "version": "v5.2.6"
}, },

View File

@ -9,7 +9,7 @@
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"/> <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"/>
<link rel="stylesheet" href="styles.css" crossorigin="anonymous"> <link rel="stylesheet" href="styles.css" crossorigin="anonymous">
<title>{% block title %}Framdate{% endblock %}</title> <title>{% block title %}Framadate{% endblock %}</title>
{# {% block stylesheets %}#} {# {% block stylesheets %}#}
{# <link rel="stylesheet" href="{{ asset('build/vendors~app.css') }}">#} {# <link rel="stylesheet" href="{{ asset('build/vendors~app.css') }}">#}
{# <link rel="stylesheet" href="{{ asset('build/app.css') }}">#} {# <link rel="stylesheet" href="{{ asset('build/app.css') }}">#}

View File

@ -2,4 +2,5 @@
{% block outerBody %} {% block outerBody %}
<h1>Bienvenue à la maison!</h1> <h1>Bienvenue à la maison!</h1>
{% endblock %} {% endblock %}

View File

@ -0,0 +1,82 @@
{% extends 'base.html.twig' %}
{% block title %}migration depuis un Framadate version 1{% endblock %}
{% block body %}
<main>
<h1>🍰 Migration des sondages depuis un Framadate version 1 </h1>
<fieldset>
Depuis la base de données <strong>
{{ OLD_DATABASE_NAME }}
</strong>
avec l'utilisateur <strong>
{{ OLD_DATABASE_USER }}
</strong> vers la base symfony locale, telle que configurée dans le fichier <strong> .env </strong>.
</fieldset>
<fieldset>
🎉 Ont été migrés:
<ul>
<li>
🎈 Sondages: {{ counters.polls }}
</li>
<li>
🍾 stacks of vote: {{ counters.polls }}
</li>
<li>
🧁 slots : {{ counters.choices }}
</li>
<li>
🍰 votes : {{ counters.votes }}
</li>
<li>
☕ comments : {{ counters.comments }}
</li>
</ul>
</fieldset>
<section class="well">
<hr>
Debug:
<br>
{{ debug | nl2br}}
</section>
</main>
<style type="text/css">
main {
margin: 0 auto;
width: 90vw;
}
fieldset{
margin-bottom: 1em;
}
.well{
font-size: 0.85rem;
background: #dedede;
padding: 1em;
}
html, body, main, header, footer, div {
font-family: Ubuntu, Arial, sans-serif;
}
.email {
padding: 1em;
}
.footer-content {
margin-top: 1em;
background: #f2dff2;
}
ul {
border-left: 3px solid #f2dff2;
}
h1, h2, h3 {
color: #3c334a;
}
</style>
{% endblock %}