Fixes vim mode line.
[platal.git] / upgrade / 1.0.1 / merge_accent_names.php
CommitLineData
ce30bbea
SJ
1#!/usr/bin/php5 -q
2<?php
3/***************************************************************************
c441aabe 4 * Copyright (C) 2003-2014 Polytechnique.org *
ce30bbea
SJ
5 * http://opensource.polytechnique.org/ *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., *
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
21 ***************************************************************************/
22
23require '../../bin/connect.db.inc.php';
24
25$globals->debug = 0; // Do not store backtraces
26
27
28$res = XDB::iterator("SELECT p.pid, p.ax_id, p.hrpid,
29 f.Nom_patronymique, f.Nom_usuel, f.Nom_complet,
30 ppn.lastname_initial, ppn.lastname_main, ppn.lastname_marital, ppn.lastname_ordinary
31 FROM fusionax_anciens AS f
32 INNER JOIN profiles AS p ON (f.ax_id = p.ax_id)
33 INNER JOIN profile_public_names AS ppn ON (p.pid = ppn.pid)
34 ORDER BY pid");
35
36function format($string)
37{
38 $string = preg_replace('/\-/', ' ', $string);
39 return preg_replace('/\s+/', ' ', $string);
40}
41
42$updates_count = 0;
43$count = 0;
44$total = $res->total();
45while ($item = $res->next()) {
46 array_map('trim', $item);
47 $ax_plain = array(
48 'Nom_patronymique' => mb_strtolower(replace_accent($item['Nom_patronymique'])),
49 'Nom_usuel' => mb_strtolower(replace_accent($item['Nom_usuel'])),
50 'Nom_complet' => mb_strtolower(replace_accent($item['Nom_complet']))
51 );
52 $ax = array();
53 foreach ($ax_plain as $key => $value) {
54 $ax[$key] = format($value);
55 }
56 $xorg = array(
57 'lastname_initial' => format(mb_strtolower(replace_accent($item['lastname_initial']))),
58 'lastname_main' => format(mb_strtolower(replace_accent($item['lastname_main']))),
59 'lastname_ordinary' => format(mb_strtolower(replace_accent($item['lastname_ordinary'])))
60 );
61
62 foreach ($xorg as $key => $name) {
63 $ax_key = array_search($name, $ax);
64 if ($ax_key !== false && mb_strtolower($item[$ax_key]) != mb_strtolower($item[$key]) && $ax_plain[$ax_key] == mb_strtolower($item[$key])) {
65 XDB::execute("UPDATE profile_public_names
66 SET $key = {?}
67 WHERE pid = {?}",
68 $item[$ax_key], $item['pid']);
69
70 ++$updates_count;
71 }
72 }
73
74 printf("\r%u / %u", $count, $total);
75 ++$count;
76}
77printf("\r%u / %u\n\n", $count, $total);
78
79echo "Nombre de mises à jour effectuées : " . $updates_count . ".\n";
80
448c8cdc 81// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
ce30bbea 82?>