From 5f4b91c3a925b7302a3ba2d533e98937be39bfd9 Mon Sep 17 00:00:00 2001 From: reine Date: Tue, 1 May 2012 14:08:46 +0900 Subject: [PATCH] =?utf8?q?convert,upgrades=E5=86=85=E3=81=AE=E3=82=B3?= =?utf8?q?=E3=83=BC=E3=83=89=E3=82=82=E5=90=AB=E3=82=81=E3=81=A6DB?= =?utf8?q?=E3=82=AF=E3=83=A9=E3=82=B9=E3=82=92=E4=BD=BF=E7=94=A8=E3=81=99?= =?utf8?q?=E3=82=8B=E3=82=B3=E3=83=BC=E3=83=89=E3=81=AB=E4=BF=AE=E6=AD=A3?= =?utf8?q?=EF=BC=88=E6=9C=AA=E3=83=86=E3=82=B9=E3=83=88=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- nucleus/convert/functions.inc.php | 71 ++++--- nucleus/convert/wordpress.php | 354 ++++++++++++++++++--------------- nucleus/libs/PLUGIN.php | 2 +- nucleus/libs/globalfunctions.php | 3 +- nucleus/upgrades/upgrade.functions.php | 33 +-- nucleus/upgrades/upgrade1.0.php | 10 +- nucleus/upgrades/upgrade1.1.php | 8 +- nucleus/upgrades/upgrade2.5.php | 2 +- nucleus/upgrades/upgrade3.3.php | 6 +- 9 files changed, 268 insertions(+), 221 deletions(-) diff --git a/nucleus/convert/functions.inc.php b/nucleus/convert/functions.inc.php index cf5fede..cf28fb5 100644 --- a/nucleus/convert/functions.inc.php +++ b/nucleus/convert/functions.inc.php @@ -804,9 +804,12 @@ class BlogImport { $query = 'INSERT INTO '.sql_table('item').' (ITITLE, IBODY, IMORE, IBLOG, IAUTHOR, ITIME, ICLOSED, IKARMAPOS, IKARMANEG, ICAT) ' . "VALUES ('$title', '$body', '$more', $blogid, $authorid, '$timestamp', $closed, $karmapos, $karmaneg, $category)"; - mysql_query($query) or die("Error while executing query: " . $query); + if ( DB::execute($query) === FALSE ) + { + die("Error while executing query: " . $query); + } - return mysql_insert_id(); + return DB::getInsertId(); } function sql_addToBlog($name, $shortname, $ownerid) { @@ -814,15 +817,18 @@ class BlogImport { $shortname = addslashes($shortname); // create new category first - mysql_query('INSERT INTO '.sql_table('category')." (CNAME, CDESC) VALUES ('General','Items that do not fit in another category')"); - $defcat = mysql_insert_id(); + DB::execute('INSERT INTO '.sql_table('category')." (CNAME, CDESC) VALUES ('General','Items that do not fit in another category')"); + $defcat = DB::getInsertId(); $query = 'INSERT INTO '.sql_table('blog')." (BNAME, BSHORTNAME, BCOMMENTS, BMAXCOMMENTS, BDEFCAT) VALUES ('$name','$shortname',1 ,0, $defcat)"; - mysql_query($query) or die("Error while executing query: " . $query); - $id = mysql_insert_id(); + if ( DB::execute($query) === FALSE ) + { + die("Error while executing query: " . $query); + } + $id = DB::getInsertId(); // update category row so it links to blog - mysql_query('UPDATE ' . sql_table('category') . ' SET cblog=' . intval($id). ' WHERE catid=' . intval($defcat)); + DB::execute('UPDATE ' . sql_table('category') . ' SET cblog=' . intval($id). ' WHERE catid=' . intval($defcat)); BlogImport::sql_addToTeam($id,$ownerid,1); @@ -842,9 +848,12 @@ class BlogImport { . ' (CUSER, CMAIL, CMEMBER, CBODY, CITEM, CTIME, CHOST, CBLOG, CIP) ' . "VALUES ('$name', '$url', $memberid, '$body', $itemid, '$timestamp', '$host', $blogid, '$ip')"; - mysql_query($query) or die("Error while executing query: " . $query); + if ( DB::execute($query) === FALSE ) + { + die("Error while executing query: " . $query); + } - return mysql_insert_id(); + return DB::getInsertId(); } function sql_addToTeam($blogid, $memberid, $admin) { @@ -852,13 +861,14 @@ class BlogImport { $query = 'INSERT INTO '.sql_table('team').' (TMEMBER, TBLOG, TADMIN) ' . "VALUES ($memberid, $blogid, $admin)"; - mysql_query($query) or die("Error while executing query: " . $query); + if ( DB::execute($query) === FALSE ) + { + die("Error while executing query: " . $query); + } - return mysql_insert_id(); + return DB::getInsertId(); } - - } // some sort of version checking @@ -890,9 +900,12 @@ if ($ver > 250) $query = 'INSERT INTO '.sql_table('item').' (ITITLE, IBODY, IMORE, IBLOG, IAUTHOR, ITIME, ICLOSED, IKARMAPOS, IKARMANEG, ICAT) ' . "VALUES ('$title', '$body', '$more', $blogid, $authorid, '$timestamp', $closed, $karmapos, $karmaneg, $category)"; - mysql_query($query) or die("Error while executing query: " . $query); + if ( DB::execute($query) === FALSE ) + { + die("Error while executing query: " . $query); + } - return mysql_insert_id(); + return DB::getInsertId(); } @@ -902,16 +915,18 @@ if ($ver > 250) $shortname = addslashes($shortname); // create new category first - mysql_query('INSERT INTO '.sql_table('category')." (CNAME, CDESC) VALUES ('General','Items that do not fit in another categort')"); - $defcat = mysql_insert_id(); + DB::execute('INSERT INTO '.sql_table('category')." (CNAME, CDESC) VALUES ('General','Items that do not fit in another categort')"); + $defcat = DB::getInsertId(); $query = 'INSERT INTO '.sql_table('blog')." (BNAME, BSHORTNAME, BCOMMENTS, BMAXCOMMENTS, BDEFCAT) VALUES ('$name','$shortname',1 ,0, $defcat)"; - mysql_query($query) or die("Error while executing query: " . $query); - $id = mysql_insert_id(); + if ( DB::execute($query) === FALSE ) + { + die("Error while executing query: " . $query); + } + $id = DB::getInsertId(); convert_addToTeam($id,$ownerid,1); - return $id; } @@ -927,9 +942,12 @@ if ($ver > 250) . ' (CUSER, CMAIL, CMEMBER, CBODY, CITEM, CTIME, CHOST, CBLOG, CIP) ' . "VALUES ('$name', '$url', $memberid, '$body', $itemid, '$timestamp', '$host', $blogid, '$ip')"; - mysql_query($query) or die("Error while executing query: " . $query); + if ( DB::execute($query) === FALSE ) + { + die("Error while executing query: " . $query); + } - return mysql_insert_id(); + return DB::getInsertId(); } // TODO: remove this function (replaced by BlogImport::sql_addToTeam) @@ -938,9 +956,12 @@ if ($ver > 250) $query = 'INSERT INTO '.sql_table('team').' (TMEMBER, TBLOG, TADMIN) ' . "VALUES ($memberid, $blogid, $admin)"; - mysql_query($query) or die("Error while executing query: " . $query); - - return mysql_insert_id(); + if ( DB::execute($query) === FALSE ) + { + die("Error while executing query: " . $query); + } + + return DB::getInsertId(); } function convert_showLogin($type) { diff --git a/nucleus/convert/wordpress.php b/nucleus/convert/wordpress.php index a35330b..cb00639 100644 --- a/nucleus/convert/wordpress.php +++ b/nucleus/convert/wordpress.php @@ -21,64 +21,70 @@ /* v1.1 - add robustness code for category creation and item adding (admun) v1.2 - add sql_table() -*/ + */ include("../../config.php"); - function def($s){ - if (isset($_POST[$s])) - echo addslashes(stripslashes($_POST[$s])); - else { - if (i18n::strpos($s,'host')!==FALSE) echo "localhost"; - if (i18n::strpos($s,'username')!==FALSE) echo "root"; - if (i18n::strpos($s,'wpprefix')!==FALSE) echo "wp_"; - } - } - - function error($s){ - global $isok; - $isok=false; - echo "

Error: $s

"; - } - - // line breaks into properly formatted paragraphs - function paragraph($text, $br = false) { - $text=trim($text); - $text = str_replace("\r",'',$text); - $text = preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $text); - if ($text=="") return ""; - $text = $text . "\n"; // just to make things a little easier, pad the end - $text = preg_replace('|
\s*
|', "\n\n", $text); - $text = preg_replace('!(<(?:table|ul|ol|li|pre|form|blockquote|h[1-6])[^>]*>)!', "\n$1", $text); // Space things out a little - $text = preg_replace('!()!', "$1\n", $text); // Space things out a little - $text = preg_replace("/(\r\n|\r)/", "\n", $text); // cross-platform newlines - $text = preg_replace("/\n\n+/", "\n\n", $text); // take care of duplicates - $text = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "\t

$1

\n", $text); // make paragraphs, including one at the end - $text = preg_replace('|

\s*?

|', '', $text); // under certain strange conditions it could create a P of entirely whitespace - $text = preg_replace("|

(|", "$1", $text); // problem with nested lists - // blockquote - $text = preg_replace('|

]*)>|i', "

", $text); - $text = str_replace('

', '

', $text); - // now the hard work - $text = preg_replace('!

\s*(]*>)!', "$1", $text); - $text = preg_replace('!(]*>)\s*

