id]['unixtime'] = $row->unixtime;
}
// get the cats with their descriptions
$sql = "select categoryid, category_name, category_description from ".$s9y_prefix."category;";
$result = mysql_query($sql);
// put them in an array
$s9y_cats = array();
$s9y_updates =0; //counter
while($row = mysql_fetch_object($result)){
$s9y_cats[$row->categoryid]['name'] = $row->category_name;
$s9y_cats[$row->categoryid]['desc'] = $row->category_description;
$qry = "update ".$table_prefix."categories set category_description = '".mysql_escape_string($row->category_description)."' where category_description = '' and cat_name = '".mysql_escape_string($row->category_name)."' limit 1;";
if(!mysql_query($qry)){
print("Oops! an error occurred:
");
print(mysql_error()."
");
print($qry."
");
exit(0);
} else {
$s9y_updates++;
}
}
// now, get the category of the original post
$sql = "select * from ".$s9y_prefix."entrycat;";
$result = mysql_query($sql);
// put the results with the post
while($row = mysql_fetch_object($result)){
$s9y_wp_posts[$row->entryid]['cat'] = $row->categoryid;
$s9y_wp_posts[$row->entryid]['cat_name'] = $s9y_cats[$row->categoryid]['name'];
}
// fetch categories in wp
$sql = "select cat_ID, cat_name, category_nicename, category_description from ".$table_prefix."categories;";
$result = mysql_query($sql);
// put the results in the wp_cats
$wp_cats = array();
while($row = mysql_fetch_object($result)){
$wp_cats[$row->category_nicename]['name'] = $row->cat_name;
$wp_cats[$row->category_nicename]['cat_id'] = $row->cat_ID;
$wp_cats[$row->category_nicename]['description'] = $row->category_description;
}
// check the wp_tables for the entries
$post_updates = 0;
foreach($s9y_wp_posts as $id=>$v){
//again, we need an id where the times match
$sql = "select ".$table_prefix."posts.ID, ".$table_prefix."post2cat.category_id as wp_cat_id from ".$table_prefix."posts, ".$table_prefix."post2cat where ".$table_prefix."posts.ID = ".$table_prefix."post2cat.post_id and ".$table_prefix."posts.post_date='".$s9y_wp_posts[$id]['unixtime']."';";
$result = mysql_query($sql);
while($row = mysql_fetch_object($result)){
$s9y_wp_posts[$id]['wp_catid'] = $row->wp_cat_id;
$s9y_wp_posts[$id]['wp_cat_name'] = strtolower(str_replace(' ','-',$s9y_wp_posts[$id]['cat_name']));
$s9y_wp_posts[$id]['new_cat_id'] = $wp_cats[strtolower(str_replace(' ','-',$s9y_wp_posts[$id]['cat_name']))]['cat_id'];
//security check:
if(isset($s9y_wp_posts[$id]['new_cat_id']) && isset($s9y_wp_posts[$id]['cat_name'])){
// update
$s9y_wp_posts[$id]['update'] = "update ".$table_prefix."post2cat set category_id = ".$s9y_wp_posts[$id]['new_cat_id']." where post_id = ".$row->ID." limit 1;";
if(!mysql_query($s9y_wp_posts[$id]['update'])){
print("Oops! an error occurred:
");
print(mysql_error()."
");
print($qry."
");
exit(0);
} else {
$post_updates++;
}
}
}
}
mysql_close($link);
print("I have updated ".$s9y_updates." categories and ".$post_updates." posts.
");
?>