| Line 21... |
Line 21... |
| 21 |
switch($cmd) {
|
21 |
switch($cmd) {
|
| 22 |
case 'migrerFormatSmartFlore' :
|
22 |
case 'migrerFormatSmartFlore' :
|
| 23 |
$this->migrerFormatSmartFlore();
|
23 |
$this->migrerFormatSmartFlore();
|
| 24 |
break;
|
24 |
break;
|
| Line 25... |
Line 25... |
| 25 |
|
25 |
|
| 26 |
case 'migrerSentiersSmartFlore' :
|
26 |
case 'migrerSentiersSmartFlore' :
|
| 27 |
$this->migrerSentiersSmartFlore();
|
27 |
$this->migrerSentiersSmartFlore();
|
| Line 28... |
Line 28... |
| 28 |
break;
|
28 |
break;
|
| 29 |
|
29 |
|
| 30 |
default:
|
30 |
default:
|
| Line 31... |
Line 31... |
| 31 |
}
|
31 |
}
|
| 32 |
}
|
32 |
}
|
| 33 |
|
33 |
|
| 34 |
protected function migrerSentiersSmartFlore() {
|
34 |
protected function migrerSentiersSmartFlore() {
|
| 35 |
$this->wiki = Registre::get('wikiApi');
|
35 |
$this->wiki = Registre::get('wikiApi');
|
| 36 |
$requete = 'SELECT * FROM '.$this->wiki->GetConfigValue('table_prefix').'pages WHERE latest = "Y" '.
|
36 |
$requete = 'SELECT * FROM '.$this->wiki->GetConfigValue('table_prefix').'pages WHERE latest = "Y" '.
|
| 37 |
'AND tag = "AccesProjet" ';
|
37 |
'AND tag = "AccesProjet" ';
|
| 38 |
|
38 |
|
| 39 |
$page_sentiers = $this->wiki->LoadSingle($requete);
|
39 |
$page_sentiers = $this->wiki->LoadSingle($requete);
|
| 40 |
// Attention les wiki sont en iso Argh%#[{!?
|
40 |
// Attention les wiki sont en iso Argh%#[{!?
|
| Line 41... |
Line 41... |
| 41 |
// Il faut convertir car sinon certains sentiers ne matcheront pas à leur propriétaire
|
41 |
// Il faut convertir car sinon certains sentiers ne matcheront pas à leur propriétaire
|
| 42 |
$page_sentiers['body'] = mb_convert_encoding($page_sentiers['body'], Config::get('encodage_appli'), Config::get('encodage_wiki'));
|
42 |
$page_sentiers['body'] = mb_convert_encoding($page_sentiers['body'], Config::get('encodage_appli'), Config::get('encodage_wiki'));
|
| 43 |
preg_match_all("|\[\[([^\]\]]*)\]\]|", $page_sentiers['body'], $sentiers, PREG_PATTERN_ORDER);
|
43 |
preg_match_all("|\[\[([^\]\]]*)\]\]|", $page_sentiers['body'], $sentiers, PREG_PATTERN_ORDER);
|
| 44 |
|
44 |
|
| Line 45... |
Line 45... |
| 45 |
// Seule une partie du tableau contenant les noms des sentiers nous interesse
|
45 |
// Seule une partie du tableau contenant les noms des sentiers nous interesse
|
| Line 46... |
Line 46... |
| 46 |
$sentiers = $sentiers[1];
|
46 |
$sentiers = $sentiers[1];
|
| 47 |
|
47 |
|
| 48 |
echo "Nombre de sentiers à migrer : ".count($sentiers)."\n";
|
48 |
echo "Nombre de sentiers à migrer : ".count($sentiers)."\n";
|
| Line 49... |
Line 49... |
| 49 |
|
49 |
|
| 50 |
$valeurs_sentiers_a_inserer = array();
|
50 |
$valeurs_sentiers_a_inserer = array();
|
| 51 |
|
51 |
|
| 52 |
$proprietaires_sentiers = array();
|
52 |
$proprietaires_sentiers = array();
|
| 53 |
// Chargement du fichier contenant les propriétaires à associer aux sentiers
|
53 |
// Chargement du fichier contenant les propriétaires à associer aux sentiers
|
| 54 |
$fichier = file(realpath(dirname(__FILE__)).'/proprietaires_sentiers.csv');
|
54 |
$fichier = file(realpath(dirname(__FILE__)).'/proprietaires_sentiers.csv');
|
| 55 |
|
55 |
|
| Line 56... |
Line 56... |
| 56 |
foreach ($fichier as $ligne) {
|
56 |
foreach ($fichier as $ligne) {
|
| Line 79... |
Line 79... |
| 79 |
|
79 |
|
| 80 |
$requete_insertion = 'INSERT INTO '.$this->wiki->GetConfigValue('table_prefix').'triples '.
|
80 |
$requete_insertion = 'INSERT INTO '.$this->wiki->GetConfigValue('table_prefix').'triples '.
|
| Line 81... |
Line 81... |
| 81 |
'(resource, property, value) VALUES ';
|
81 |
'(resource, property, value) VALUES ';
|
| 82 |
|
82 |
|
| 83 |
foreach($sentiers as $sentier) {
|
83 |
foreach($sentiers as $sentier) {
|
| - |
|
84 |
|
| 84 |
|
85 |
list($tag, $titre) = explode(' ', $sentier, 2);
|
| 85 |
list($tag, $titre) = explode(' ', $sentier, 2);
|
86 |
$titre = trim($titre);
|
| Line 86... |
Line 87... |
| 86 |
// Reconversion dans l'encodage du wiki pour l'insertion
|
87 |
// Reconversion dans l'encodage du wiki pour l'insertion
|
| 87 |
$titre_encode_wiki = mb_convert_encoding($titre, Config::get('encodage_wiki'), Config::get('encodage_appli'));
|
88 |
$titre_encode_wiki = mb_convert_encoding($titre, Config::get('encodage_wiki'), Config::get('encodage_appli'));
|
| 88 |
|
89 |
|
| 89 |
$requete = 'SELECT * FROM '.$this->wiki->GetConfigValue('table_prefix').'pages WHERE latest = "Y" '.
|
90 |
$requete = 'SELECT * FROM '.$this->wiki->GetConfigValue('table_prefix').'pages WHERE latest = "Y" '.
|
| Line 90... |
Line 91... |
| 90 |
'AND tag = "'.$tag.'" ';
|
91 |
'AND tag = "'.$tag.'" ';
|
| 91 |
|
92 |
|
| Line 103... |
Line 104... |
| 103 |
$valeurs_fiches_a_associer[] = "('".$fiche_du_sentier."', 'smartFlore.sentiers.fiche', '".addslashes(trim($titre_encode_wiki))."')";
|
104 |
$valeurs_fiches_a_associer[] = "('".$fiche_du_sentier."', 'smartFlore.sentiers.fiche', '".addslashes(trim($titre_encode_wiki))."')";
|
| 104 |
}
|
105 |
}
|
| 105 |
}
|
106 |
}
|
| 106 |
}
|
107 |
}
|
| Line 107... |
Line 108... |
| 107 |
|
108 |
|
| 108 |
$valeurs_a_inserer = $valeurs_sentiers_a_inserer + $valeurs_fiches_a_associer;
|
109 |
$valeurs_a_inserer = array_merge($valeurs_sentiers_a_inserer, $valeurs_fiches_a_associer);
|
| 109 |
$requete_insertion .= implode(', '."\n", $valeurs_a_inserer);
|
110 |
$requete_insertion .= implode(', '."\n", $valeurs_a_inserer);
|
| 110 |
// Tout est contenu dans la table triple du wiki, donc une seule requête suffit pour tout insérer
|
111 |
// Tout est contenu dans la table triple du wiki, donc une seule requête suffit pour tout insérer
|
| Line 111... |
Line 112... |
| 111 |
$this->wiki->Query($requete_insertion);
|
112 |
$this->wiki->Query($requete_insertion);
|
| Line 116... |
Line 117... |
| 116 |
|
117 |
|
| Line 117... |
Line 118... |
| 117 |
protected function migrerFormatSmartFlore() {
|
118 |
protected function migrerFormatSmartFlore() {
|
| 118 |
|
119 |
|
| 119 |
// sections "souples" - attention, ne seront pas "quotées" mais interprétées comme morceaux de regexp directement !
|
120 |
// sections "souples" - attention, ne seront pas "quotées" mais interprétées comme morceaux de regexp directement !
|
| 120 |
$sections = array("Fiche simplifi.+e Smart.+flore", "Introduction","Comment la reconna.+tre.+","Son histoire","Ses usages",".+(?:cologie|habitat).+","Ce qu.+il faut savoir.+","Sources");
|
121 |
$sections = array("Fiche simplifi.+e Smart.+flore", "Introduction","Comment la reconna.+tre.+","Son histoire","Ses usages",".+(?:cologie|habitat).+","Ce qu.+il faut savoir.+","Sources");
|
| 121 |
$nouvelles_sections = array(
|
122 |
$nouvelles_sections = array(
|
| 122 |
"Description" => array("Introduction","Comment la reconna.+tre.+","Son histoire"),
|
123 |
"Description" => array("Introduction","Comment la reconna.+tre.+","Son histoire"),
|
| 123 |
"Usages" => array("Ses usages", "Ce qu.+il faut savoir.+"),
|
124 |
"Usages" => array("Ses usages", "Ce qu.+il faut savoir.+"),
|
| 124 |
"Écologie & habitat" => array(".+(?:cologie|habitat).+"), // groupe non-capturant avec (?:a|b)
|
125 |
"Écologie & habitat" => array(".+(?:cologie|habitat).+"), // groupe non-capturant avec (?:a|b)
|
| Line 182... |
Line 183... |
| 182 |
// dûes à certaines antédiluviennités de wikini
|
183 |
// dûes à certaines antédiluviennités de wikini
|
| 183 |
exit;
|
184 |
exit;
|
| 184 |
}
|
185 |
}
|
| Line 185... |
Line 186... |
| 185 |
|
186 |
|
| 186 |
// http://stackoverflow.com/questions/834303/startswith-and-endswith-functions-in-php
|
187 |
// http://stackoverflow.com/questions/834303/startswith-and-endswith-functions-in-php
|
| 187 |
protected function endsWith($haystack, $needle) {
|
188 |
protected function endsWith($haystack, $needle) {
|
| 188 |
// search forward starting from end minus needle length characters
|
189 |
// search forward starting from end minus needle length characters
|
| 189 |
return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== FALSE);
|
190 |
return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== FALSE);
|
| 190 |
}
|
191 |
}
|
| 191 |
}
|
192 |
}
|