|"!', "$1", $text); - if ($br) $text = preg_replace('|(?)\s*\n|', "
\n", $text); // optionally make line breaks - $text = preg_replace('!(]*>)\s*
!', "$1", $text); - $text = preg_replace('!
(\s*)!', '$1', $text); - // some cleanup - $text = str_replace('


','

',$text); - $text = str_replace("
\n

",'

',$text); - return $text; - } +function def($s) +{ + if ( isset($_POST[$s]) ) + echo addslashes(stripslashes($_POST[$s])); + else + { + if ( i18n::strpos($s, 'host') !== FALSE ) echo "localhost"; + if ( i18n::strpos($s, 'username') !== FALSE ) echo "root"; + if ( i18n::strpos($s, 'wpprefix') !== FALSE ) echo "wp_"; + } +} + +function error($s) +{ + global $isok; + $isok = false; + echo "

Error: $s

"; +} + +// line breaks into properly formatted paragraphs +function paragraph($text, $br = false) +{ + $text = trim($text); + $text = str_replace("\r", '', $text); + $text = preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $text); + if ( $text == "" ) return ""; + $text = $text . "\n"; // just to make things a little easier, pad the end + $text = preg_replace('|
\s*
|', "\n\n", $text); + $text = preg_replace('!(<(?:table|ul|ol|li|pre|form|blockquote|h[1-6])[^>]*>)!', "\n$1", $text); // Space things out a little + $text = preg_replace('!()!', "$1\n", $text); // Space things out a little + $text = preg_replace("/(\r\n|\r)/", "\n", $text); // cross-platform newlines + $text = preg_replace("/\n\n+/", "\n\n", $text); // take care of duplicates + $text = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "\t

