'; ?> Movable Type -> Nucleus database conversion tool

Movable Type -> Nucleus database conversion tool

Version 1.1

Created by Olli Savolainen, inbox [ät] pilpi [dot] net

Before you can do anything with this script "; echo "you must edit the configuration variables in "; echo "the source of this file. Instructions are included in the "; echo "source as well.


"; } else{ ?> />Commit conversion (entries and comments)
/>Show SQL query (if not committing only entry queries possible)
"; foreach ($data as $a=>$b){ echo "# $a = $b
"; } echo "

"; } if ($_GET['commit']||$_GET['show']){ // begin script, connect to database server echo "# Exporting data...

"; // export the entries from Movable Type $query1="SELECT entry_id,entry_blog_id,entry_text, entry_status,"; $query1.=" entry_category_id, entry_title, entry_text, entry_text_more,"; $query1.=" entry_created_on FROM ".$data['mt_entry_table']." ORDER BY"; $query1.=" entry_id ASC"; mysql_select_db ($data['export_database'] ,$exportCon); $result = mysql_query($query1,$exportCon); //initialize entry- and comment counters $i=0; $c=0; echo "

"; } while ($row = mysql_fetch_assoc($result)) { //echo $row['entry_blog_id'] . $data['mt_blog_id']."IIII
"; if ($row['entry_blog_id']==$data['mt_blog_id']){ $i++; foreach ($row as $a=>$b){ if ($data['nucleus_version']!="2.0"){ $n=html_entity_decode($b,ENT_NOQUOTES); } $n=str_replace("\n","
\n", $n); $row[$a]=mysql_escape_string($n); } mysql_select_db ($data['export_database'] ,$exportCon); // MT stores the categories of its entries in a special table $placement_query="SELECT placement_entry_id,placement_category_id"; $placement_query.=" FROM ".$data['mt_placement_table']." WHERE"; $placement_query.=" placement_entry_id='".$row['entry_id']."'"; $placement_result = mysql_query($placement_query,$exportCon) or die ("Error: ".mysql_error()); $placement_row = mysql_fetch_assoc($placement_result); $catid = $placement_row['placement_category_id']; $catid=$mt_category[$catid]; // category id acquired, so free the resources taken up by that query mysql_free_result($placement_result); // if it's a draft in MT, make it a draft in Nucleus as well // (too bad you currently can't make a published entry a draft // in Nucleus like you can in MT) if ($row['entry_status']==$data['mt_published_status']){ $draft=$data['nucleus_published_status']; } else{ $draft=$data['nucleus_draft_status']; } // generate the main query to insert the entry // excuse the strange variable name ;) $gogo="INSERT into ".$data['nucleus_entry_table']; $gogo.="(ititle,ibody,imore,iblog,iauthor,itime,iclosed,idraft,"; $gogo.="ikarmapos,icat,ikarmaneg) VALUES "; $gogo.="('".$row['entry_title']."','".$row['entry_text']."','"; $gogo.=$row['entry_text_more']."','".$data['nucleus_blog_id']."','"; $gogo.=$data['nucleus_blog_author']."','".$row['entry_created_on']; $gogo.="','0','".$draft."','0','".$catid."','0')"; if ($_GET['commit']==1){ echo "

# Importing data...

