forked from LeedRSS/Leed
-
Notifications
You must be signed in to change notification settings - Fork 1
/
update-r93.php
85 lines (74 loc) · 2.19 KB
/
update-r93.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
error_reporting(E_ALL);
@set_time_limit(0);
/**
* met à jour la BDD de la rev92 à la rev 93
* Leed doit déjà être installé
* auteur : alefburzmali
*/
ob_start();
require 'constant.php';
// connexion
$mysql = new MySQLi(MYSQL_HOST,MYSQL_LOGIN,MYSQL_MDP,MYSQL_BDD);
$tables = array(
'c' => MYSQL_PREFIX.'configuration',
'e' => MYSQL_PREFIX.'event',
'f' => MYSQL_PREFIX.'feed',
'd' => MYSQL_PREFIX.'folder',
'u' => MYSQL_PREFIX.'user',
);
// on convertit toutes les tables
foreach ($tables as $tb)
{
echo '<br>conversion de la structure de la table '.$tb.' ... ';
ob_flush(); flush();
if (!$mysql->query('ALTER TABLE '.$tb.' CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci, ENGINE=InnoDB'))
{
echo 'erreur !<br>';
print_r($mysql->error_list);
ob_flush(); flush();
die(1);
}
echo 'ok';
}
// on passe la connexion en utf-8 pour traiter les données
$mysql->query('SET NAMES utf8');
// maintenant on va récupérer toutes les tables pour faire html_entity_decode
function convert($table, $champs)
{
global $mysql;
echo '<br>conversion des données de la table '.$table.' ... ';
ob_flush(); flush();
$res = $mysql->query('SELECT * FROM '.$table);
if ($res)
{
while ($row = $res->fetch_assoc())
{
$sql = 'UPDATE '.$table.' SET ';
$first = true;
foreach ($champs as $c)
{
$row[$c] = html_entity_decode($row[$c]);
$sql .= ($first?'':', '). $c .'="'.$mysql->real_escape_string($row[$c]).'"';
$first = false;
}
$sql .= ' WHERE id = '.$row['id'];
if (!$mysql->query($sql))
{
echo 'erreur champ '.$row['id'].'<br>';
print_r($mysql->error_list);
echo '<br>on continue ... ';
ob_flush(); flush();
}
}
echo 'ok';
$res->free();
}
}
// evenements
convert($tables['e'], array('title','creator','content','description'));
// feed
convert($tables['f'], array('name','description'));
// folder
convert($tables['d'], array('name'));
echo '<br>Conversion terminée';