$1

\n", $text); // make paragraphs, including one at the end + $text = preg_replace('|

\s*?

|', '', $text); // under certain strange conditions it could create a P of entirely whitespace + $text = preg_replace("|

(|", "$1", $text); // problem with nested lists + // blockquote + $text = preg_replace('|

]*)>|i', "

", $text); + $text = str_replace('

', '

', $text); + // now the hard work + $text = preg_replace('!

\s*(]*>)!', "$1", $text); + $text = preg_replace('!(]*>)\s*

|"!', "$1", $text); + if ( $br ) $text = preg_replace('|(?)\s*\n|', "
\n", $text); + // optionally make line breaks + $text = preg_replace('!(]*>)\s*
!', "$1", $text); + $text = preg_replace('!
(\s*)!', '$1', $text); + // some cleanup + $text = str_replace('


', '

', $text); + $text = str_replace("
\n

", '

', $text); + return $text; +} + +function encoding($s) +{ + global $input; + if ( is_callable("iconv") ) + return iconv($input, 'utf-8', $s); + else + return $s; +} - function encoding($s){ - global $input; - if (is_callable("iconv")) - return iconv($input,'utf-8',$s); - else - return $s; - } - ?> @@ -104,130 +110,148 @@ a:hover{text-decoration:underline}

