Importscript von Drupal nach WordPress
Samstag, März 6th, 2010Endlich hat der AStA eine neue Webseite. Was auffällt ist vermutlich das Kopfzeilen Hintergründigbild das meinem vielleicht ein bisschen ähnelt. Die Jungs vom AStA haben beim anschauen meines Blogs ein bisschen inspirieren lassen. Toll an dem Bild, das ich von meinem Turm geschossen habe, ist nämlich das es die sich um die Sicht der ganzen FH-Aachen auf Aachen handelt, da alle Standorte sich hinter dem HBF befinden. Ich habe dafür einen Importscript von Drupal nach WordPress geschrieben. Wie immer habe ich es als PHP_CLI Anwendung auf der Konsole gemacht.
#!/usr/bin/php5
$link = mysql_connect('localhost', 'root', 'PW');
mysql_select_db("drupal",$link);
## Encoding Convert
function con($string)
{
return iconv ("UTF-8", "ISO-8859-1", $string);
}
### IMPORT SACIC SITES
$sql = '
SELECT "1" AS `post_author`,
`cms_content`.create_date AS `post_date`,
`cms_content`. modified_date AS `post_date_gmt`,
`cms_content_props`.`content` AS `post_content`,
`cms_content`.content_name AS `post_title`,
"publish" AS `post_status`,
"closed" AS `comment_status`,
"closed" AS `ping_status`,
`cms_content`.`content_alias` AS `post_name`,
`cms_content`.modified_date AS `post_modified`,
`cms_content`.modified_date AS `post_modified_gmt`,
"0" AS `post_parent`,
"0" AS `menu_order`,
"page" AS `post_type`,
"0" AS `comment_count`
FROM `cms_content`, `cms_content_props`
WHERE `cms_content`.`type`="content" AND
`cms_content`.`content_id`=`cms_content_props`.`content_id`
AND NOT `cms_content_props`.`content`=""
ORDER BY `cms_content`.hierarchy';
$sql = 'SELECT `news_id` , `news_category_id` , `news_title` , `news_data` , `news_date` ,
`summary` , `start_time` , `end_time` , `status` , `icon` , `create_date` , `modified_date` ,
`author_id` , `news_extra`
FROM `cms_module_news`';
$q = mysql_query($sql,$link);
mysql_select_db("wordpress",$link);
for(;$ds = mysql_fetch_array($q);)
{
$sql = "SELECT * FROM `wp_posts` WHERE `post_title`='".
mysql_real_escape_string(con( $ds['post_title'] )) ."'";
if(mysql_num_rows(mysql_query($sql,$link)) > 0)
{
#UPDATE
$sql = "UPDATE `wp_posts` SET `post_content`=
CONCAT(`post_content` , '" . mysql_real_escape_string(con( $ds['post_content'] )) ."')
WHERE `post_title`='". mysql_real_escape_string(con( $ds['post_title'] )) ."'";
}
else
{
$sql = "
INSERT INTO `wp_posts`
SET
`post_author`='1',
`post_date`='". $ds['post_date'] ."',
`post_date_gmt`='". $ds['post_date'] ."',
`post_content`='" . mysql_real_escape_string(con( $ds['post_content'] )) ."',
`post_title`='". mysql_real_escape_string(con( $ds['post_title'] )) ."',
`post_excerpt`='',
`post_status`='publish',
`comment_status`='closed',
`ping_status`='closed',
`post_password`='',
`post_name`='". $ds['post_name'] ."',
`to_ping`='',
`pinged`='',
`post_modified`='". $ds['post_modified'] ."',
`post_modified_gmt`='". $ds['post_modified'] ."',
`post_type`='page';
";
}
mysql_query($sql,$link) or die (mysql_error($link));
}
### Import Post
mysql_select_db("drupal",$link);
$sql = 'SELECT `news_id` , `news_category_id` , `news_title` , `news_data` ,
`news_date` , `summary` , `start_time` , `end_time` , `status` ,
`icon` , `create_date` , `modified_date` , `author_id` , `news_extra`
FROM `cms_module_news`';
$q = mysql_query($sql,$link);
mysql_select_db("wordpress",$link);
for(;$ds = mysql_fetch_array($q);)
{
$sql = "
INSERT INTO `wp_posts`
SET
`post_author`='1',
`post_date`='". $ds['create_date'] ."',
`post_date_gmt`='". $ds['create_date'] ."',
`post_content`='" . mysql_real_escape_string(con( $ds['news_data'] )) ."',
`post_title`='". mysql_real_escape_string(con( $ds['news_title'] )) ."',
`post_excerpt`='" . mysql_real_escape_string(con( $ds['summary'] )) ."',
`post_status`='publish',
`comment_status`='closed',
`ping_status`='closed',
`post_password`='',
`post_name`='". $ds['post_name'] ."',
`to_ping`='',
`pinged`='',
`post_modified`='". $ds['modified_date'] ."',
`post_modified_gmt`='". $ds['modified_date'] ."'
";
mysql_query($sql,$link) or die (mysql_error($link));
}
?>