Subversion Repositories Applications.annuaire

Compare Revisions

Ignore whitespace Rev 617 → Rev 618

/trunk/scripts/modules/migrationwp/Migrationwp.php
19,6 → 19,7
class Migrationwp extends Script {
private $basewp = "wordpress.site_";
private $table = "site_";
private $doc_loc = array();
public function executer() {
$this->bdd = new Bdd();
50,19 → 51,19
case "activite": // obligatoire pour affichage
$retour = $this->migrerUtilisateurActivite();
break;
case "actualiteTout" :
$retour = $this->migrerUtilisateurActualites();
$retour .= $this->migrerUtilisateurActualitesRubrique();
$retour .= $this->migrerUtilisateurActualitesCommentaire();
break;
case "actualiteTout" :
$retour = $this->migrerActualites();
$retour .= $this->migrerActualitesRubrique();
$retour .= $this->migrerActualitesCommentaires();
break;
case "actualite" :
$retour = $this->migrerUtilisateurActualites();
$retour = $this->migrerActualites();
break;
case "actualiteRubrique" :
$retour = $this->migrerUtilisateurActualitesRubrique();
$retour = $this->migrerActualitesRubrique();
break;
case "actualiteComm" :
$retour = $this->migrerUtilisateurActualitesCommentaire();
$retour = $this->migrerActualitesCommentaires();
break;
default: break;
}
185,6 → 186,33
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`
198,28 → 226,41
`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 `spip_documents` d left join spip_documents_articles da on da.`id_document` = d.`id_document`";
$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`";
$documents = $this->bdd->recupererTous($requete_doc);
foreach ($documents as $doc) {
$doc_loc[$doc['id_document']] = $doc['fichier'];
}
$this->doc_loc[$doc['id_document']] = $doc['fichier'];
}$i=0;
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("\<img([0-9]*)\|[a-z]*\>", '<img src="'.$doc_loc['${1}'].'" />', $article['post_content']);
$insert[] = "(".implode($article, ', ').")";
$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;
}
}
$requete_insert = "INSERT INTO `wp4_posts` VALUES ".implode($insert, ', ').";";
$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 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 `spip_articles` WHERE id_rubrique in (22,54,70,30,19,51)";
FROM tela_prod_spip_actu.`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;
226,7 → 267,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`