19,7 → 19,6 |
class Migrationwp extends Script { |
private $basewp = "wordpress.site_"; |
private $table = "site_"; |
private $doc_loc = array(); |
|
public function executer() { |
$this->bdd = new Bdd(); |
51,19 → 50,19 |
case "activite": // obligatoire pour affichage |
$retour = $this->migrerUtilisateurActivite(); |
break; |
case "actualiteTout" : |
$retour = $this->migrerActualites(); |
$retour .= $this->migrerActualitesRubrique(); |
$retour .= $this->migrerActualitesCommentaires(); |
break; |
case "actualiteTout" : |
$retour = $this->migrerUtilisateurActualites(); |
$retour .= $this->migrerUtilisateurActualitesRubrique(); |
$retour .= $this->migrerUtilisateurActualitesCommentaire(); |
break; |
case "actualite" : |
$retour = $this->migrerActualites(); |
$retour = $this->migrerUtilisateurActualites(); |
break; |
case "actualiteRubrique" : |
$retour = $this->migrerActualitesRubrique(); |
$retour = $this->migrerUtilisateurActualitesRubrique(); |
break; |
case "actualiteComm" : |
$retour = $this->migrerActualitesCommentaires(); |
$retour = $this->migrerUtilisateurActualitesCommentaire(); |
break; |
default: break; |
} |
186,33 → 185,6 |
return $retour; |
} |
|
private function migrerEvenements() { |
$retour = array(); |
/* |
* */ |
$requete = ""; |
$articles = $this->bdd->recupererTous($requete); |
|
|
$requete_insert = "INSERT INTO ".$this->basewp."posts VALUES ".implode($insert, ', ').";"; |
$retour[] = $this->bdd->executer($requete_insert); |
echo 'Il y a '.count($retour).' actualités migrées '."--"; |
return $retour; |
} |
|
private function migrerEvenementsRubrique() { |
$requete = "INSERT INTO ".$this->basewp."term_relationships (`object_id`, `term_taxonomy_id`) |
SELECT `bf_id_fiche` +10000, replace( replace( replace( replace( `bf_ce_nature` , '3', '39' ) , '4', '38' ) , '2', '37' ) , '1', '40' ) |
FROM `bazar_fiche` |
WHERE year( `bf_date_debut_validite_fiche` ) =2016 |
UNION SELECT `bf_id_fiche` +10000, 36 AS cat_evnt |
FROM `bazar_fiche` |
WHERE year( `bf_date_debut_validite_fiche` ) =2016"; |
$retour = $this->bdd->executer($requete); |
echo 'Il y a '.count($retour).' actualités migrées '."--"; |
return $retour; |
} |
|
private function migrerActualites() { |
$retour = array(); |
/*INSERT INTO `wp4_posts` |
226,41 → 198,28 |
`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, |
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)"; |
$articles = $this->bdd->recupererTous($requete); |
$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`"; |
$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`"; |
$documents = $this->bdd->recupererTous($requete_doc); |
foreach ($documents as $doc) { |
$this->doc_loc[$doc['id_document']] = $doc['fichier']; |
}$i=0; |
$doc_loc[$doc['id_document']] = $doc['fichier']; |
} |
foreach ($articles as $article) { |
|
$article['post_content'] = preg_replace("/\[([^\[]*)\-\>([^\[]*)\]/", '<a href="\2" target="_blank">\1</a>', $article['post_content']); |
$article['post_content'] = preg_replace("\[(.*)->(.*)\]", '<a href="\2" target="_blank">\1</a>', $article['post_content']); |
//$images = preg_grep("\<img([0-9]*)\|[a-z]*\>", $article['post_content']); |
$article['post_content'] = preg_replace_callback("/\<img([0-9]*)\|[a-z]*\>/", array($this, transformerNumEnUrl), $article['post_content']); |
$insert[] = "(".implode($this->bdd->proteger($article), ', ').")"; $i++; |
if ($i >50) { |
$requete_insert = "INSERT INTO ".$this->basewp."posts VALUES ".implode($insert, ', ').";"; |
$retour[] = $this->bdd->executer($requete_insert); |
$insert = array(); $i = 0; |
} |
$article['post_content'] = preg_replace("\<img([0-9]*)\|[a-z]*\>", '<img src="'.$doc_loc['${1}'].'" />', $article['post_content']); |
$insert[] = "(".implode($article, ', ').")"; |
} |
$requete_insert = "INSERT INTO ".$this->basewp."posts VALUES ".implode($insert, ', ').";"; |
$requete_insert = "INSERT INTO `wp4_posts` VALUES ".implode($insert, ', ').";"; |
$retour[] = $this->bdd->executer($requete_insert); |
echo 'Il y a '.count($retour).' actualités migrées '."--"; |
return $retour; |
} |
|
private function transformerNumEnUrl($matches) { |
$remplace = ""; |
if (isset($matches[1])) { |
$remplace = '<img src="http://www.tela-botanica.org/actu/'.$this->doc_loc[$matches[1]].'" \/\>'; |
} |
return $remplace; |
} |
|
private function migrerActualitesRubrique() { |
$requete = "INSERT INTO ".$this->basewp."term_relationships (`object_id`, `term_taxonomy_id`) |
$requete = "INSERT INTO ".$this->basewp."term_relationships`(`object_id`, `term_taxonomy_id`) |
SELECT `id_article`, replace(replace(replace(replace(replace(replace(`id_rubrique`, 22, 20), 54, 21), 30, 23), 19, 24), 51, 25), 70, 22) |
FROM tela_prod_spip_actu.`spip_articles` WHERE id_rubrique in (22,54,70,30,19,51)"; |
FROM `spip_articles` WHERE id_rubrique in (22,54,70,30,19,51)"; |
|
$retour = $this->bdd->executer($requete); |
echo 'Il y a '.count($retour).' actualités migrées '."--"; |
return $retour; |
267,7 → 226,7 |
} |
|
private function migrerActualitesCommentaires() { |
$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`) |
$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`) |
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 |
TYPE , `id_parent` , `id_auteur` |
FROM tela_prod_spip_actu.`spip_forum` |