From 859dcdb360f409dbaf2e331c99752994ab6c7b62 Mon Sep 17 00:00:00 2001 From: Cameron Date: Sun, 10 Mar 2013 18:43:44 -0700 Subject: [PATCH] Forum upgrade improvements. Tested and appears to be functional. --- e107_handlers/sitelinks_class.php | 3 +- e107_plugins/forum/forum_setup.php | 8 +- e107_plugins/forum/forum_update.php | 262 +++++++++++++++------------- 3 files changed, 151 insertions(+), 122 deletions(-) diff --git a/e107_handlers/sitelinks_class.php b/e107_handlers/sitelinks_class.php index 4099a1d8f..0dfcfb68f 100644 --- a/e107_handlers/sitelinks_class.php +++ b/e107_handlers/sitelinks_class.php @@ -1091,7 +1091,8 @@ class e_navigation $rid = str_replace(array(' ', '_'), '-', $act).($id ? "-{$id}" : ''); - if (($active_page == $act && !is_numeric($act))|| (str_replace("?", "", e_PAGE.e_QUERY) == str_replace("?", "", $act))) + //XXX && !is_numeric($act) ??? + if (($active_page == $act)|| (str_replace("?", "", e_PAGE.e_QUERY) == str_replace("?", "", $act))) { $temp = $tmpl['button_active'.$kpost]; } diff --git a/e107_plugins/forum/forum_setup.php b/e107_plugins/forum/forum_setup.php index e3cc75af7..963175a39 100644 --- a/e107_plugins/forum/forum_setup.php +++ b/e107_plugins/forum/forum_setup.php @@ -49,7 +49,11 @@ class forum_setup */ function upgrade_required() { - return false; // true to trigger an upgrade alert, and false to not. + if(!e107::getDb()->field('forum','forum_thread')) + { + return true; // true to trigger an upgrade alert, and false to not. + } + } @@ -57,7 +61,7 @@ class forum_setup { //Redirect upgrade to customized upgrade routine - // e107::getRedirect()->redirect(e_PLUGIN.'forum/forum_update.php'); + e107::getRedirect()->redirect(e_PLUGIN.'forum/forum_update.php'); //header('Location: '.e_PLUGIN.'forum/forum_update.php'); } diff --git a/e107_plugins/forum/forum_update.php b/e107_plugins/forum/forum_update.php index 5386428d3..0eb2f4ee3 100644 --- a/e107_plugins/forum/forum_update.php +++ b/e107_plugins/forum/forum_update.php @@ -95,29 +95,32 @@ function step1() } $text .= "
-
- + +     - +
"; } else { - $text = "Attachment and attachment/thumb directories are writable -

-
- + $mes->addSuccess("Attachment and attachment/thumb directories are writable"); + + $text = " +
"; } - $e107->ns->tablerender('Attachment directory permissions', $text); + $e107->ns->tablerender('Step 1: Attachment directory permissions', $mes->render(). $text); } } function step2() { $e107 = e107::getInstance(); + $mes = e107::getMessage(); + $ns = e107::getRender(); + if(!isset($_POST['create_tables'])) { $text = " @@ -127,48 +130,47 @@ function step2() "; - $e107->ns->tablerender('Step 2: Forum table creation', $text); + $ns->tablerender('Step 2: Forum table creation', $text); return; } + // FIXME - use db_verify. ?? require_once(e_HANDLER.'db_table_admin_class.php'); $db = new db_table_admin; - $tabList = array('forum' => 'forum_new'); // , 'forum_thread' => '', 'forum_post' => '', 'forum_track' => '' + $tabList = array('forum' => 'forum_new' , 'forum_thread' => '', 'forum_post' => '', 'forum_track' => '' ); // $ret = ''; $failed = false; $text = ''; foreach($tabList as $name => $rename) { - $text .= 'Creating table '.($rename ? $rename : $name).' -> '; + $message = 'Creating table '.($rename ? $rename : $name); + $result = $db->createTable(e_PLUGIN.'forum/forum_sql.php', $name, true, $rename); if($result === true) { - $text .= 'Success
'; + $mes->addSuccess($message); + // $text .= 'Success
'; } elseif($result !== true) { - $text .= 'Failed
'; + // $text .= 'Failed
'; + $mes->addError($message); $failed = true; } } if($failed) { - $text .= " -

- Creation of table(s) failed. You can not continue until these are create successfully! - "; + $mes->addError("Creation of table(s) failed. You can not continue until these are created successfully!"); + } else { - $text .= " -

