window.location='".e_PLUGIN."forum/forum_update.php'
";
exit;
}
$eplug_admin = true;
require_once('../../class2.php');
if (!getperms('P'))
{
header('location:'.e_BASE.'index.php');
exit;
}
error_reporting(E_ALL);
require_once(e_PLUGIN.'forum/forum_class.php');
require_once(e_ADMIN.'auth.php');
$forum = new e107forum;
$timestart = microtime();
$f = new forumUpgrade;
$e107 = e107::getInstance();
$upgradeNeeded = $f->checkUpdateNeeded();
if(!$upgradeNeeded)
{
$text = "The forum is already at the most recent version, no upgrade is required";
$ns->tablerender('Forum Upgrade', $text);
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;
$e107 = e107::getInstance();
//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
{
$text = "Attachment and attachment/thumb directories are writable
";
}
$e107->ns->tablerender('Attachment directory permissions', $text);
}
}
function step2()
{
$e107 = e107::getInstance();
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.
Creation of table(s) failed. You can not continue until these are create successfully!
";
}
else
{
$text .= "
";
}
$e107->ns->tablerender('Step 2: Forum table creation', $text);
}
function step3()
{
$e107 = e107::getInstance();
$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
Creation of extended field(s) failed. You can not continue until these are create successfully!
';
}
else
{
$text .= "
";
}
$e107->ns->tablerender($stepCaption, $text);
}
function step4()
{
global $pref;
$e107 = e107::getInstance();
$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.
";
if($viewed != '')
{
$ue->user_extended_setvalue($userId, 'plugin_forum_viewed', mysql_real_escape_string($viewed));
$result['viewcount']++;
}
if(is_array($trackList) && count($trackList))
{
foreach($trackList as $threadId)
{
$result['trackcount']++;
$threadId = (int)$threadId;
if($threadId > 0)
{
$tmp = array();
$tmp['track_userid'] = $userId;
$tmp['track_thread'] = $threadId;
$e107->sql->db_Insert('forum_track', $tmp);
}
}
}
}
}
$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']}
";
$e107->ns->tablerender($stepCaption, $text);
}
function step5()
{
$e107 = e107::getInstance();
$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 0.7 forum table will be renamed `forum_old` and the newly created `forum_new` table will be renamed `forum`.
";
$e107->ns->tablerender($stepCaption, $text);
return;
}
$counts = array('parens' => 0, 'forums' => 0, 'subs' => 0);
if($e107->sql->db_Select('forum'))
{
$forumList = $e107->sql->db_getList();
foreach($forumList as $forum)
{
if($forum['forum_parent'] == 0)
{
$counts['parents']++;
}
elseif($forum['forum_sub'] != 0)
{
$counts['subs']++;
}
else
{
$counts['forums']++;
}
$tmp = $forum;
$tmp['forum_threadclass'] = $tmp['forum_postclass'];
$tmp['forum_options'] = '_NULL_';
// $tmp['_FIELD_TYPES'] = $ftypes['_FIELD_TYPES'];
$e107->sql->db_Insert('forum_new', $tmp);
}
$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);
}
}
function step7()
{
$e107 = e107::getInstance();
$stepCaption = 'Step 7: Calculate user post counts';
if(!isset($_POST['calculate_usercounts']))
{
$text = "
This step will calculate post count information for all users, as well as recount all for thread and reply counts.
";
$e107->ns->tablerender($stepCaption, $text);
return;
}
global $forum;
require_once(e_HANDLER.'user_extended_class.php');
$ue = new e107_user_extended;
$counts = $forum->getUserCounts();
foreach($counts as $uid => $count)
{
$ue->user_extended_setvalue($uid, 'user_plugin_forum_posts', $count, 'int');
}
$forum->forumUpdateCounts('all', true);
// var_dump($counts);
$text .= "
Successfully recalculated forum posts for ".count($counts)." users.
";
$e107->ns->tablerender($stepCaption, $text);
}
function step8()
{
$e107 = e107::getInstance();
$stepCaption = 'Step 8: Calculate last post information';
if(!isset($_POST['calculate_lastpost']))
{
$text = "
This step will recalculate all thread and forum lastpost information
";
$e107->ns->tablerender($stepCaption, $text);
return;
}
global $forum;
$forum->forumUpdateLastpost('forum', 'all', true);
// $forum->forumUpdateLastpost('thread', 84867);
$text .= "
Successfully recalculated lastpost information for all forums and threads.
";
$e107->ns->tablerender($stepCaption, $text);
}
function step9()
{
$e107 = e107::getInstance();
$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->ns->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
";
if($e107->sql->db_Select_gen($qry))
{
while($row = $e107->sql->db_Fetch(MYSQL_ASSOC))
{
$threadList[] = $row['thread_id'];
}
foreach($threadList as $threadId)
{
if($e107->sql->db_Select('forum_thread', 'thread_options', 'thread_id = '.$threadId, 'default'))
{
$row = $e107->sql->db_Fetch(MYSQL_ASSOC);
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';
$e107->sql->db_Update('forum_thread', $tmp);
}
}
}
else
{
$text = 'No threads found! ';
}
$text .= "
Successfully migrated forum poll information for ".count($threadList)." thread poll(s).
";
$e107->ns->tablerender($stepCaption, $text);
}
function step10()
{
$e107 = e107::getInstance();
global $f;
$stepCaption = 'Step 10: Migrate forum attachments';
if(!isset($_POST['migrate_attachments']))
{
$text = "
This step will migrate all forum attachment information.
All files will be moved from the e107_files/public directory into the e107_plugins/forum/attachment directory and related posts will be updated accordingly.
//Check for attached full-size images
if(preg_match_all('#\[img.*?\]({e_FILE}.*?_FT\d+_.*?)\[/img\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER))
{
foreach($matches as $match)
{
//Ensure it hasn't already been handled above
if(!in_array($match[1], $foundFiles))
{
$att = array();
$att['thread_id'] = $post['thread_id'];
$att['type'] = 'img';
$att['html'] = $match[0];
$att['name'] = $match[1];
$att['thumb'] = '';
$attachments[] = $att;
}
}
}
if(preg_match_all('#\[img.*?\](\.\./\.\./e107_files/public/.*?_FT\d+_.*?)\[/img\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER))
{
foreach($matches as $match)
{
//Ensure it hasn't already been handled above
if(!in_array($match[1], $foundFiles))
{
$att = array();
$att['thread_id'] = $post['thread_id'];
$att['type'] = 'img';
$att['html'] = $match[0];
$att['name'] = $match[1];
$att['thumb'] = '';
$attachments[] = $att;
}
}
}
//[file={e_FILE}public/1230090820_1_FT0_julia.zip]julia.zip[/file]
//Check for attached file (non-images)
if(preg_match_all('#\[file=({e_FILE}.*?)\](.*?)\[/file\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER))
{
foreach($matches as $match)
{
$att = array();
$att['thread_id'] = $post['thread_id'];
$att['type'] = 'file';
$att['html'] = $match[0];
$att['name'] = $match[1];
$att['thumb'] = '';
$attachments[] = $att;
}
}
if(preg_match_all('#\[file=(\.\./\.\./e107_files/public/.*?)\](.*?)\[/file\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER))
{
foreach($matches as $match)
{
$att = array();
$att['thread_id'] = $post['thread_id'];
$att['type'] = 'file';
$att['html'] = $match[0];
$att['name'] = $match[1];
$att['thumb'] = '';
$attachments[] = $att;
}
}
if(count($attachments))
{
$f->log("found ".count($attachments)." attachments");
$newValues = array();
$info = array();
$info['post_entry'] = $post['post_entry'];
foreach($attachments as $attachment)
{
$error = '';
$f->log($attachment['name']);
if($f->moveAttachment($attachment, $post['post_id'], $error))
{
$fInfo = pathinfo($attachment['name']);
// $_file = split('/', $attachment['name']);
$newval = $attachment['type'].'*'.$fInfo['basename'];
switch($attachment['type'])
{
//If file, add real name to entry
case 'file':
$tmp = explode('_', $fInfo['basename'], 4);
$newval .= '*'.$tmp[3];
break;
//If image and it has a thumb, add thumb filename to entry
case 'img':
if($attachment['thumb'])
{
$fInfo = pathinfo($attachment['thumb']);
$newval .= '*'.$fInfo['basename'];
}
break;
}
$newValues[] = $newval;
// echo "Newval = $newval ";
// echo "Removing from post:".htmlentities($attachment['html'])." ";
$info['post_entry'] = str_replace($attachment['html'], '', $info['post_entry']);
}
else
{
$errorText .= "Failure processing post {$post['post_id']} - file {$attachment['name']} - {$error} ";
$f->log("Failure processing post {$post['post_id']} - file {$attachment['name']} - {$error}");
}
}
// echo $errorText." ";
// Did we make any changes at all?
if(count($newValues))
{
$info['WHERE'] = 'post_id = '.$post['post_id'];
$info['post_attachments'] = implode(',', $newValues);
// print_a($info);
$e107->sql->db_Update('forum_post', $info);
}
// echo $post['thread_thread']." ";
// print_a($newValues);
// echo $info['newpost']." -------------------------------------- ";
// Update db values now
}
}
}
else
{
$text = 'No forum attachments found! ';
}
// $forum->forumUpdateLastpost('thread', 84867);
$text .= "
Successfully migrated forum attachment information for ".count($postList)." post(s).
";
$e107->ns->tablerender($stepCaption, $text);
}
function step11()
{
$e107 = e107::getInstance();
$stepCaption = 'Step 11: Delete old attachments';
if(!isset($_POST['delete_orphans']))
{
$text = "
The previous versions of the forum had difficulty deleting attachment files when posts or threads were deleted.
As a result of this, there is a potential for numerous files to exist that do not point to anything. In this step
we will try to identify these files and delete them.
";
$e107->ns->tablerender($stepCaption, $text);
return;
}
else
{
$text .= "
There were no orphaned files found
";
$e107->ns->tablerender($stepCaption, $text);
return;
}
}
function step12()
{
$e107 = e107::getInstance();
$f = new forumUpgrade;
$stepCaption = 'Step 12: Delete old forum data';
if(!isset($_POST['delete_old']))
{
$text = "
The forum upgrade should now be complete. During the upgrade process the old forum tables were
retained, it is now time to remove the tables.
We will also be marking the forum upgrade as completed!
";
$e107->ns->tablerender($stepCaption, $text);
return;
}
$qryArray = array(
"DROP TABLE `#forum_old`",
"DROP TABLE `#forum_t",
"DELETE * FROM `#generic` WHERE gen_type = 'forumUpgrade'"
);
foreach($qryArray as $qry)
{
$e107->sql->db_Select_gen($qry, true);
}
$ret = $f->setNewVersion();
$text = "
Congratulations, the forum upgrade is now completed!