"; //mysql_close(); //$connection = connectDB($export_password,$import_password,$data,0); mysql_select_db ($data['import_database'] ,$importCon); mysql_query($gogo,$importCon) or die("# Could not insert: " . mysql_error()); // get the inserted entry's new id to be used while inserting // the comments of the entry $citem=mysql_insert_id(); echo "# Entry: ".$row['entry_id']."=>$citem"; echo " titled \"".$row['entry_title']."\"
"; } // if requested, display the INSERT query for the entry // html entities need to be converted for the web page, // but if the entries already contain entities, those should // _not_ be converted again if ($_GET['show']==1) echo htmlentities2($gogo)."
"; //mysql_close(); //$connection = connectDB($export_password,$import_password,$data,1); // get the comments for the entry mysql_select_db ($data['export_database'] ,$exportCon); $comments_query = "SELECT comment_entry_id,comment_ip,comment_author"; $comments_query .= ",comment_email,comment_url,comment_text,"; $comments_query .= "comment_created_on FROM ". $data['mt_comment_table']; $comments_query .= " WHERE comment_entry_id='".$row['entry_id']."'"; $comments_result = mysql_query($comments_query,$exportCon) or die ("# ...".mysql_error()); // process all the comments for a particular entry while ($comments_row = mysql_fetch_assoc($comments_result)){ $c++; $cmember="";$cuser="";$cmail=""; foreach ($comments_row as $a=>$b){ if ($data['nucleus_version']!="2.0"){ $n=html_entity_decode($b,ENT_NOQUOTES); } //echo "".$a."---".$b.""; $comments_row[$a]=mysql_escape_string($n); } $cip=$comments_row['comment_ip']; // since MT only stores the ip, get the _current_ // hostname for it - not ideal, but will do if ($data['resolve_ips']){ $chost=gethostbyaddr($cip); } // if the comment is by the special user, (determined by the string // defined by the user in $data['mt_special_user'] ) // let's not insert name or email, just the member id in // $data['nucleus_special_user'] $su=stristr($comments_row['comment_author'], $data['mt_special_user']); if ((!empty($data['mt_special_user'])) && ($su)){ $cmember=$data['nucleus_special_user']; } else{ $cmember=0; $cuser=$comments_row['comment_author']; if (strcmp($comments_row['comment_url'],"")) $cmail=$comments_row['comment_email']; else $cmail=$comments_row['comment_url']; } // the INSERT query for the comment $cgogo="INSERT into ".$data['nucleus_comment_table']; $cgogo.="(cbody,cuser,"; $cgogo.="cmail,cmember,citem,ctime,chost,cip,cblog) VALUES "; $cgogo.="('".$comments_row['comment_text']."','".$cuser."','"; $cgogo.=$cmail."','".$cmember."','".$citem."','"; $cgogo.=$comments_row['comment_created_on']."','".$chost."','"; $cgogo.=$cip."','1')"; // echo the INSERT row only if the conversion is being committed // (it's not possible to know what the INSERT row for the // conversion is before actually importing the entries first, // since only after importing the entries do we know the numbers // of the new entries with which the comments should be associated. if ($_GET['commit']==1){ echo "#   --Comment at: "; echo $comments_row['comment_created_on']."
"; if ($_GET['show']==1) echo htmlentities2($cgogo).";
"; mysql_select_db ($data['import_database'] ,$importCon); mysql_query($cgogo,$importCon) or die("# Could not insert: " . mysql_error()); } } mysql_free_result($comments_result); } } mysql_free_result($result); echo "

"; echo "

# Conversion successful with $i entries and $c comments.

"; function connectDB($export_password,$import_password,$data,$export){ $result; //global $data; if($export==1){ $current_password=$export_password; $current_user=$data['export_user']; $current_server=$data['export_server']; } else{ $current_password=$import_password; $current_user=$data['import_user']; $current_server=$data['import_server']; } $result=mysql_connect($current_server, $current_user, $current_password) or die("# Could not connect: " . mysql_error()); // select the database if($data['export_database']!=$data['import_database']){ if ($export) $s="export"; else $s="import"; echo "

# Connected to $s database ".$data[$s.'_database']; echo " at ".$data[$s.'_server'].".

"; } else if ($export==1){ echo "

# Connected to database ".$data['export_database']; echo " at ".$data['export_server'].".

"; } //or die("Could not connect: " . mysql_error()); return $result; } function htmlentities2($myHTML) { // from http://php.net/manual/en/function.htmlentities.php $translation_table=get_html_translation_table (HTML_ENTITIES,ENT_QUOTES); $translation_table[chr(38)] = '&'; $regexp="/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/"; $result=preg_replace($regexp,"&", strtr($myHTML, $translation_table)); return $result; } function html_entity_decode( $given_html, $quote_style = ENT_QUOTES ) { // from http://php.net/manual/en/function.html-entity-decode.php $trans_table = get_html_translation_table( HTML_SPECIALCHARS, $quote_style ); if( $trans_table["'"] != ''' ) { # some versions of PHP match single quotes to ' $trans_table["'"] = '''; } return ( strtr( $given_html, array_flip( $trans_table ) ) ); } ?>