WordPress »» Nucleus CMS »» convertor

-

This tool will convert your WordPress blog (tested w/ 3.1.x), into Nucleus CMS weblog. First, install Nucleus, in a default install, and only after that run this tool. It will transfer all categories, posts, and comments into blog #1.

Please correct these errors first!


"; - } else { - /* */ - /* transfer data ! */ - /* */ - $prefixwp=$_POST['wpprefix']; - - /* *********************************************** */ - echo "

Getting encoding...

"; - $query="select option_value from ".$prefixwp."options where option_name='blog_charset'"; - $querywp=mysql_query($query,$linkwp) or die($query); - if ($row=mysql_fetch_object($querywp)) - $input=$row->option_value; - else - $input="utf-8"; - echo "

Encoding: $input

"; + $isok = true; - /* *********************************************** */ - echo "

Transfering categories...

"; - mysql_query("delete from ". sql_table('category') . " where cdesc='@wordpress'",$linkblogcms); - $q = mysql_query("SELECT count(*) as result FROM " . sql_table('category')); - $total_row = mysql_fetch_object($q); - $total_num = $total_row->result; - $catdd = $total_num; - $total_num++; + // connect to WordPress database + $linkwp = @mysql_connect($_POST['wphost'], $_POST['wpusername'], $_POST['wppassword'], true); + if ( $linkwp == false ) + error("Cannot connect to WordPress DB.."); + else + { + @mysql_select_db($_POST['wpdatabase'], $linkwp) or error("Cannot select WordPress DB..."); + } + + // connect to Nucleus CMS database + /* + $linkblogcms = @mysql_connect($_POST['blogcmshost'],$_POST['blogcmsusername'],$_POST['blogcmspassword'],true); + if($linkblogcms==false) + error("Cannot connect to Nucleus DB.."); + else { + @mysql_select_db($_POST['blogcmsdatabase'],$linkblogcms) or error("Cannot select Nucleus DB..."); + } + */ - $query="SELECT * FROM ".$prefixwp."term_taxonomy , ".$prefixwp."terms WHERE ".$prefixwp."term_taxonomy.term_taxonomy_id = ".$prefixwp."terms.term_id AND ".$prefixwp."term_taxonomy.taxonomy='category'"; - $querywp=mysql_query($query,$linkwp) or die($query); - echo "

rows to transfer: ".mysql_num_rows($querywp)."

"; - echo "

"; - $cate_map = array(); - while ($row=mysql_fetch_object($querywp)) { - echo $total_num.", "; - $cate_map[$row->term_id] = $total_num; - $query= - "INSERT INTO " . sql_table('category') . - " (catid,cblog,cname,cdesc) values (". - intval($total_num).",1,'".encoding($row->name)."','@wordpress')"; - $result = mysql_query($query,$linkblogcms) or die($query); - $total_num++; - } - echo "

"; + if ( !$isok ) + { + echo "

Please correct these errors first!


"; + } + else + { + /* */ + /* transfer data ! */ + /* */ + $prefixwp = $_POST['wpprefix']; - /* *********************************************** */ - echo "

Transfering posts and comments...

"; - mysql_query("delete from " . sql_table('comment') . " where chost='@wordpress'",$linkblogcms); - $query="select * from ".$prefixwp."posts where post_status='publish' order by ID"; - $querywp=mysql_query($query,$linkwp) or die($query); - echo "

