Line 17... |
Line 17... |
17 |
*/
|
17 |
*/
|
Line 18... |
Line 18... |
18 |
|
18 |
|
19 |
class Migrationwp extends Script {
|
19 |
class Migrationwp extends Script {
|
20 |
private $basewp = "wordpress.site_";
|
20 |
private $basewp = "wordpress.site_";
|
- |
|
21 |
private $table = "site_";
|
Line 21... |
Line 22... |
21 |
private $table = "site_";
|
22 |
private $doc_loc = array();
|
22 |
|
23 |
|
23 |
public function executer() {
|
24 |
public function executer() {
|
24 |
$this->bdd = new Bdd();
|
25 |
$this->bdd = new Bdd();
|
Line 48... |
Line 49... |
48 |
$retour = $this->migrerUtilisateurProfil();
|
49 |
$retour = $this->migrerUtilisateurProfil();
|
49 |
break;
|
50 |
break;
|
50 |
case "activite": // obligatoire pour affichage
|
51 |
case "activite": // obligatoire pour affichage
|
51 |
$retour = $this->migrerUtilisateurActivite();
|
52 |
$retour = $this->migrerUtilisateurActivite();
|
52 |
break;
|
53 |
break;
|
53 |
case "actualiteTout" :
|
54 |
case "actualiteTout" :
|
54 |
$retour = $this->migrerUtilisateurActualites();
|
55 |
$retour = $this->migrerActualites();
|
55 |
$retour .= $this->migrerUtilisateurActualitesRubrique();
|
56 |
$retour .= $this->migrerActualitesRubrique();
|
56 |
$retour .= $this->migrerUtilisateurActualitesCommentaire();
|
57 |
$retour .= $this->migrerActualitesCommentaires();
|
57 |
break;
|
58 |
break;
|
58 |
case "actualite" :
|
59 |
case "actualite" :
|
59 |
$retour = $this->migrerUtilisateurActualites();
|
60 |
$retour = $this->migrerActualites();
|
60 |
break;
|
61 |
break;
|
61 |
case "actualiteRubrique" :
|
62 |
case "actualiteRubrique" :
|
62 |
$retour = $this->migrerUtilisateurActualitesRubrique();
|
63 |
$retour = $this->migrerActualitesRubrique();
|
63 |
break;
|
64 |
break;
|
64 |
case "actualiteComm" :
|
65 |
case "actualiteComm" :
|
65 |
$retour = $this->migrerUtilisateurActualitesCommentaire();
|
66 |
$retour = $this->migrerActualitesCommentaires();
|
66 |
break;
|
67 |
break;
|
67 |
default: break;
|
68 |
default: break;
|
68 |
}
|
69 |
}
|
Line 69... |
Line 70... |
69 |
|
70 |
|
Line 183... |
Line 184... |
183 |
$retour[] = $this->bdd->executer($requete_insert);
|
184 |
$retour[] = $this->bdd->executer($requete_insert);
|
184 |
}
|
185 |
}
|
185 |
return $retour;
|
186 |
return $retour;
|
186 |
}
|
187 |
}
|
Line -... |
Line 188... |
- |
|
188 |
|
- |
|
189 |
private function migrerEvenements() {
|
- |
|
190 |
$retour = array();
|
- |
|
191 |
/*
|
- |
|
192 |
* */
|
- |
|
193 |
$requete = "";
|
- |
|
194 |
$articles = $this->bdd->recupererTous($requete);
|
- |
|
195 |
|
- |
|
196 |
|
- |
|
197 |
$requete_insert = "INSERT INTO ".$this->basewp."posts VALUES ".implode($insert, ', ').";";
|
- |
|
198 |
$retour[] = $this->bdd->executer($requete_insert);
|
- |
|
199 |
echo 'Il y a '.count($retour).' actualités migrées '."--";
|
- |
|
200 |
return $retour;
|
- |
|
201 |
}
|
- |
|
202 |
|
- |
|
203 |
private function migrerEvenementsRubrique() {
|
- |
|
204 |
$requete = "INSERT INTO ".$this->basewp."term_relationships (`object_id`, `term_taxonomy_id`)
|
- |
|
205 |
SELECT `bf_id_fiche` +10000, replace( replace( replace( replace( `bf_ce_nature` , '3', '39' ) , '4', '38' ) , '2', '37' ) , '1', '40' )
|
- |
|
206 |
FROM `bazar_fiche`
|
- |
|
207 |
WHERE year( `bf_date_debut_validite_fiche` ) =2016
|
- |
|
208 |
UNION SELECT `bf_id_fiche` +10000, 36 AS cat_evnt
|
- |
|
209 |
FROM `bazar_fiche`
|
- |
|
210 |
WHERE year( `bf_date_debut_validite_fiche` ) =2016";
|
- |
|
211 |
$retour = $this->bdd->executer($requete);
|
- |
|
212 |
echo 'Il y a '.count($retour).' actualités migrées '."--";
|
- |
|
213 |
return $retour;
|
- |
|
214 |
}
|
187 |
|
215 |
|
188 |
private function migrerActualites() {
|
216 |
private function migrerActualites() {
|
189 |
$retour = array();
|
217 |
$retour = array();
|
190 |
/*INSERT INTO `wp4_posts`
|
218 |
/*INSERT INTO `wp4_posts`
|
191 |
SELECT spip_articles.`id_article` as ID, `id_auteur` as post_author, `date` as post_date, `date` as post_date_gmt,
|
219 |
SELECT spip_articles.`id_article` as ID, `id_auteur` as post_author, `date` as post_date, `date` as post_date_gmt,
|
Line 196... |
Line 224... |
196 |
$requete = "SELECT spip_articles.`id_article` as ID, `id_auteur` as post_author, `date` as post_date, `date` as post_date_gmt,
|
224 |
$requete = "SELECT spip_articles.`id_article` as ID, `id_auteur` as post_author, `date` as post_date, `date` as post_date_gmt,
|
197 |
replace(replace(replace(replace(replace(replace(replace(replace(replace(convert( convert( texte USING latin1 ) USING utf8 ),'{{{{',''), '}}}}', '<!--more-->'), '{{{','<h2>'), '}}}', '</h2>'), '{{', '<strong>'), '}}', '</strong>'), '{', '<em>'), '}', '</em>'), '_ ', '') as post_content,
|
225 |
replace(replace(replace(replace(replace(replace(replace(replace(replace(convert( convert( texte USING latin1 ) USING utf8 ),'{{{{',''), '}}}}', '<!--more-->'), '{{{','<h2>'), '}}}', '</h2>'), '{{', '<strong>'), '}}', '</strong>'), '{', '<em>'), '}', '</em>'), '_ ', '') as post_content,
|
198 |
`titre` as post_title, \"\" as post_excerpt, replace(replace(replace(replace(replace(`statut`,'poubelle', 'trash'),'publie', 'publish'), 'prepa', 'private'), 'prop', 'pending'), 'refuse', 'trash') as post_status, \"open\" as comment_status, \"open\" as ping_status, \"\" as post_password, spip_articles.`id_article` as post_name, \"\" as to_ping, \"\" as pinged, `date_modif` as post_modified,`date_modif` as post_modified_gmt, \"\" as post_content_filtered, \"\" as post_parent,
|
226 |
`titre` as post_title, \"\" as post_excerpt, replace(replace(replace(replace(replace(`statut`,'poubelle', 'trash'),'publie', 'publish'), 'prepa', 'private'), 'prop', 'pending'), 'refuse', 'trash') as post_status, \"open\" as comment_status, \"open\" as ping_status, \"\" as post_password, spip_articles.`id_article` as post_name, \"\" as to_ping, \"\" as pinged, `date_modif` as post_modified,`date_modif` as post_modified_gmt, \"\" as post_content_filtered, \"\" as post_parent,
|
199 |
concat(\"http://tela-botanica.net/wpsite/actu\",spip_articles.`id_article`) as guid, \"0\" as menu_order, \"post\" as post_type, \"\" as post_mime_type, \"\" as comment_count FROM tela_prod_spip_actu.`spip_articles` left join tela_prod_spip_actu.spip_auteurs_articles on spip_auteurs_articles.`id_article` = spip_articles.`id_article` WHERE id_rubrique in (22,54,70,30,19,51)";
|
227 |
concat(\"http://tela-botanica.net/wpsite/actu\",spip_articles.`id_article`) as guid, \"0\" as menu_order, \"post\" as post_type, \"\" as post_mime_type, \"\" as comment_count FROM tela_prod_spip_actu.`spip_articles` left join tela_prod_spip_actu.spip_auteurs_articles on spip_auteurs_articles.`id_article` = spip_articles.`id_article` WHERE id_rubrique in (22,54,70,30,19,51)";
|
200 |
$articles = $this->bdd->recupererTous($requete);
|
228 |
$articles = $this->bdd->recupererTous($requete);
|
201 |
$requete_doc = "SELECT d.`id_document`, `fichier`, `id_article` FROM `spip_documents` d left join spip_documents_articles da on da.`id_document` = d.`id_document`";
|
229 |
$requete_doc = "SELECT d.`id_document`, `fichier`, `id_article` FROM tela_prod_spip_actu.`spip_documents` d left join tela_prod_spip_actu.spip_documents_articles da on da.`id_document` = d.`id_document`";
|
202 |
$documents = $this->bdd->recupererTous($requete_doc);
|
230 |
$documents = $this->bdd->recupererTous($requete_doc);
|
203 |
foreach ($documents as $doc) {
|
231 |
foreach ($documents as $doc) {
|
204 |
$doc_loc[$doc['id_document']] = $doc['fichier'];
|
232 |
$this->doc_loc[$doc['id_document']] = $doc['fichier'];
|
205 |
}
|
233 |
}$i=0;
|
206 |
foreach ($articles as $article) {
|
234 |
foreach ($articles as $article) {
|
- |
|
235 |
|
207 |
$article['post_content'] = preg_replace("\[(.*)->(.*)\]", '<a href="\2" target="_blank">\1</a>', $article['post_content']);
|
236 |
$article['post_content'] = preg_replace("/\[([^\[]*)\-\>([^\[]*)\]/", '<a href="\2" target="_blank">\1</a>', $article['post_content']);
|
208 |
//$images = preg_grep("\<img([0-9]*)\|[a-z]*\>", $article['post_content']);
|
237 |
//$images = preg_grep("\<img([0-9]*)\|[a-z]*\>", $article['post_content']);
|
209 |
$article['post_content'] = preg_replace("\<img([0-9]*)\|[a-z]*\>", '<img src="'.$doc_loc['${1}'].'" />', $article['post_content']);
|
238 |
$article['post_content'] = preg_replace_callback("/\<img([0-9]*)\|[a-z]*\>/", array($this, transformerNumEnUrl), $article['post_content']);
|
210 |
$insert[] = "(".implode($article, ', ').")";
|
239 |
$insert[] = "(".implode($this->bdd->proteger($article), ', ').")"; $i++;
|
- |
|
240 |
if ($i >50) {
|
- |
|
241 |
$requete_insert = "INSERT INTO ".$this->basewp."posts VALUES ".implode($insert, ', ').";";
|
- |
|
242 |
$retour[] = $this->bdd->executer($requete_insert);
|
- |
|
243 |
$insert = array(); $i = 0;
|
- |
|
244 |
}
|
211 |
}
|
245 |
}
|
212 |
$requete_insert = "INSERT INTO `wp4_posts` VALUES ".implode($insert, ', ').";";
|
246 |
$requete_insert = "INSERT INTO ".$this->basewp."posts VALUES ".implode($insert, ', ').";";
|
213 |
$retour[] = $this->bdd->executer($requete_insert);
|
247 |
$retour[] = $this->bdd->executer($requete_insert);
|
214 |
echo 'Il y a '.count($retour).' actualités migrées '."--";
|
248 |
echo 'Il y a '.count($retour).' actualités migrées '."--";
|
215 |
return $retour;
|
249 |
return $retour;
|
216 |
}
|
250 |
}
|
Line -... |
Line 251... |
- |
|
251 |
|
- |
|
252 |
private function transformerNumEnUrl($matches) {
|
- |
|
253 |
$remplace = "";
|
- |
|
254 |
if (isset($matches[1])) {
|
- |
|
255 |
$remplace = '<img src="http://www.tela-botanica.org/actu/'.$this->doc_loc[$matches[1]].'" \/\>';
|
- |
|
256 |
}
|
- |
|
257 |
return $remplace;
|
- |
|
258 |
}
|
217 |
|
259 |
|
218 |
private function migrerActualitesRubrique() {
|
260 |
private function migrerActualitesRubrique() {
|
219 |
$requete = "INSERT INTO ".$this->basewp."term_relationships`(`object_id`, `term_taxonomy_id`)
|
261 |
$requete = "INSERT INTO ".$this->basewp."term_relationships (`object_id`, `term_taxonomy_id`)
|
220 |
SELECT `id_article`, replace(replace(replace(replace(replace(replace(`id_rubrique`, 22, 20), 54, 21), 30, 23), 19, 24), 51, 25), 70, 22)
|
262 |
SELECT `id_article`, replace(replace(replace(replace(replace(replace(`id_rubrique`, 22, 20), 54, 21), 30, 23), 19, 24), 51, 25), 70, 22)
|
221 |
FROM `spip_articles` WHERE id_rubrique in (22,54,70,30,19,51)";
|
- |
|
222 |
|
263 |
FROM tela_prod_spip_actu.`spip_articles` WHERE id_rubrique in (22,54,70,30,19,51)";
|
223 |
$retour = $this->bdd->executer($requete);
|
264 |
$retour = $this->bdd->executer($requete);
|
224 |
echo 'Il y a '.count($retour).' actualités migrées '."--";
|
265 |
echo 'Il y a '.count($retour).' actualités migrées '."--";
|
225 |
return $retour;
|
266 |
return $retour;
|
Line 226... |
Line 267... |
226 |
}
|
267 |
}
|
227 |
|
268 |
|
228 |
private function migrerActualitesCommentaires() {
|
269 |
private function migrerActualitesCommentaires() {
|
229 |
$requete = "INSERT INTO ".$this->basewp.'comments`(`comment_ID`, `comment_post_ID`, `comment_author`, `comment_author_email`, `comment_author_url`, `comment_author_IP`, `comment_date`, `comment_date_gmt`, `comment_content`, `comment_karma`, `comment_approved`, `comment_agent`, `comment_type`, `comment_parent`, `user_id`)
|
270 |
$requete = "INSERT INTO ".$this->basewp.'comments (`comment_ID`, `comment_post_ID`, `comment_author`, `comment_author_email`, `comment_author_url`, `comment_author_IP`, `comment_date`, `comment_date_gmt`, `comment_content`, `comment_karma`, `comment_approved`, `comment_agent`, `comment_type`, `comment_parent`, `user_id`)
|
230 |
SELECT `id_forum` , `id_article` , `auteur` , `email_auteur` , "" AS url, `ip` , `date_heure` , `date_heure` AS gmt, `texte` , "0" AS karma, replace(`statut`, "publie", "1") , "" AS agent, "" AS
|
271 |
SELECT `id_forum` , `id_article` , `auteur` , `email_auteur` , "" AS url, `ip` , `date_heure` , `date_heure` AS gmt, `texte` , "0" AS karma, replace(`statut`, "publie", "1") , "" AS agent, "" AS
|
231 |
TYPE , `id_parent` , `id_auteur`
|
272 |
TYPE , `id_parent` , `id_auteur`
|