mirror of
https://github.com/e107inc/e107.git
synced 2025-08-14 02:24:08 +02:00
Issue #149 Forum upgrade fixes - attachments still need work
This commit is contained in:
@@ -442,8 +442,9 @@ class e107_user_extended
|
|||||||
|
|
||||||
function user_extended_field_exist($name)
|
function user_extended_field_exist($name)
|
||||||
{
|
{
|
||||||
global $sql, $tp;
|
$sql = e107::getDb('sql2');
|
||||||
return $sql->db_Count('user_extended_struct','(*)', "WHERE user_extended_struct_name = '".$tp -> toDB($name, true)."'");
|
$tp = e107::getParser();
|
||||||
|
return $sql->count('user_extended_struct','(*)', "WHERE user_extended_struct_name = '".$tp -> toDB($name, true)."'");
|
||||||
}
|
}
|
||||||
|
|
||||||
function clear_cache()
|
function clear_cache()
|
||||||
@@ -461,48 +462,58 @@ class e107_user_extended
|
|||||||
|
|
||||||
function user_extended_add($name, $text, $type, $parms, $values, $default, $required, $read, $write, $applicable, $order='', $parent)
|
function user_extended_add($name, $text, $type, $parms, $values, $default, $required, $read, $write, $applicable, $order='', $parent)
|
||||||
{
|
{
|
||||||
global $sql, $tp;
|
global $sql, $tp;
|
||||||
$this->clear_cache();
|
|
||||||
if(is_array($name))
|
|
||||||
{
|
|
||||||
extract($name);
|
|
||||||
}
|
|
||||||
if(!is_numeric($type))
|
|
||||||
{
|
|
||||||
$type = $this->typeArray[$type];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$this->user_extended_field_exist($name) && !$this->user_extended_reserved($name))
|
$this->clear_cache();
|
||||||
{
|
|
||||||
$field_info = $this->user_extended_type_text($type, $default);
|
|
||||||
|
|
||||||
// wrong type
|
if(is_array($name))
|
||||||
if(false === $field_info) return false;
|
{
|
||||||
|
extract($name);
|
||||||
|
}
|
||||||
|
|
||||||
if($order === '' && $field_info)
|
if(!is_numeric($type))
|
||||||
|
{
|
||||||
|
$type = $this->typeArray[$type];
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->user_extended_field_exist($name))
|
||||||
{
|
{
|
||||||
if($sql->db_Select('user_extended_struct','MAX(user_extended_struct_order) as maxorder','1'))
|
return TRUE;
|
||||||
{
|
}
|
||||||
$row = $sql->db_Fetch();
|
|
||||||
if(is_numeric($row['maxorder']))
|
if (!$this->user_extended_reserved($name))
|
||||||
|
{
|
||||||
|
$field_info = $this->user_extended_type_text($type, $default);
|
||||||
|
|
||||||
|
// wrong type
|
||||||
|
if(false === $field_info) return false;
|
||||||
|
|
||||||
|
if($order === '' && $field_info)
|
||||||
{
|
{
|
||||||
$order = $row['maxorder']+1;
|
if($sql->select('user_extended_struct','MAX(user_extended_struct_order) as maxorder','1'))
|
||||||
|
{
|
||||||
|
$row = $sql->fetch();
|
||||||
|
if(is_numeric($row['maxorder']))
|
||||||
|
{
|
||||||
|
$order = $row['maxorder']+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// field of type category
|
||||||
|
if($field_info)
|
||||||
|
{
|
||||||
|
$sql->gen('ALTER TABLE #user_extended ADD user_'.$tp -> toDB($name, true).' '.$field_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql->insert('user_extended_struct',"null,'".$tp -> toDB($name, true)."','".$tp -> toDB($text, true)."','".intval($type)."','".$tp -> toDB($parms, true)."','".$tp -> toDB($values, true)."', '".$tp -> toDB($default, true)."', '".intval($read)."', '".intval($write)."', '".intval($required)."', '0', '".intval($applicable)."', '".intval($order)."', '".intval($parent)."'");
|
||||||
|
|
||||||
|
if ($this->user_extended_field_exist($name))
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
// field of type category
|
|
||||||
if($field_info)
|
|
||||||
{
|
|
||||||
$sql->db_Select_gen('ALTER TABLE #user_extended ADD user_'.$tp -> toDB($name, true).' '.$field_info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql->db_Insert('user_extended_struct',"null,'".$tp -> toDB($name, true)."','".$tp -> toDB($text, true)."','".intval($type)."','".$tp -> toDB($parms, true)."','".$tp -> toDB($values, true)."', '".$tp -> toDB($default, true)."', '".intval($read)."', '".intval($write)."', '".intval($required)."', '0', '".intval($applicable)."', '".intval($order)."', '".intval($parent)."'");
|
return FALSE;
|
||||||
if ($this->user_extended_field_exist($name))
|
|
||||||
{
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -102,13 +102,18 @@ class e107forum
|
|||||||
private $userViewed, $permList;
|
private $userViewed, $permList;
|
||||||
public $modArray, $prefs;
|
public $modArray, $prefs;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct($update= false)
|
||||||
{
|
{
|
||||||
$this->e107 = e107::getInstance();
|
$this->e107 = e107::getInstance();
|
||||||
$tp = e107::getParser();
|
$tp = e107::getParser();
|
||||||
$this->userViewed = array();
|
$this->userViewed = array();
|
||||||
$this->modArray = array();
|
$this->modArray = array();
|
||||||
$this->loadPermList();
|
|
||||||
|
if($update === false)
|
||||||
|
{
|
||||||
|
$this->loadPermList();
|
||||||
|
}
|
||||||
|
|
||||||
$this->prefs = e107::getPlugConfig('forum');
|
$this->prefs = e107::getPlugConfig('forum');
|
||||||
if(!$this->prefs->get('postspage')) {
|
if(!$this->prefs->get('postspage')) {
|
||||||
$this->setDefaults();
|
$this->setDefaults();
|
||||||
@@ -911,7 +916,7 @@ class e107forum
|
|||||||
}
|
}
|
||||||
if($row['thread_lastuser_anon'])
|
if($row['thread_lastuser_anon'])
|
||||||
{
|
{
|
||||||
$sql->update('forum', "forum_lastpost_user = 0, forum_lastpost_anon = '{$row['thread_lastuser_anon']}', forum_lastpost_info = '{$lp_info}' WHERE forum_id=".$id);
|
$sql->update('forum', "forum_lastpost_user = 0, forum_lastpost_user_anon = '{$row['thread_lastuser_anon']}', forum_lastpost_info = '{$lp_info}' WHERE forum_id=".$id);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1306,6 +1311,8 @@ class e107forum
|
|||||||
// echo "threadid = $threadId <br />forum id = $forumId <br />";
|
// echo "threadid = $threadId <br />forum id = $forumId <br />";
|
||||||
// return;
|
// return;
|
||||||
$e107 = e107::getInstance();
|
$e107 = e107::getInstance();
|
||||||
|
$sql = e107::getDb();
|
||||||
|
|
||||||
$threadId = (int)$threadId;
|
$threadId = (int)$threadId;
|
||||||
$forumId = (int)$forumId;
|
$forumId = (int)$forumId;
|
||||||
$lastpost = (int)$lastpost;
|
$lastpost = (int)$lastpost;
|
||||||
|
@@ -23,7 +23,7 @@ if (!getperms('P'))
|
|||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
require_once(e_PLUGIN.'forum/forum_class.php');
|
require_once(e_PLUGIN.'forum/forum_class.php');
|
||||||
require_once(e_ADMIN.'auth.php');
|
require_once(e_ADMIN.'auth.php');
|
||||||
$forum = new e107forum;
|
$forum = new e107forum(true);
|
||||||
$timestart = microtime();
|
$timestart = microtime();
|
||||||
|
|
||||||
$f = new forumUpgrade;
|
$f = new forumUpgrade;
|
||||||
@@ -177,8 +177,8 @@ function step2()
|
|||||||
|
|
||||||
function step3()
|
function step3()
|
||||||
{
|
{
|
||||||
$e107 = e107::getInstance();
|
|
||||||
$ns = e107::getRender();
|
$ns = e107::getRender();
|
||||||
|
$mes = e107::getMessage();
|
||||||
|
|
||||||
$stepCaption = 'Step 3: Extended user field creation';
|
$stepCaption = 'Step 3: Extended user field creation';
|
||||||
if(!isset($_POST['create_extended']))
|
if(!isset($_POST['create_extended']))
|
||||||
@@ -208,37 +208,35 @@ function step3()
|
|||||||
$failed = false;
|
$failed = false;
|
||||||
foreach($fieldList as $fieldName => $fieldType)
|
foreach($fieldList as $fieldName => $fieldType)
|
||||||
{
|
{
|
||||||
$text .= 'Creating extended user field user_'.$fieldName.' -> ';
|
|
||||||
$result = $ue->user_extended_add_system($fieldName, $fieldType);
|
$result = $ue->user_extended_add_system($fieldName, $fieldType);
|
||||||
if($result)
|
|
||||||
|
if($result === true)
|
||||||
{
|
{
|
||||||
$text .= 'Success <br />';
|
$mes->addSuccess('Creating extended user field user_'.$fieldName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$text .= 'Failed <br />';
|
$mes->addError('Creating extended user field user_'.$fieldName);
|
||||||
$failed = true;
|
$failed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($failed)
|
if($failed)
|
||||||
{
|
{
|
||||||
$text .= '
|
$mes->addError("Creation of extended field(s) failed. You can not continue until these are create successfully!");
|
||||||
<br /><br />
|
|
||||||
Creation of extended field(s) failed. You can not continue until these are create successfully!
|
|
||||||
';
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$text .= "
|
$text .= "
|
||||||
<br /><br />
|
|
||||||
<form method='post' action='".e_SELF."?step=4'>
|
<form method='post' action='".e_SELF."?step=4'>
|
||||||
<input class='btn button' type='submit' name='nextStep[4]' value='Proceed to step 4' />
|
<input class='btn button' type='submit' name='nextStep[4]' value='Proceed to step 4' />
|
||||||
</form>
|
</form>
|
||||||
";
|
";
|
||||||
}
|
}
|
||||||
|
|
||||||
$ns->tablerender($stepCaption, $text);
|
$ns->tablerender($stepCaption, $mes->render(). $text);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,7 +273,7 @@ function step4()
|
|||||||
if(substr($k, 0, 6) == 'forum_')
|
if(substr($k, 0, 6) == 'forum_')
|
||||||
{
|
{
|
||||||
$nk = substr($k, 6);
|
$nk = substr($k, 6);
|
||||||
echo "Converting $k to $nk<br />";
|
$mes->addDebug("Converting $k to $nk");
|
||||||
$old_prefs[$nk] = $v;
|
$old_prefs[$nk] = $v;
|
||||||
$coreConfig->remove($k);
|
$coreConfig->remove($k);
|
||||||
}
|
}
|
||||||
@@ -321,12 +319,13 @@ function step4()
|
|||||||
$realm = trim($realm, '-.');
|
$realm = trim($realm, '-.');
|
||||||
$trackList = preg_split('#\D+#', $realm);
|
$trackList = preg_split('#\D+#', $realm);
|
||||||
|
|
||||||
// echo 'user_id = '.$userId.'<br />';
|
|
||||||
// echo 'viewed = '.$viewed.'<br />';
|
$debug = 'user_id = '.$userId.'<br />';
|
||||||
// echo 'realm = '.$realm.'<br />';
|
$debug .= 'viewed = '.$viewed.'<br />';
|
||||||
// echo 'tracking = ' . implode(',', $trackList).'<br />';
|
$debug .= 'realm = '.$realm.'<br />';
|
||||||
// print_a($trackList);
|
$debug .= 'tracking = ' . implode(',', $trackList).'<br />';
|
||||||
// echo "<br /><br />";
|
$debug .= print_a($trackList,true);
|
||||||
|
$mes->addDebug($debug);
|
||||||
|
|
||||||
if($viewed != '')
|
if($viewed != '')
|
||||||
{
|
{
|
||||||
@@ -380,10 +379,10 @@ function step5()
|
|||||||
$stepCaption = 'Step 5: Migrate forum data';
|
$stepCaption = 'Step 5: Migrate forum data';
|
||||||
if(!isset($_POST['move_forum_data']))
|
if(!isset($_POST['move_forum_data']))
|
||||||
{
|
{
|
||||||
$mes->addInfo("This step will copy all of your forum configuration from the `forum` table into the `forum_new` table.<br />
|
$text ="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 />
|
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 = "
|
$text .= "
|
||||||
<form method='post'>
|
<form method='post'>
|
||||||
<input class='btn button' type='submit' name='move_forum_data' value='Proceed with forum data move' />
|
<input class='btn button' type='submit' name='move_forum_data' value='Proceed with forum data move' />
|
||||||
</form>
|
</form>
|
||||||
@@ -392,7 +391,7 @@ function step5()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$counts = array('parens' => 0, 'forums' => 0, 'subs' => 0); //XXX Typo on 'parents' ?
|
$counts = array('parents' => 0, 'forums' => 0, 'subs' => 0); //XXX Typo on 'parents' ?
|
||||||
|
|
||||||
if($sql->select('forum'))
|
if($sql->select('forum'))
|
||||||
{
|
{
|
||||||
@@ -416,10 +415,19 @@ function step5()
|
|||||||
$tmp['forum_threadclass'] = $tmp['forum_postclass'];
|
$tmp['forum_threadclass'] = $tmp['forum_postclass'];
|
||||||
$tmp['forum_options'] = '_NULL_';
|
$tmp['forum_options'] = '_NULL_';
|
||||||
// $tmp['_FIELD_TYPES'] = $ftypes['_FIELD_TYPES'];
|
// $tmp['_FIELD_TYPES'] = $ftypes['_FIELD_TYPES'];
|
||||||
$sql->insert('forum_new', $tmp);
|
if($sql->insert('forum_new', $tmp))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$mes->addError("Insert failed on ".print_a($tmp,true));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$mes->addInfo ( "
|
$mes->addSuccess ( "
|
||||||
Forum data move results:
|
Forum data move results:
|
||||||
<ul>
|
<ul>
|
||||||
<li>Number of forum parents processed: {$counts['parents']} </li>
|
<li>Number of forum parents processed: {$counts['parents']} </li>
|
||||||
@@ -429,10 +437,10 @@ function step5()
|
|||||||
");
|
");
|
||||||
|
|
||||||
$result = $sql->gen('RENAME TABLE `#forum` TO `#forum_old` ') ? e_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
|
$result = $sql->gen('RENAME TABLE `#forum` TO `#forum_old` ') ? e_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
|
||||||
$mes->add("Renaming forum to forum_old",$result);
|
$mes->add("Renaming forum to forum_old", $result);
|
||||||
|
|
||||||
$result = $sql->gen('RENAME TABLE `#forum_new` TO `#forum` ') ? e_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
|
$result = $sql->gen('RENAME TABLE `#forum_new` TO `#forum` ') ? e_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
|
||||||
$mes->add("Renaming forum_new to forum",$result);
|
$mes->add("Renaming forum_new to forum", $result);
|
||||||
|
|
||||||
|
|
||||||
$text = "
|
$text = "
|
||||||
@@ -463,21 +471,21 @@ function step6()
|
|||||||
{
|
{
|
||||||
$count = $sql->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);
|
$limitDropdown = createThreadLimitDropdown($count);
|
||||||
$text = "
|
|
||||||
<form method='post'>
|
$text = "This step will copy all of your existing forum threads and posts into the new `forum_thread` and `forum_post` tables.<br /><br />
|
||||||
This step will copy all of your existing forum threads and posts into the new `forum_thread` and `forum_post` tables.<br /><br />
|
|
||||||
Depending on your forum size and speed of server, this could take some time. This routine will attempt to do it in steps in order to
|
Depending on your forum size and speed of server, this could take some time. This routine will attempt to do it in steps in order to
|
||||||
reduce the possibility of data loss and server timeouts.<br />
|
reduce the possibility of data loss and server timeouts.<br />
|
||||||
<br />
|
<br />
|
||||||
Your current timeout appears to be set at {$maxTime} seconds. This routine will attempt to extend this time in order to process all threads,
|
Your current timeout appears to be set at {$maxTime} seconds. This routine will attempt to extend this time in order to process all threads,
|
||||||
success will depend on your server configuration. If you get a timeout while performing this function, return to this page and select fewer threads
|
success will depend on your server configuration. If you get a timeout while performing this function, return to this page and select fewer threads
|
||||||
to process.
|
to process.
|
||||||
<br /><br />
|
";
|
||||||
|
|
||||||
|
$text .= "<form method='post'>
|
||||||
There are {$count} forum threads to convert, we will be doing it in steps of: {$limitDropdown}
|
There are {$count} forum threads to convert, we will be doing it in steps of: {$limitDropdown}
|
||||||
<br /><br />
|
<br /><br />
|
||||||
<input class='btn button' type='submit' name='move_thread_data' value='Begin thread data move' />
|
<input class='btn button' type='submit' name='move_thread_data' value='Begin thread data move' />
|
||||||
</form>
|
</form>";
|
||||||
";
|
|
||||||
$ns->tablerender($stepCaption, $mes->render(). $text);
|
$ns->tablerender($stepCaption, $mes->render(). $text);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -501,7 +509,7 @@ function step6()
|
|||||||
{
|
{
|
||||||
$postCount = 0;
|
$postCount = 0;
|
||||||
$threadList = $sql->db_getList();
|
$threadList = $sql->db_getList();
|
||||||
$text = '';
|
|
||||||
foreach($threadList as $t)
|
foreach($threadList as $t)
|
||||||
{
|
{
|
||||||
set_time_limit(30);
|
set_time_limit(30);
|
||||||
@@ -509,7 +517,7 @@ function step6()
|
|||||||
$result = $f->migrateThread($id);
|
$result = $f->migrateThread($id);
|
||||||
if($result === false)
|
if($result === false)
|
||||||
{
|
{
|
||||||
echo "ERROR! Failed to migrate thread id: {$id}<br />";
|
$mes->addError("ERROR! Failed to migrate thread id: {$id}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -518,11 +526,13 @@ function step6()
|
|||||||
$f->setUpdateInfo();
|
$f->setUpdateInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$text .= '<br />Successfully converted '.count($threadList)." threads and {$postCount} replies.<br />";
|
|
||||||
$text .= "Last thread id = {$t['thread_id']}<br />";
|
$mes->addSuccess('Successfully converted '.count($threadList)." threads and {$postCount} replies");
|
||||||
|
$mes->addSuccess("Last thread id = {$t['thread_id']}");
|
||||||
|
|
||||||
|
|
||||||
$count = $sql->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)
|
if($count)
|
||||||
{
|
{
|
||||||
$limitDropdown = createThreadLimitDropdown($count);
|
$limitDropdown = createThreadLimitDropdown($count);
|
||||||
@@ -714,7 +724,7 @@ function step10()
|
|||||||
{
|
{
|
||||||
$text = "
|
$text = "
|
||||||
This step will migrate all forum attachment information.<br />
|
This step will migrate all forum attachment information.<br />
|
||||||
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.
|
All files will be moved from the e107_files/public directory into the ".e_MEDIA."plugins/forum/attachment directory and related posts will be updated accordingly.
|
||||||
<br /><br />
|
<br /><br />
|
||||||
<form method='post'>
|
<form method='post'>
|
||||||
<input class='btn button' type='submit' name='migrate_attachments' value='Proceed with attachment migration' />
|
<input class='btn button' type='submit' name='migrate_attachments' value='Proceed with attachment migration' />
|
||||||
@@ -1058,8 +1068,8 @@ function step12()
|
|||||||
|
|
||||||
$qryArray = array(
|
$qryArray = array(
|
||||||
"DROP TABLE `#forum_old`",
|
"DROP TABLE `#forum_old`",
|
||||||
"DROP TABLE `#forum_t",
|
"DROP TABLE `#forum_t`",
|
||||||
"DELETE * FROM `#generic` WHERE gen_type = 'forumUpgrade'"
|
"DELETE FROM `#generic` WHERE gen_type = 'forumUpgrade' "
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach($qryArray as $qry)
|
foreach($qryArray as $qry)
|
||||||
@@ -1091,7 +1101,7 @@ class forumUpgrade
|
|||||||
{
|
{
|
||||||
$this->updateInfo['lastThread'] = 0;
|
$this->updateInfo['lastThread'] = 0;
|
||||||
$this->attachmentData = array();
|
$this->attachmentData = array();
|
||||||
$this->logf = e_MEDIA.'files/forum_upgrade.txt';
|
$this->logf = e_LOG.'forum_upgrade.txt';
|
||||||
$this->getUpdateInfo();
|
$this->getUpdateInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user