rows to transfer: ".mysql_num_rows($querywp)."

"; - echo "

"; - $i=1; - while ($row=mysql_fetch_object($querywp)) { - echo $i++.", "; - // find category - $query = 'select * from '.$prefixwp.'term_relationships, '.$prefixwp.'term_taxonomy where '.$prefixwp.'term_relationships.term_taxonomy_id='.$prefixwp.'term_taxonomy.term_taxonomy_id and object_id='.$row->ID.' and '.$prefixwp.'term_taxonomy.taxonomy=\'category\' limit 1'; - $catwp = mysql_query($query, $linkwp) or die($query); - $category = mysql_fetch_object($catwp); - $cat = $cate_map[$category->term_id]; - if (empty($cat)) $cat = 1; + /* *********************************************** */ + echo "

Getting encoding...

"; + $query = "SELECT option_value FROM " . $prefixwp . "options WHERE option_name='blog_charset'"; + $querywp = mysql_query($query, $linkwp) or die($query); + if ( $row = mysql_fetch_object($querywp) ) + $input = $row->option_value; + else + $input = "utf-8"; + echo "

Encoding: $input

"; - // insert post - $query= - "INSERT INTO " . sql_table('item') . " ". - "(ititle,ibody,iblog,iauthor,itime,icat) values (". - "'".addslashes(encoding($row->post_title))."','".addslashes(paragraph(encoding(stripslashes($row->post_content)),false))."',1,1,'".$row->post_date."',$cat)"; - $result = mysql_query($query,$linkblogcms) or die($query); - $itemid=mysql_insert_id($linkblogcms); + /* *********************************************** */ + echo "

Transfering categories...

"; + DB::execute("DELETE FROM " . sql_table('category') . " WHERE cdesc='@wordpress'"); + $total_num = DB::getValue("SELECT count(*) as result FROM " . sql_table('category')); + $catdd = $total_num; + $total_num++; - // insert comments - $query="select * from ".$prefixwp."comments where comment_post_ID=".$row->ID; - $querywp_detail=mysql_query($query,$linkwp) or die($query); - while ($row_detail=mysql_fetch_object($querywp_detail)) { - $url=$row_detail->comment_author_email; - if (!empty($row_detail->comment_author_url)) $url=$row_detail->comment_author_url; - $query= - "INSERT INTO " . sql_table('comment') . - " (cbody,cuser,cmail,cmember,citem,ctime,cip,cblog,chost) values (". - "'".addslashes(paragraph(encoding(strip_tags(stripslashes($row_detail->comment_content))),true))."',". - "'".encoding($row_detail->comment_author)."',". - "'$url',". - "0,". - "$itemid,". - "'".$row_detail->comment_date."',". - "'".$row_detail->comment_author_IP."',". - "1,". - "'@wordpress')"; - $result = mysql_query($query,$linkblogcms) or die($query); - } - } - echo "

"; + $query = "SELECT * FROM " . $prefixwp . "term_taxonomy , " . $prefixwp . "terms WHERE " . $prefixwp . "term_taxonomy.term_taxonomy_id = " + . $prefixwp . "terms.term_id AND " . $prefixwp . "term_taxonomy.taxonomy='category'"; + $querywp = mysql_query($query, $linkwp) or die($query); + echo "

rows to transfer: " . mysql_num_rows($querywp) . "

"; + echo "

"; + $cate_map = array(); + while ( $row = mysql_fetch_object($querywp) ) + { + echo $total_num . ", "; + $cate_map[$row->term_id] = $total_num; + $query = sprintf("INSERT INTO %s (catid,cblog,cname,cdesc) VALUES (%d,1,'%s','@wordpress')" + , sql_table('category'), intval($total_num), encoding($row->name)); + if ( DB::execute($query) === FALSE ) + { + die($query); + } + $total_num++; + } + echo "

"; - // done - echo "

Done! Enjoy your stay in Nucleus

"; - die; - } + /* *********************************************** */ + echo "

Transfering posts and comments...

