1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 20:58:30 +01:00

Forum upgrade improvements. Tested and appears to be functional.

This commit is contained in:
Cameron 2013-03-10 18:43:44 -07:00
parent 6f8481e528
commit 859dcdb360
3 changed files with 151 additions and 122 deletions

View File

@ -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];
}

View File

@ -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');
}

View File

@ -95,29 +95,32 @@ function step1()
}
$text .= "
<br />
<form method='post'>
<input class='button' type='submit' name='retest_attach' value='Retest Permissions' />
<form method='post' action='".e_SELF."?step=2'>
<input class='btn' type='submit' name='retest_attach' value='Retest Permissions' />
&nbsp;&nbsp;&nbsp;
<input class='button' type='submit' name='skip_attach' value='Skip - I understand the risks' />
<input class='btn btn-success' type='submit' name='skip_attach' value='Skip - I understand the risks' />
</form>
";
}
else
{
$text = "Attachment and attachment/thumb directories are writable
<br /><br />
<form method='post'>
<input class='button' type='submit' name='nextStep[2]' value='Proceed to step 2' />
$mes->addSuccess("Attachment and attachment/thumb directories are writable");
$text = "<form method='post' action='".e_SELF."?step=2'>
<input class='btn btn-success' type='submit' name='nextStep[2]' value='Proceed to step 2' />
</form>
";
}
$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()
<input class='button' type='submit' name='create_tables' value='Proceed with table creation' />
</form>
";
$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 <br />';
$mes->addSuccess($message);
// $text .= 'Success <br />';
}
elseif($result !== true)
{
$text .= 'Failed <br />';
// $text .= 'Failed <br />';
$mes->addError($message);
$failed = true;
}
}
if($failed)
{
$text .= "
<br /><br />
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 .= "
<br /><br />
<form method='post'>
<input class='button' type='submit' name='nextStep[4]' value='Proceed to step 3' />
</form>
";
$text = "<form method='post' action='".e_SELF."?step=4'>
<input class='btn button' type='submit' name='nextStep[4]' value='Proceed to step 3' />
</form>";
}
$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()
<input class='button' type='submit' name='move_user_data' value='Proceed with user data move' />
</form>
";
$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<br />";
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:<br />
Number of users processed: {$result['usercount']} <br />
Number of viewed data processed: {$result['viewcount']} <br />
Number of tracked records added: {$result['trackcount']} <br />
<br /><br />
<form method='post'>
$mes->addSuccess( "User data move results:
<ul>
<li>Number of users processed: {$result['usercount']} </li>
<li>Number of viewed data processed: {$result['viewcount']} </li>
<li>Number of tracked records added: {$result['trackcount']} </li>
</ul>
");
$text = "<form method='post' action='".e_SELF."?step=5'>
<input class='button' type='submit' name='nextStep[5]' value='Proceed to step 5' />
</form>
";
</form>";
$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.<br /><br />
$mes->addInfo("This step will copy all of your forum configuration from the `forum` table into the `forum_new` table.<br />
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`.<br />
<br /><br />
");
$text = "
<form method='post'>
<input class='button' type='submit' name='move_forum_data' value='Proceed with forum data move' />
</form>
";
$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:
<ul>
<li>Number of forum parents processed: {$counts['parents']} </li>
<li>Number of forums processed: {$counts['forums']} </li>
<li>Number of sub forums processed: {$counts['subs']} </li>
</ul>
");
$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:<br />
Number of forum parents processed: {$counts['parents']} <br />
Number of forums processed: {$counts['forums']} <br />
Number of sub forums processed: {$counts['subs']} <br />
<br /><br />
";
$result = $e107->sql->db_Select_gen('RENAME TABLE `#forum` TO `#forum_old` ');
$text .= "Rename forum to forum_old -> ".($result ? 'Passed' : 'Failed!');
$text .= '<br />';
$result = $e107->sql->db_Select_gen('RENAME TABLE `#forum_new` TO `#forum` ');
$text .= "Rename forum_new to forum -> ".($result ? 'Passed' : 'Failed!');
$text .= '<br />';
$text .= "
<br /><br />
<form method='post'>
<form method='post' action='".e_SELF."?step=6'>
<input class='button' type='submit' name='nextStep[6]' value='Proceed to step 6' />
</form>
";
$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 = "
<form method='post'>
@ -456,11 +471,11 @@ function step6()
<input class='button' type='submit' name='move_thread_data' value='Begin thread data move' />
</form>
";
$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']}<br />";
$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()
<form method='post'>
We still have {$count} threads remaining to convert, do them in steps of {$limitDropdown}
<br /><br />
<input class='button' type='submit' name='move_thread_data' value='Continue thread data move' />
<input class='btn btn-success' type='submit' name='move_thread_data' value='Continue thread data move' />
</form>
";
$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!!
<br /><br />
<form method='post'>
$mes->addSuccess("Thread migration is complete!!");
$text = "<form method='post' action='".e_SELF."?step=7'>
<input class='button' type='submit' name='nextStep[7]' value='Proceed to step 7' />
</form>
";
$e107->ns->tablerender($stepCaption, $text);
</form>";
$ns->tablerender($stepCaption, $mes->render(). $text);
}
}
@ -571,7 +584,7 @@ function step7()
$text .= "
Successfully recalculated forum posts for ".count($counts)." users.
<br /><br />
<form method='post'>
<form method='post' action='".e_SELF."?step=8'>
<input class='button' type='submit' name='nextStep[8]' value='Proceed to step 8' />
</form>
";
@ -606,7 +619,7 @@ function step8()
$text .= "
Successfully recalculated lastpost information for all forums and threads.
<br /><br />
<form method='post'>
<form method='post' action='".e_SELF."?step=9'>
<input class='button' type='submit' name='nextStep[9]' value='Proceed to step 9' />
</form>
";
@ -671,7 +684,7 @@ function step9()
$text .= "
Successfully migrated forum poll information for ".count($threadList)." thread poll(s).
<br /><br />
<form method='post'>
<form method='post' action='".e_SELF."?step=10'>
<input class='button' type='submit' name='nextStep[10]' value='Proceed to step 10' />
</form>
";
@ -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()
<input class='button' type='submit' name='migrate_attachments' value='Proceed with attachment migration' />
</form>
";
$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'])."<br />";
@ -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']."<br />";
// print_a($newValues);
@ -895,7 +914,7 @@ function step10()
$text .= "
Successfully migrated forum attachment information for ".count($postList)." post(s).
<br /><br />
<form method='post'>
<form method='post' action='".e_SELF."?step=11'>
<input class='button' type='submit' name='nextStep[11]' value='Proceed to step 11' />
</form>
";
@ -956,7 +975,7 @@ function step11()
Successfully removed {$success} orphaned files <br />
{$failText}
<br /><br />
<form method='post'>
<form method='post' action='".e_SELF."?step=12'>
<input class='button' type='submit' name='nextStep[12]' value='Proceed to step 12' />
</form>
";
@ -992,7 +1011,7 @@ function step11()
$text .= "
There were no orphaned files found <br />
<br /><br />
<form method='post'>
<form method='post' action='".e_SELF."?step=12'>
<input class='button' type='submit' name='nextStep[12]' value='Proceed to step 12' />
</form>
";
@ -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()
<input class='button' type='submit' name='delete_old' value='Remove old forum tables' />
</form>
";
$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!<br /><br />
{$ret}
<br /><br />
";
$e107->ns->tablerender($stepCaption, $text);
$mes->addSuccess("Congratulations, the forum upgrade is now completed!<br /><br />{$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} <br />";
@ -1373,7 +1403,7 @@ class forumUpgrade
function createThreadLimitDropdown($count)
{
$ret = "
<select name='threadLimit'>
<select class='tbox' name='threadLimit'>
";
$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'] = "<span style='color:green;'>{$var[$i]['text']}</span>";
}
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);