| Line 12... |
Line 12... |
| 12 |
|
12 |
|
| Line 13... |
Line 13... |
| 13 |
class MigrationSmartFlore extends Script {
|
13 |
class MigrationSmartFlore extends Script {
|
| Line 14... |
Line -... |
| 14 |
|
- |
|
| 15 |
protected $mode_verbeux = false;
|
- |
|
| 16 |
|
- |
|
| 17 |
// Paramêtres autorisées lors de l'appel au script en ligne de commande
|
- |
|
| 18 |
protected $parametres_autorises = array(
|
14 |
|
| 19 |
'-n' => array(true, true, 'Nom du fichier ou du dossier à traiter'));
|
- |
|
| 20 |
|
- |
|
| 21 |
public function executer() {
|
15 |
protected $mode_verbeux = false;
|
| 22 |
// L'obligation de mettre un paramètre -a donnée par le framework
|
16 |
|
| Line 23... |
Line 17... |
| 23 |
// n'a pas de sens, ça ne doit pas être obligatoire !!!
|
17 |
public function executer() {
|
| 24 |
$cmd = $this->getParametre('a');
|
18 |
$cmd = $this->getParametre('a');
|
| 25 |
$this->mode_verbeux = $this->getParametre('v');
|
19 |
$this->mode_verbeux = $this->getParametre('v');
|
| 26 |
|
20 |
|
| Line -... |
Line 21... |
| - |
|
21 |
switch($cmd) {
|
| - |
|
22 |
case 'migrerFormatSmartFlore' :
|
| - |
|
23 |
$this->migrerFormatSmartFlore();
|
| - |
|
24 |
break;
|
| 27 |
switch($cmd) {
|
25 |
|
| 28 |
case 'tous' :
|
26 |
case 'migrerSentiersSmartFlore' :
|
| 29 |
$this->migrerFormatSmartFlore();
|
27 |
$this->migrerSentiersSmartFlore();
|
| Line -... |
Line 28... |
| - |
|
28 |
break;
|
| - |
|
29 |
|
| - |
|
30 |
default:
|
| - |
|
31 |
}
|
| - |
|
32 |
}
|
| - |
|
33 |
|
| - |
|
34 |
protected function migrerSentiersSmartFlore() {
|
| - |
|
35 |
$this->wiki = Registre::get('wikiApi');
|
| - |
|
36 |
$requete = 'SELECT * FROM '.$this->wiki->GetConfigValue('table_prefix').'pages WHERE latest = "Y" '.
|
| - |
|
37 |
'AND tag = "AccesProjet" ';
|
| - |
|
38 |
|
| - |
|
39 |
$page_sentiers = $this->wiki->LoadSingle($requete);
|
| - |
|
40 |
|
| - |
|
41 |
preg_match_all("|\[\[([^\]\]]*)\]\]|", $page_sentiers['body'], $sentiers, PREG_PATTERN_ORDER);
|
| - |
|
42 |
$sentiers = $sentiers[1];
|
| - |
|
43 |
|
| - |
|
44 |
echo "Nombre de sentiers à migrer : ".count($sentiers)."\n";
|
| - |
|
45 |
|
| - |
|
46 |
$sentiers_a_inserer = array();
|
| - |
|
47 |
$valeurs_sentiers_a_inserer = array();
|
| - |
|
48 |
$fiches_a_associer = array();
|
| - |
|
49 |
|
| - |
|
50 |
$proprietaires_sentiers = array();
|
| - |
|
51 |
// Chargement du fichier contenant les propriétaires à associer aux sentiers
|
| - |
|
52 |
$fichier = file(realpath(dirname(__FILE__)).'proprietaires_sentiers.csv');
|
| - |
|
53 |
|
| - |
|
54 |
foreach ($fichier as $ligne) {
|
| - |
|
55 |
$data = str_getcsv($ligne);
|
| - |
|
56 |
if($data[2] != "") {
|
| - |
|
57 |
$proprietaires_sentiers[trim($data[0])] = trim($data[2]);
|
| - |
|
58 |
}
|
| - |
|
59 |
}
|
| - |
|
60 |
|
| - |
|
61 |
$courriel_proprietaires = array_values(array_unique($proprietaires_sentiers));
|
| - |
|
62 |
$url_infos_courriels = Config::get('annuaire_infos_courriels_url').implode(',', $courriel_proprietaires);
|
| - |
|
63 |
|
| - |
|
64 |
$infos_proprietaires = json_decode(file_get_contents($url_infos_courriels), true);
|
| - |
|
65 |
|
| - |
|
66 |
$infos_proprietaires_a_sentier = array();
|
| - |
|
67 |
|
| - |
|
68 |
foreach($proprietaires_sentiers as $nom_sentier => $proprietaire_sentier) {
|
| - |
|
69 |
if(isset($infos_proprietaires[$proprietaire_sentier])) {
|
| - |
|
70 |
$infos_proprietaires_a_sentier[$nom_sentier] = $infos_proprietaires[$proprietaire_sentier]['nomWiki'];
|
| - |
|
71 |
} else {
|
| - |
|
72 |
// les sentiers sans propriétaires sont affectés au compte accueil
|
| - |
|
73 |
$infos_proprietaires_a_sentier[$nom_sentier] = "AssociationTelaBotanica";
|
| - |
|
74 |
}
|
| - |
|
75 |
}
|
| - |
|
76 |
|
| - |
|
77 |
$requete_insertion = 'INSERT INTO '.$this->wiki->GetConfigValue('table_prefix').'triples '.
|
| - |
|
78 |
'(resource, property, value) VALUES ';
|
| - |
|
79 |
|
| - |
|
80 |
foreach($sentiers as $sentier) {
|
| - |
|
81 |
|
| - |
|
82 |
list($tag, $titre) = explode(' ', $sentier, 2);
|
| - |
|
83 |
|
| - |
|
84 |
$requete = 'SELECT * FROM '.$this->wiki->GetConfigValue('table_prefix').'pages WHERE latest = "Y" '.
|
| - |
|
85 |
'AND tag = "'.$tag.'" ';
|
| - |
|
86 |
|
| - |
|
87 |
$infos_sentier = $this->wiki->LoadSingle($requete);
|
| - |
|
88 |
|
| - |
|
89 |
$titre = trim($titre);
|
| - |
|
90 |
$proprietaire = !empty($infos_proprietaires_a_sentier[$titre]) ? $infos_proprietaires_a_sentier[$titre] : "AssociationTelaBotanica";
|
| - |
|
91 |
|
| - |
|
92 |
$sentiers_a_inserer[] = array(
|
| - |
|
93 |
'resource' => $titre,
|
| - |
|
94 |
'property' => 'smartFlore.sentiers',
|
| - |
|
95 |
'value' => $proprietaire
|
| - |
|
96 |
);
|
| - |
|
97 |
|
| - |
|
98 |
$valeurs_sentiers_a_inserer[] = "('".addslashes(trim($titre))."', 'smartFlore.sentiers', '".$proprietaire."')";
|
| - |
|
99 |
|
| - |
|
100 |
preg_match_all("|\[\[(SmartFlore[^(?:nt)]*nt[0-9]*)|", $infos_sentier['body'], $fiches_du_sentier, PREG_PATTERN_ORDER);
|
| - |
|
101 |
|
| - |
|
102 |
if(!empty($fiches_du_sentier[0])) {
|
| - |
|
103 |
foreach($fiches_du_sentier[1] as $fiche_du_sentier) {
|
| - |
|
104 |
$fiches_a_associer[] = array(
|
| - |
|
105 |
'resource' => $fiche_du_sentier,
|
| - |
|
106 |
'property' => 'smartFlore.sentiers.fiche',
|
| - |
|
107 |
'value' => $titre
|
| - |
|
108 |
);
|
| - |
|
109 |
|
| - |
|
110 |
$valeurs_fiches_a_associer[] = "('".$fiche_du_sentier."', 'smartFlore.sentiers.fiche', '".addslashes(trim($titre))."')";
|
| - |
|
111 |
}
|
| - |
|
112 |
}
|
| - |
|
113 |
}
|
| - |
|
114 |
|
| - |
|
115 |
$valeurs_a_inserer = $valeurs_sentiers_a_inserer + $valeurs_fiches_a_associer;
|
| - |
|
116 |
$requete_insertion .= implode(', '."\n", $valeurs_a_inserer);
|
| - |
|
117 |
// Tout est contenu dans la table triple du wiki, donc une seule requête suffit pour tout insérer
|
| 30 |
break;
|
118 |
$this->wiki->Query($requete_insertion);
|
| Line 31... |
Line 119... |
| 31 |
|
119 |
|
| 32 |
default:
|
120 |
echo 'Migration des sentiers effectuée'."\n";
|
| 33 |
}
|
121 |
exit;
|
| 34 |
}
|
122 |
}
|
| 35 |
|
123 |
|
| 36 |
protected function migrerFormatSmartFlore() {
|
124 |
protected function migrerFormatSmartFlore() {
|
| 37 |
|
125 |
|
| 38 |
// sections "souples" - attention, ne seront pas "quotées" mais interprétées comme morceaux de regexp directement !
|
126 |
// sections "souples" - attention, ne seront pas "quotées" mais interprétées comme morceaux de regexp directement !
|
| Line 39... |
Line 127... |
| 39 |
$sections = array("Fiche simplifi.+e Smart.+flore", "Introduction","Comment la reconna.+tre.+","Son histoire","Ses usages",".+(?:cologie|habitat).+","Ce qu.+il faut savoir.+","Sources");
|
127 |
$sections = array("Fiche simplifi.+e Smart.+flore", "Introduction","Comment la reconna.+tre.+","Son histoire","Ses usages",".+(?:cologie|habitat).+","Ce qu.+il faut savoir.+","Sources");
|
| 40 |
$nouvelles_sections = array(
|
128 |
$nouvelles_sections = array(
|
| 41 |
"Description" => array("Introduction","Comment la reconna.+tre.+","Son histoire"),
|
129 |
"Description" => array("Introduction","Comment la reconna.+tre.+","Son histoire"),
|