"; + DB::execute("DELETE FROM " . sql_table('comment') . " WHERE chost='@wordpress'"); + $query = "SELECT * FROM " . $prefixwp . "posts WHERE post_status='publish' ORDER BY ID"; + $querywp = mysql_query($query, $linkwp) or die($query); + echo "

rows to transfer: " . mysql_num_rows($querywp) . "

"; + echo "

"; + $i = 1; + while ( $row = mysql_fetch_object($querywp) ) + { + echo $i++ . ", "; + // find category + $query = 'SELECT * FROM ' . $prefixwp . 'term_relationships, ' . $prefixwp . 'term_taxonomy WHERE ' . $prefixwp + . 'term_relationships.term_taxonomy_id=' . $prefixwp . 'term_taxonomy.term_taxonomy_id AND object_id=' . $row->ID . ' AND ' + . $prefixwp . 'term_taxonomy.taxonomy=\'category\' LIMIT 1'; + $catwp = mysql_query($query, $linkwp) or die($query); + $category = mysql_fetch_object($catwp); + $cat = $cate_map[$category->term_id]; + if ( empty($cat) ) $cat = 1; + // insert post + $query = sprintf("INSERT INTO %s (ititle,ibody,iblog,iauthor,itime,icat) VALUES (%s,%s,1,1,'%s',%d)" + , sql_table('item') + , DB::quoteValue(encoding($row->post_title)) + , DB::quoteValue(paragraph(encoding(stripslashes($row->post_content)), false)) + , $row->post_date + , $cat); + if ( DB::execute($query) === FALSE ) + { + die($query); + } + $itemid = DB::getInsertId(); + + // insert comments + $query = "SELECT * FROM " . $prefixwp . "comments WHERE comment_post_ID=" . $row->ID; + $querywp_detail = mysql_query($query, $linkwp) or die($query); + while ( $row_detail = mysql_fetch_object($querywp_detail) ) + { + $url = $row_detail->comment_author_email; + if ( !empty($row_detail->comment_author_url) ) $url = $row_detail->comment_author_url; + $query = sprintf("INSERT INTO %s (cbody,cuser,cmail,cmember,citem,ctime,cip,cblog,chost)" + . " VALUES (%s,%s,%s,0,%d,'%s',%s,1,'@wordpress')" + , sql_table('comment') + , DB::quoteValue(paragraph(encoding(strip_tags(stripslashes($row_detail->comment_content))), true)) + , encoding($row_detail->comment_author) + , DB::quoteValue($url) + , $itemid + , $row_detail->comment_date + , DB::quoteValue($row_detail->comment_author_IP)); + if ( DB::execute($query) === FALSE ) + { + die($query); + } + } + } + echo "

"; + + // done + echo "

Done! Enjoy your stay in Nucleus