-
- -
- "; + $text = "
+ +
"; } - $e107->ns->tablerender('Step 2: Forum table creation', $text); + $ns->tablerender('Step 2: Forum table creation', $mes->render(). $text); } @@ -237,6 +239,9 @@ function step4() { global $pref; $e107 = e107::getInstance(); + $mes = e107::getMessage(); + $ns = e107::getRender(); + $stepCaption = 'Step 4: Move user specific forum data and forum prefs'; if(!isset($_POST['move_user_data'])) { @@ -250,7 +255,7 @@ function step4() "; - $e107->ns->tablerender($stepCaption, $text); + $ns->tablerender($stepCaption, $text); return; } @@ -272,8 +277,9 @@ function step4() 'reported_post_email', 'email_notify', 'email_notify_on' ); - foreach($forumPrefList as $_fp) { - echo "converting $_fp to $_fp
"; + foreach($forumPrefList as $_fp) + { + $mes->addDebug( "converting $_fp to $_fp" ); $old_prefs[$_fp] = $coreConfig->get($_fp); $coreConfig->remove($_fp); } @@ -287,12 +293,12 @@ function step4() 'trackcount' => 0 ); $db = new db; - if($db->db_Select('user', 'user_id, user_viewed, user_realm',"user_viewed != '' OR user_realm != ''")) + if($db->select('user', 'user_id, user_viewed, user_realm',"user_viewed != '' OR user_realm != ''")) { require_once(e_HANDLER.'user_extended_class.php'); $ue = new e107_user_extended; - while($row = $db->db_Fetch(MYSQL_ASSOC)) + while($row = $db->fetch(MYSQL_ASSOC)) { $result['usercount']++; $userId = (int)$row['user_id']; @@ -340,44 +346,50 @@ function step4() } } - $text .= " - User data move results:
- Number of users processed: {$result['usercount']}
- Number of viewed data processed: {$result['viewcount']}
- Number of tracked records added: {$result['trackcount']}
-

-
+ $mes->addSuccess( "User data move results: + + "); + + $text = " -
- "; + "; - $e107->ns->tablerender($stepCaption, $text); + $ns->tablerender($stepCaption, $mes->render().$text); } function step5() { $e107 = e107::getInstance(); + + $sql = e107::getDb(); + $ns = e107::getRender(); + $mes = e107::getMessage(); + $stepCaption = 'Step 5: Migrate forum data'; if(!isset($_POST['move_forum_data'])) { - $text = " - This step will copy all of your forum configuration from the `forum` table into the `forum_new` table.

+ $mes->addInfo("This step will copy all of your forum configuration from the `forum` table into the `forum_new` table.
Once the information is successfully copied, the existing 1.0 forum table will be renamed `forum_old` and the newly created `forum_new` table will be renamed `forum`.
-

+ "); + $text = "
"; - $e107->ns->tablerender($stepCaption, $text); + $ns->tablerender($stepCaption, $mes->render().$text); return; } - $counts = array('parens' => 0, 'forums' => 0, 'subs' => 0); + $counts = array('parens' => 0, 'forums' => 0, 'subs' => 0); //XXX Typo on 'parents' ? - if($e107->sql->db_Select('forum')) + if($sql->select('forum')) { - $forumList = $e107->sql->db_getList(); + $forumList = $sql->db_getList(); foreach($forumList as $forum) { if($forum['forum_parent'] == 0) @@ -397,33 +409,32 @@ function step5() $tmp['forum_threadclass'] = $tmp['forum_postclass']; $tmp['forum_options'] = '_NULL_'; // $tmp['_FIELD_TYPES'] = $ftypes['_FIELD_TYPES']; - $e107->sql->db_Insert('forum_new', $tmp); + $sql->insert('forum_new', $tmp); } + $mes->addInfo ( " + Forum data move results: + + "); + + $result = $sql->gen('RENAME TABLE `#forum` TO `#forum_old` ') ? e_MESSAGE_SUCCESS : E_MESSAGE_ERROR; + $mes->add("Renaming forum to forum_old",$result); + + $result = $sql->gen('RENAME TABLE `#forum_new` TO `#forum` ') ? e_MESSAGE_SUCCESS : E_MESSAGE_ERROR; + $mes->add("Renaming forum_new to forum",$result); + + $text = " - Forum data move results:
- Number of forum parents processed: {$counts['parents']}
- Number of forums processed: {$counts['forums']}
- Number of sub forums processed: {$counts['subs']}
-

- "; - - $result = $e107->sql->db_Select_gen('RENAME TABLE `#forum` TO `#forum_old` '); - $text .= "Rename forum to forum_old -> ".($result ? 'Passed' : 'Failed!'); - $text .= '
'; - - $result = $e107->sql->db_Select_gen('RENAME TABLE `#forum_new` TO `#forum` '); - $text .= "Rename forum_new to forum -> ".($result ? 'Passed' : 'Failed!'); - $text .= '
'; - - $text .= " -

-
+
"; - $e107->ns->tablerender($stepCaption, $text); + $ns->tablerender($stepCaption, $mes->render(). $text); } } @@ -432,6 +443,10 @@ function step6() { global $f; $e107 = e107::getInstance(); + $ns = e107::getRender(); + $mes = e107::getMessage(); + $sql = e107::getDb(); + $stepCaption = 'Step 6: Thread and post data'; $threadLimit = varset($_POST['threadLimit'], 1000); $lastThread = varset($f->updateInfo['lastThread'], 0); @@ -439,7 +454,7 @@ function step6() if(!isset($_POST['move_thread_data'])) { - $count = $e107->sql->db_Count('forum_t', '(*)', "WHERE thread_parent = 0 AND thread_id > {$lastThread}"); + $count = $sql->count('forum_t', '(*)', "WHERE thread_parent = 0 AND thread_id > {$lastThread}"); $limitDropdown = createThreadLimitDropdown($count); $text = "
@@ -456,11 +471,11 @@ function step6()
"; - $e107->ns->tablerender($stepCaption, $text); + $ns->tablerender($stepCaption, $mes->render(). $text); return; } - $count = $e107->sql->db_Count('forum_t', '(*)', "WHERE thread_parent=0 AND thread_id>{$lastThread}"); + $count = $sql->count('forum_t', '(*)', "WHERE thread_parent=0 AND thread_id>{$lastThread}"); if($count === false) { echo "error: Unable to determine last thread id"; @@ -475,10 +490,10 @@ function step6() ORDER BY thread_id ASC LIMIT 0, {$threadLimit} "; - if($e107->sql->db_Select_gen($qry)) + if($sql->gen($qry)) { $postCount = 0; - $threadList = $e107->sql->db_getList(); + $threadList = $sql->db_getList(); $text = ''; foreach($threadList as $t) { @@ -500,7 +515,7 @@ function step6() $text .= "Last thread id = {$t['thread_id']}
"; - $count = $e107->sql->db_Count('forum_t', '(*)', "WHERE thread_parent = 0 AND thread_id > {$f->updateInfo['lastThread']}"); + $count = $sql->count('forum_t', '(*)', "WHERE thread_parent = 0 AND thread_id > {$f->updateInfo['lastThread']}"); if($count) { $limitDropdown = createThreadLimitDropdown($count); @@ -508,10 +523,10 @@ function step6()
We still have {$count} threads remaining to convert, do them in steps of {$limitDropdown}

- +
"; - $e107->ns->tablerender($stepCaption, $text); + $ns->tablerender($stepCaption, $mes->render(). $text); } else { @@ -524,14 +539,12 @@ function step6() } if($done) { - $text .= " - Thread migration is complete!! -

-
+ $mes->addSuccess("Thread migration is complete!!"); + $text = " -
- "; - $e107->ns->tablerender($stepCaption, $text); + "; + + $ns->tablerender($stepCaption, $mes->render(). $text); } } @@ -571,7 +584,7 @@ function step7() $text .= " Successfully recalculated forum posts for ".count($counts)." users.

-
+
"; @@ -606,7 +619,7 @@ function step8() $text .= " Successfully recalculated lastpost information for all forums and threads.

-
+
"; @@ -671,7 +684,7 @@ function step9() $text .= " Successfully migrated forum poll information for ".count($threadList)." thread poll(s).

-
+
"; @@ -681,6 +694,9 @@ function step9() function step10() { $e107 = e107::getInstance(); + $sql = e107::getDb(); + $ns = e107::getRender(); + global $f; $stepCaption = 'Step 10: Migrate forum attachments'; @@ -695,7 +711,7 @@ function step10() "; - $e107->ns->tablerender($stepCaption, $text); + $ns->tablerender($stepCaption, $text); return; } @@ -703,15 +719,18 @@ function step10() SELECT post_id, post_entry FROM `#forum_post` WHERE post_entry REGEXP '_[[:digit:]]+_FT' "; - if($e107->sql->db_Select_gen($qry, true)) + + if($sql->gen($qry)) { - while($row = $e107->sql->db_Fetch(MYSQL_ASSOC)) + while($row = $sql->fetch(MYSQL_ASSOC)) { $postList[] = $row; } $i = 0; $pcount = 0; $f->log("Found ".count($postList). " posts with attachments"); + + //XXX Run post through $tp->toHtml() and then use $tp->getTag() to find images or files.? foreach($postList as $post) { // echo htmlentities($post['post_entry'])."
"; @@ -876,7 +895,7 @@ function step10() $info['WHERE'] = 'post_id = '.$post['post_id']; $info['post_attachments'] = implode(',', $newValues); // print_a($info); - $e107->sql->db_Update('forum_post', $info); + $sql->db_Update('forum_post', $info); } // echo $post['thread_thread']."
"; // print_a($newValues); @@ -895,7 +914,7 @@ function step10() $text .= " Successfully migrated forum attachment information for ".count($postList)." post(s).

-
+
"; @@ -956,7 +975,7 @@ function step11() Successfully removed {$success} orphaned files
{$failText}

-
+
"; @@ -992,7 +1011,7 @@ function step11() $text .= " There were no orphaned files found


-
+
"; @@ -1003,9 +1022,14 @@ function step11() function step12() { - $e107 = e107::getInstance(); - $f = new forumUpgrade; + $sql = e107::getDb(); + $ns = e107::getRender(); + $mes = e107::getMessage(); + + $f = new forumUpgrade; + $stepCaption = 'Step 12: Delete old forum data'; + if(!isset($_POST['delete_old'])) { $text = " @@ -1018,7 +1042,7 @@ function step12() "; - $e107->ns->tablerender($stepCaption, $text); + $ns->tablerender($stepCaption, $text); return; } @@ -1027,21 +1051,24 @@ function step12() "DROP TABLE `#forum_t", "DELETE * FROM `#generic` WHERE gen_type = 'forumUpgrade'" ); + foreach($qryArray as $qry) { - $e107->sql->db_Select_gen($qry, true); + $sql->gen($qry); } + $ret = $f->setNewVersion(); - $text = " - Congratulations, the forum upgrade is now completed!

- {$ret} -

- "; - $e107->ns->tablerender($stepCaption, $text); + $mes->addSuccess("Congratulations, the forum upgrade is now completed!

{$ret}"); + $ns->tablerender($stepCaption,$mes->render(). $text); return; } + + + + + class forumUpgrade { var $newVersion = '2.0'; @@ -1069,9 +1096,10 @@ class forumUpgrade public function checkUpdateNeeded() { - include_once(e_PLUGIN.'forum/forum_update_check.php'); - $needed = update_forum_08('check'); - return !$needed; + return true; + // include_once(e_PLUGIN.'forum/forum_update_check.php'); + // $needed = update_forum_08('check'); + // return !$needed; } function checkAttachmentDirs() @@ -1126,9 +1154,11 @@ class forumUpgrade function setNewVersion() { - global $pref; + $pref = e107::getPref(); $e107 = e107::getInstance(); - $e107->sql->db_Update('plugin',"plugin_version = '{$this->newVersion}' WHERE plugin_name='Forum'", true); + $sql = e107::getDb(); + + $sql->update('plugin',"plugin_version = '{$this->newVersion}' WHERE plugin_name='Forum'"); $pref['plug_installed']['forum'] = $this->newVersion; save_prefs(); return "Forum Version updated to version: {$this->newVersion}
"; @@ -1373,7 +1403,7 @@ class forumUpgrade function createThreadLimitDropdown($count) { $ret = " - "; $last = min($count, 10000); if($count < 2000) { @@ -1396,11 +1426,11 @@ function createThreadLimitDropdown($count) function forum_update_adminmenu() -{ - global $currentStep; +{ + $action = 1; $var[1]['text'] = '1 - Permissions'; - $var[1]['link'] = '#'; + $var[1]['link'] = e_SELF; $var[2]['text'] = '2 - Create new tables'; $var[2]['link'] = '#'; @@ -1435,17 +1465,11 @@ function forum_update_adminmenu() $var[12]['text'] = '12 - Delete old forum data'; $var[12]['link'] = '#'; - - for($i=1; $i < $currentStep; $i++) - { - $var[$i]['text'] = "{$var[$i]['text']}"; - } - if(isset($_POST['nextStep'])) + if(isset($_GET['step'])) { - $tmp = array_keys($_POST['nextStep']); - $action = $tmp[0]; - + // $action = key($_POST['nextStep']); + $action = intval($_GET['step']); } show_admin_menu('Forum Upgrade', $action, $var);