From ce30bbeae0ce14f5520a852bb520d3e040202d04 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Sat, 10 Dec 2011 18:30:03 +0100 Subject: [PATCH] Retrieves accents from AX. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- upgrade/1.0.1/merge_accent_names.php | 82 ++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 upgrade/1.0.1/merge_accent_names.php diff --git a/upgrade/1.0.1/merge_accent_names.php b/upgrade/1.0.1/merge_accent_names.php new file mode 100755 index 0000000..b8237a8 --- /dev/null +++ b/upgrade/1.0.1/merge_accent_names.php @@ -0,0 +1,82 @@ +#!/usr/bin/php5 -q +debug = 0; // Do not store backtraces + + +$res = XDB::iterator("SELECT p.pid, p.ax_id, p.hrpid, + f.Nom_patronymique, f.Nom_usuel, f.Nom_complet, + ppn.lastname_initial, ppn.lastname_main, ppn.lastname_marital, ppn.lastname_ordinary + FROM fusionax_anciens AS f + INNER JOIN profiles AS p ON (f.ax_id = p.ax_id) + INNER JOIN profile_public_names AS ppn ON (p.pid = ppn.pid) + ORDER BY pid"); + +function format($string) +{ + $string = preg_replace('/\-/', ' ', $string); + return preg_replace('/\s+/', ' ', $string); +} + +$updates_count = 0; +$count = 0; +$total = $res->total(); +while ($item = $res->next()) { + array_map('trim', $item); + $ax_plain = array( + 'Nom_patronymique' => mb_strtolower(replace_accent($item['Nom_patronymique'])), + 'Nom_usuel' => mb_strtolower(replace_accent($item['Nom_usuel'])), + 'Nom_complet' => mb_strtolower(replace_accent($item['Nom_complet'])) + ); + $ax = array(); + foreach ($ax_plain as $key => $value) { + $ax[$key] = format($value); + } + $xorg = array( + 'lastname_initial' => format(mb_strtolower(replace_accent($item['lastname_initial']))), + 'lastname_main' => format(mb_strtolower(replace_accent($item['lastname_main']))), + 'lastname_ordinary' => format(mb_strtolower(replace_accent($item['lastname_ordinary']))) + ); + + foreach ($xorg as $key => $name) { + $ax_key = array_search($name, $ax); + if ($ax_key !== false && mb_strtolower($item[$ax_key]) != mb_strtolower($item[$key]) && $ax_plain[$ax_key] == mb_strtolower($item[$key])) { + XDB::execute("UPDATE profile_public_names + SET $key = {?} + WHERE pid = {?}", + $item[$ax_key], $item['pid']); + + ++$updates_count; + } + } + + printf("\r%u / %u", $count, $total); + ++$count; +} +printf("\r%u / %u\n\n", $count, $total); + +echo "Nombre de mises à jour effectuées : " . $updates_count . ".\n"; + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +?> -- 2.1.4