updateInfo['currentStep'] = intval($_GET['reset']);
$f -> setUpdateInfo();
}
if (e_AJAX_REQUEST)
{
if (!vartrue($_GET['mode']))
{
echo "data-progress-mode not set!";
exit ;
}
$func = 'step' . intval($_GET['mode']) . "_ajax";
if (function_exists($func))
{
call_user_func($func);
}
else
{
echo $func . "() doesn't exist!";
}
exit ;
}
$upgradeNeeded = $f -> checkUpdateNeeded();
$upgradeNeeded = true;
if (!$upgradeNeeded)
{
$mes = e107::getMessage();
$mes -> addInfo("The forum is already at the most recent version, no upgrade is required");
$ns -> tablerender('Forum Upgrade', $mes -> render());
require (e_ADMIN . 'footer.php');
exit ;
}
if (isset($_POST) && count($_POST))
{
if (isset($_POST['skip_attach']))
{
$f -> updateInfo['skip_attach'] = 1;
$f -> updateInfo['currentStep'] = 2;
$f -> setUpdateInfo();
}
if (isset($_POST['nextStep']))
{
$tmp = array_keys($_POST['nextStep']);
$f -> updateInfo['currentStep'] = $tmp[0];
$f -> setUpdateInfo();
}
}
$currentStep = (isset($f -> updateInfo['currentStep']) ? $f -> updateInfo['currentStep'] : 1);
$stepParms = (isset($stepParms) ? $stepParms : '');
//echo "currentStep = $currentStep ";
if (function_exists('step' . $currentStep))
{
$result = call_user_func('step' . $currentStep, $stepParms);
}
require (e_ADMIN . 'footer.php');
exit ;
function step1()
{
global $f;
$f -> updateInfo['currentStep'] = 1;
$f -> setUpdateInfo();
$mes = e107::getMessage();
//Check attachment dir permissions
if (!isset($f -> updateInfo['skip_attach']))
{
$f -> checkAttachmentDirs();
if (isset($f -> error['attach']))
{
$text = "
ERROR:
The following errors have occured. These issues must be resolved if you ever want to enable attachment or image uploading in your forums. If you do not ever plan on enabling this setting in your forum, you may click the 'skip' button
";
foreach ($f->error['attach'] as $e)
{
$text .= '** ' . $e . ' ';
}
$text .= "
";
}
else
{
$mes -> addSuccess("Attachment and attachment/thumb directories are writable");
$text = "
";
}
e107::getRender() -> tablerender('Step 1: Attachment directory permissions', $mes -> render() . $text);
}
}
function step2()
{
$mes = e107::getMessage();
$ns = e107::getRender();
if (!isset($_POST['create_tables']))
{
$text = "
This step will create the new forum_thread, forum_post, and forum_attach tables. It will also create a forum_new table that will become the 'real' forum table once the data from the current table is migrated.
";
$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' => ''
);
//
$ret = '';
$failed = false;
$text = '';
$sql = e107::getDb();
foreach ($tabList as $name => $rename)
{
$message = 'Creating table ' . ($rename ? $rename : $name);
$curTable = ($rename ? $rename : $name);
if($sql->isTable($curTable) && $sql->isEmpty($curTable))
{
$mes -> addSuccess("Skipping table ".$name." (already exists)");
continue;
}
$result = $db->createTable(e_PLUGIN . 'forum/forum_sql.php', $name, true, $rename);
if ($result === true)
{
$mes -> addSuccess($message);
// $text .= 'Success ';
}
elseif ($result !== true)
{
// $text .= 'Failed ';
$mes -> addError($message);
$failed = true;
}
}
if ($failed)
{
$mes -> addError("Creation of table(s) failed. You can not continue until these are created successfully!");
}
else
{
$text = "";
}
$ns -> tablerender('Step 2: Forum table creation', $mes -> render() . $text);
}
// FIXME - use e107::getPlugin()->manage_extended_field('add', $name, $attrib, $source)
function step3()
{
$ns = e107::getRender();
$mes = e107::getMessage();
$text = '';
$stepCaption = 'Step 3: Extended user field creation';
if (!isset($_POST['create_extended']))
{
$text = "
This step will create the new extended user fields required for the new forum code:
user_plugin_forum_posts (to track number of posts for each user)
user_plugin_forum_viewed (to track threads viewed by each user
";
$ns -> tablerender($stepCaption, $text);
return;
}
$fieldList = array(
'plugin_forum_posts' => 'integer',
'plugin_forum_viewed' => 'radio'
);
$failed = false;
$ext = e107::getUserExt();
foreach ($fieldList as $fieldName => $fieldType)
{
$result = $ext->user_extended_add_system($fieldName, $fieldType);
if ($result === true)
{
$mes -> addSuccess('Creating extended user field user_' . $fieldName);
}
else
{
$mes -> addError('Creating extended user field user_' . $fieldName);
$mes->addDebug(print_a($result,true));
$failed = true;
}
}
if ($failed)
{
$mes -> addError("Creation of extended field(s) failed. You can not continue until these are create successfully!");
}
else
{
$text = "
";
}
$ns -> tablerender($stepCaption, $mes -> render() . $text);
}
function step4()
{
global $pref;
$mes = e107::getMessage();
$ns = e107::getRender();
$stepCaption = 'Step 4: Move user specific forum data and forum prefs';
if (!isset($_POST['move_user_data']))
{
$text = "
This step will move the main forum preferences into its own table row. It will also move all user_viewed data from user table into the user extended table.
The user_forum field data will not be moved, as it will be recalculated later.
Depending on the size of your user table, this step could take a while.
Number of viewed data processed: {$result['viewcount']}
Number of tracked records added: {$result['trackcount']}
");
$text = "";
$ns -> tablerender($stepCaption, $mes -> render() . $text);
}
function step5()
{
$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.
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`.
Number of forum parents processed: {$counts['parents']}
Number of forums processed: {$counts['forums']}
Number of sub forums processed: {$counts['subs']}
");
$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 = "
";
$ns -> tablerender($stepCaption, $mes -> render() . $text);
}
function step6()
{
$sql = e107::getDb();
$ns = e107::getRender();
$mes = e107::getMessage();
$stepCaption = 'Step 6: Thread and post data';
$_SESSION['forumupdate']['thread_total'] = $sql -> count('forum_t', '(*)', "WHERE thread_parent = 0");
$_SESSION['forumupdate']['thread_count'] = 0;
$_SESSION['forumupdate']['thread_last'] = 0;
$text = "This step will copy all of your existing forum threads and posts into the new `forum_thread` and `forum_post` tables.
Depending on your forum size and speed of server, this could take some time.
";
$text .= renderProgress("Begin thread data move", 6);
$ns->tablerender($stepCaption, $mes -> render() . $text);
}
function renderProgress($caption, $step)
{
if(!$step)
{
return "No step entered in function";
}
$thisStep = 'step'.$step;
$nextStep = 'step'.($step + 1);
$text = '
";
$ns -> tablerender($stepCaption, $text);
}
function step8()
{
$sql = e107::getDb();
$mes = e107::getMessage();
$stepCaption = 'Step 8: Calculate last post information';
$_SESSION['forumupdate']['lastpost_total'] = $sql -> count('forum', '(*)', "WHERE forum_parent != 0");
$_SESSION['forumupdate']['lastpost_count'] = 0;
$_SESSION['forumupdate']['lastpost_last'] = 0;
$mes->addDebug("Total LastPost: ".$_SESSION['forumupdate']['lastpost_total']);
$text = "
This step will recalculate all thread and forum lastpost information";
$text .= renderProgress('Proceed with lastpost calculation',8);
e107::getRender() -> tablerender($stepCaption, $mes->render(). $text);
return;
}
function step8_ajax()
{
$sql = e107::getDb();
$lastThread = vartrue($_SESSION['forumupdate']['lastpost_last'], 0);
global $forum;
$parentList = [];
if ($sql->select('forum', 'forum_id', 'forum_parent != 0 AND forum_id > '.$lastThread.' ORDER BY forum_id LIMIT 2'))
{
while ($row = $sql->fetch())
{
$parentList[] = $row['forum_id'];
}
foreach($parentList as $id)
{
set_time_limit(60);
$forum->forumUpdateLastpost('forum', $id);
$_SESSION['forumupdate']['lastpost_last'] = $id;
$_SESSION['forumupdate']['lastpost_count']++;
}
}
else
{
echo 100;
exit;
}
echo round(($_SESSION['forumupdate']['lastpost_count'] / $_SESSION['forumupdate']['lastpost_total']) * 100);
}
function step9()
{
$sql = e107::getDb();
$text = '';
$stepCaption = 'Step 9: Migrate poll information';
if (!isset($_POST['migrate_polls']))
{
$text = "
This step will recalculate all poll information that has been entered in the forums.
";
e107::getRender() -> tablerender($stepCaption, $text);
return;
}
$qry = "
SELECT t.thread_id, p.poll_id FROM `#polls` AS p
LEFT JOIN `#forum_thread` AS t ON t.thread_id = p.poll_datestamp
WHERE t.thread_id IS NOT NULL
";
$threadList = [];
if ($sql -> gen($qry))
{
while ($row = $sql -> fetch())
{
$threadList[] = $row['thread_id'];
}
foreach ($threadList as $threadId)
{
if ($sql -> select('forum_thread', 'thread_options', 'thread_id = ' . $threadId, 'default'))
{
$row = $sql -> fetch();
if ($row['thread_options'])
{
$opts = unserialize($row['thread_options']);
$opts['poll'] = 1;
}
else
{
$opts = array('poll' => 1);
}
$tmp = array();
$tmp['thread_options'] = serialize($opts);
$tmp['WHERE'] = 'thread_id = ' . $threadId;
// $tmp['_FIELD_TYPES']['thread_options'] = 'escape';
$sql -> update('forum_thread', $tmp);
}
}
}
else
{
$text = 'No threads found! ';
}
$text .= "
Successfully migrated forum poll information for " . count($threadList) . " thread poll(s).
";
e107::getRender() -> tablerender($stepCaption, $text);
}
function step10()
{
$sql = e107::getDb();
$ns = e107::getRender();
$mes = e107::getMessage();
global $f;
$stepCaption = 'Step 10: Migrate forum attachments';
$_SESSION['forumupdate']['attachment_total'] = $sql -> count('forum_post', '(*)', "WHERE post_entry LIKE '%public/%' ");
$_SESSION['forumupdate']['attachment_count'] = 0;
$_SESSION['forumupdate']['attachment_last'] = 0;
if ($_SESSION['forumupdate']['attachment_total'] == 0)
{
$text = "
No forum attachments found.
";
$ns -> tablerender($stepCaption, $text);
return;
}
$text = "
This step will migrate the forum attachment information that was found in " . $_SESSION['forumupdate']['attachment_total'] . " posts.
All files will be moved from the e107_files/public directory into the " . e_MEDIA . "plugins/forum/ directory and related posts will be updated accordingly.
";
$text .= renderProgress("Begin attachment migration",10);
file_put_contents(e_LOG."forum_upgrade_attachments.log",''); // clear the log.
$ns -> tablerender($stepCaption, $mes -> render() . $text);
}
/**
* Attachments
*/
function step10_ajax()//TODO
{
$sql = e107::getDb();
global $f;
$lastPost = vartrue($_SESSION['forumupdate']['attachment_last'], 0);
$errorText = '';
/*
$qry = "
SELECT post_id, post_thread, post_entry, post_user FROM `#forum_post`
WHERE post_entry REGEXP '_[[:digit:]]'
AND post_id > {$lastPost} ORDER BY post_id LIMIT 50
";
*/
$qry = "
SELECT post_id, post_thread, post_entry, post_user FROM `#forum_post`
WHERE post_id > {$lastPost} AND post_entry LIKE '%public/%'
ORDER BY post_id LIMIT 50
";
// file_put_contents(e_LOG."forum_update_step10.log",$qry."\n",FILE_APPEND);
$postList = [];
if ($sql->gen($qry))
{
while ($row = $sql->fetch())
{
$postList[] = $row;
}
$i = 0;
$pcount = 0;
$f -> log("Found " . count($postList) . " posts with attachments");
foreach ($postList as $post)
{
// echo htmlentities($post['post_entry'])." ";
$_SESSION['forumupdate']['attachment_last'] = $post['post_id'];
$_SESSION['forumupdate']['attachment_count']++;
$i++;
// if($pcount++ > 10) { die('here 10'); }
$attachments = array();
$foundFiles = array();
// echo $post['post_entry']."
";
$ns -> tablerender($stepCaption, $text);
return;
}
else
{
$text .= "
There were no orphaned files found
";
$ns -> tablerender($stepCaption, $text);
return;
}
}
function step12()
{
$sql = e107::getDb();
$ns = e107::getRender();
$mes = e107::getMessage();
$f = new forumUpgrade;
$stepCaption = 'Step 12: Delete old forum data';
if (!isset($_POST['delete_old']) && !isset($_POST['skip_delete_old']))
{
$text = "
The forum upgrade should now be complete. During the upgrade process the old forum tables were
retained. You may choose to keep these tables as a backup or delete them.
We will also be marking the forum upgrade as completed!
";
$ns -> tablerender($stepCaption, $text);
return;
}
if (vartrue($_POST['delete_old']))
{
$qryArray = array(
"DROP TABLE `#forum_old`",
"DROP TABLE `#forum_t`",
);
foreach ($qryArray as $qry)
{
$sql -> gen($qry);
}
}
unset($_SESSION['forumUpgrade']);
$ret = $f -> setNewVersion();
$mes -> addSuccess("Congratulations, the forum upgrade is now completed!