Complete the fix of accent problem during migration

This commit is contained in:
Olivier PEREZ 2015-02-26 23:03:49 +01:00
parent f40a9e5d2b
commit 6e442e02e3

View File

@ -113,10 +113,10 @@ VALUE (?,?,?,?,?,?,?,?,?,?,?,?)');
$insert->execute([ $insert->execute([
$row->id_sondage, $row->id_sondage,
$row->id_sondage_admin, $row->id_sondage_admin,
html_entity_decode($row->titre), $this->unescape($row->titre),
html_entity_decode($row->commentaires), $this->unescape($row->commentaires),
html_entity_decode($row->nom_admin), $this->unescape($row->nom_admin),
html_entity_decode($row->mail_admin), $this->unescape($row->mail_admin),
$row->date_creation, $row->date_creation,
$row->date_fin, $row->date_fin,
$row->format, $row->format,
@ -153,7 +153,11 @@ CREATE TABLE IF NOT EXISTS `' . Utils::table('slot') . '` (
$prepared = $pdo->prepare('INSERT INTO ' . Utils::table('slot') . ' (`poll_id`, `title`, `moments`) VALUE (?,?,?)'); $prepared = $pdo->prepare('INSERT INTO ' . Utils::table('slot') . ' (`poll_id`, `title`, `moments`) VALUE (?,?,?)');
foreach ($slots as $slot) { foreach ($slots as $slot) {
$prepared->execute([$slot->poll_id, $slot->title, !empty($slot->moments) ? $slot->moments : null]); $prepared->execute([
$slot->poll_id,
$this->unescape($slot->title),
!empty($slot->moments) ? $this->unescape($slot->moments) : null
]);
} }
} }
@ -186,8 +190,8 @@ VALUE (?,?,?)');
while ($row = $select->fetch(\PDO::FETCH_OBJ)) { while ($row = $select->fetch(\PDO::FETCH_OBJ)) {
$insert->execute([ $insert->execute([
$row->id_sondage, $row->id_sondage,
html_entity_decode($row->usercomment), $this->unescape($row->usercomment),
html_entity_decode($row->comment) $this->unescape($row->comment)
]); ]);
} }
} }
@ -207,14 +211,24 @@ CREATE TABLE IF NOT EXISTS `' . Utils::table('vote') . '` (
} }
private function migrateFromUserStudsToVote(\PDO $pdo) { private function migrateFromUserStudsToVote(\PDO $pdo) {
$pdo->exec(' $select = $pdo->query('
INSERT INTO `' . Utils::table('vote') . '` SELECT
(`poll_id`, `name`, `choices`)
SELECT
`id_sondage`, `id_sondage`,
`nom`, `nom`,
REPLACE(REPLACE(REPLACE(`reponses`, 1, \'X\'), 2, 1), \'X\', 2) REPLACE(REPLACE(REPLACE(`reponses`, 1, \'X\'), 2, 1), \'X\', 2) reponses
FROM `user_studs`'); FROM `user_studs`');
$insert = $pdo->prepare('
INSERT INTO `' . Utils::table('vote') . '` (`poll_id`, `name`, `choices`)
VALUE (?,?,?)');
while ($row = $select->fetch(\PDO::FETCH_OBJ)) {
$insert->execute([
$row->id_sondage,
$this->unescape($row->nom),
$row->reponses
]);
}
} }
private function transformSujetToSlot($sujet) { private function transformSujetToSlot($sujet) {
@ -252,4 +266,8 @@ INSERT INTO `' . Utils::table('vote') . '`
$pdo->exec('DROP TABLE `user_studs`'); $pdo->exec('DROP TABLE `user_studs`');
$pdo->exec('DROP TABLE `sondage`'); $pdo->exec('DROP TABLE `sondage`');
} }
private function unescape($value) {
return stripslashes(html_entity_decode($value, ENT_QUOTES));
}
} }