update-r93.php 2.2 KB

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