"; + die; } + +} ?>
diff --git a/nucleus/libs/PLUGIN.php b/nucleus/libs/PLUGIN.php index ef9a0bf..3fb00e2 100644 --- a/nucleus/libs/PLUGIN.php +++ b/nucleus/libs/PLUGIN.php @@ -136,7 +136,7 @@ abstract class NucleusPlugin * Name of the feature. See plugin documentation for more info * 'SqlTablePrefix' -> if the plugin uses the sql_table() method to get table names * 'HelpPage' -> if the plugin provides a helppage - * 'SqlApi' -> if the plugin uses the complete sql_* api (must also require nucleuscms 3.5) + * 'SqlApi' -> if the plugin uses the complete sql_* or DB::* api (must also require nucleuscms 3.5) */ public function supportsFeature($feature) { diff --git a/nucleus/libs/globalfunctions.php b/nucleus/libs/globalfunctions.php index 46cf5a6..201e0c5 100644 --- a/nucleus/libs/globalfunctions.php +++ b/nucleus/libs/globalfunctions.php @@ -196,9 +196,10 @@ if ( $MYSQL_HANDLER[0] == '' ) { $MYSQL_HANDLER[0] = 'mysql'; } +/* added for 4.0 DB::* wrapper and compatibility sql_* */ include_once($DIR_LIBS . 'sql/sql.php'); - /* end new for 3.5 sql_* wrapper */ + include($DIR_LIBS . 'MEMBER.php'); include($DIR_LIBS . 'ACTIONLOG.php'); include($DIR_LIBS . 'MANAGER.php'); diff --git a/nucleus/upgrades/upgrade.functions.php b/nucleus/upgrades/upgrade.functions.php index cc1e820..c8a67c0 100644 --- a/nucleus/upgrades/upgrade.functions.php +++ b/nucleus/upgrades/upgrade.functions.php @@ -21,7 +21,7 @@ */ /************************************************************* - * NOTE: With upgrade to 3.6, need to set this to use sql_* API + * NOTE: With upgrade to 4.0, need to set this to use DB::* API **************************************************************/ include('../../config.php'); @@ -147,8 +147,8 @@ break; } - $result = mysql_query($query); - $installed = ( $result != 0 ) && (mysql_num_rows($result) >= $minrows); + $result = DB::getResult($query); + $installed = ( $result !== FALSE ) && ($result->rowCount() >= $minrows); return $installed; } @@ -302,13 +302,14 @@ echo "
  • $friendly — "; # execute the query - $result = @mysql_query($query); + $result = @DB::execute($query); // begin if: error executing query if ( $result === FALSE ) { echo ' FAILED
    '; - echo 'Error: ', mysql_error(), ''; + $err = DB::getError(); + echo 'Error: ', $err[2], ''; $upgrade_failures++; } // else: query was successful @@ -364,19 +365,19 @@ $indices = array(); $query = 'SHOW INDEX FROM ' . sql_table($table); - $result = @mysql_query($query); + $result = @DB::getResult($query); // begin loop: each result object - while ( $object = mysql_fetch_object($result) ) + foreach ( $result as $row ) { // begin if: key has not been added to the indeces array yet - if ( !isset($indices[$object->Key_name]) ) + if ( !isset($indices[$row['Key_name']]) ) { - $indices[$object->Key_name] = array(); + $indices[$row['Key_name']] = array(); } // end if - array_push($indices[$object->Key_name], $object->Column_name); + array_push($indices[$row['Key_name']], $row['Column_name']); } // compare each index with parameter @@ -404,10 +405,10 @@ function upgrade_checkIfTableExists($table) { $query = 'SHOW TABLES LIKE ' . sql_table($table); - $result = @mysql_query($query); + $result = DB::getResult($query); // begin if: query executed successfully and one row was returned - if ( ($result !== FALSE) && (@mysql_num_rows($result) == 1) ) + if ( ($result !== FALSE) && ($result->rowCount() == 1) ) { return TRUE; } @@ -429,10 +430,10 @@ function upgrade_checkIfCVExists($value) { $query = 'SELECT name FROM ' . sql_table('config') . ' WHERE name = "' . $value . '"'; - $result = @mysql_query($query); + $result = DB::getResult($query); // begin if: query executed successfully and one row was returned - if ( ($result !== FALSE) && (@mysql_num_rows($result) == 1) ) + if ( ($result !== FALSE) && ($result->rowCount() == 1) ) { return TRUE; } @@ -455,10 +456,10 @@ function upgrade_checkIfColumnExists($table, $column) { $query = 'DESC ' . sql_table($table) . ' ' . $column; - $result = @mysql_query($query); + $result = DB::getResult($query); // begin if: query executed successfully and one row was returned - if ( ($result !== FALSE) && (@mysql_num_rows($result) == 1) ) + if ( ($result !== FALSE) && ($result->rowCount() == 1) ) { return TRUE; } diff --git a/nucleus/upgrades/upgrade1.0.php b/nucleus/upgrades/upgrade1.0.php index 27f103c..a8e96d0 100644 --- a/nucleus/upgrades/upgrade1.0.php +++ b/nucleus/upgrades/upgrade1.0.php @@ -51,11 +51,11 @@ function upgrade_do100() { if ($res) { // 5. for all members: hash their password and also copy it to mcookiekey $query = 'SELECT * FROM '.sql_table('member'); - $res = mysql_query($query); - while ($current = mysql_fetch_object($res)) { - $hashedpw = md5($current->mpassword); - $updquery = 'UPDATE '.sql_table('member')." SET mpassword='$hashedpw' WHERE mnumber=" . $current->mnumber; - upgrade_query("Encrypting password for member " . $current->mnumber,$updquery); + $res = DB::getResult($query); + foreach ( $res as $current ) { + $hashedpw = md5($current['mpassword']); + $updquery = 'UPDATE '.sql_table('member')." SET mpassword='$hashedpw' WHERE mnumber=" . $current['mnumber']; + upgrade_query("Encrypting password for member " . $current['mnumber'], $updquery); } } }else{ diff --git a/nucleus/upgrades/upgrade1.1.php b/nucleus/upgrades/upgrade1.1.php index 5a56f82..6403ab4 100644 --- a/nucleus/upgrades/upgrade1.1.php +++ b/nucleus/upgrades/upgrade1.1.php @@ -71,9 +71,9 @@ function upgrade_do110() { // 4. add 'general' categories for all blogs, and update nucleus_item $catid = 1; // generate catids ourself $query = 'SELECT bnumber FROM '.sql_table('blog'); - $res = mysql_query($query); - while ($current = mysql_fetch_object($res)) { - $blogid = $current->bnumber; + $res = DB::getResult($query); + foreach ( $res as $current ) { + $blogid = $current['bnumber']; $query = 'INSERT INTO '.sql_table('category')." (catid, cblog, cname, cdesc) VALUES ($catid, $blogid, 'General', 'Items that do not fit in other categories')"; $r = upgrade_query("Adding category 'general' for blog " . $blogid, $query); @@ -93,7 +93,7 @@ function upgrade_do110() { // 5. add template parts for category lists to all templates $query = 'SELECT tdnumber FROM '.sql_table('template_desc'); $res = DB::getResult($query); // get all template ids - foreach ( $res as $row) { + foreach ( $res as $row ) { $tid = $row['tdnumber']; // template id $query = 'INSERT INTO '.sql_table('template')." VALUES ($tid, 'CATLIST_HEADER', '
    • \">All
    • ');"; diff --git a/nucleus/upgrades/upgrade2.5.php b/nucleus/upgrades/upgrade2.5.php index dab5bb7..a602734 100644 --- a/nucleus/upgrades/upgrade2.5.php +++ b/nucleus/upgrades/upgrade2.5.php @@ -62,7 +62,7 @@ function upgrade_do250() { // store new id $aValues[] = array ( - 'id' => mysql_insert_id(), + 'id' => DB::getInsertId(), 'value' => $row['ovalue'] ); } diff --git a/nucleus/upgrades/upgrade3.3.php b/nucleus/upgrades/upgrade3.3.php index 0bc20f6..64fd207 100644 --- a/nucleus/upgrades/upgrade3.3.php +++ b/nucleus/upgrades/upgrade3.3.php @@ -35,7 +35,7 @@ function upgrade_do330() { } // check cmail column to separate to URL and cemail - mysql_query( + DB::execute( 'UPDATE ' . sql_table('comment') . ' ' . "SET cemail = cmail, cmail = '' " . "WHERE cmail LIKE '%@%'" @@ -61,8 +61,8 @@ function upgrade_do330() { // check to see if user turn on Weblogs.com ping, if so, suggest to install the plugin $query = "SELECT bsendping FROM " . sql_table('blog') . " WHERE bsendping='1'"; - $res = mysql_query($query); - if (mysql_num_rows($res) > 0) { + $res = DB::getResult($query); + if ($res->rowCount() > 0) { echo "
    • Note: The weblogs.com ping function is improved and moved into a plugin. To activate this function in v3.3, please go to plugin menu and install NP_Ping plugin. Also, NP_Ping is replacing NP_PingPong. If you have NP_PingPing installed, please also remove it.
    • "; } } -- 2.11.0