From e911c7272c9e4605352357b7161b14eb4fb67f61 Mon Sep 17 00:00:00 2001 From: Cameron Date: Thu, 28 Mar 2013 00:43:00 -0700 Subject: [PATCH] Issue #149 Forum upgrade fixes - attachments still need work --- e107_handlers/user_extended_class.php | 89 ++++++++++++++------------ e107_plugins/forum/forum_class.php | 13 +++- e107_plugins/forum/forum_update.php | 92 +++++++++++++++------------ 3 files changed, 111 insertions(+), 83 deletions(-) diff --git a/e107_handlers/user_extended_class.php b/e107_handlers/user_extended_class.php index 55eba813e..890b3d946 100644 --- a/e107_handlers/user_extended_class.php +++ b/e107_handlers/user_extended_class.php @@ -442,8 +442,9 @@ class e107_user_extended function user_extended_field_exist($name) { - global $sql, $tp; - return $sql->db_Count('user_extended_struct','(*)', "WHERE user_extended_struct_name = '".$tp -> toDB($name, true)."'"); + $sql = e107::getDb('sql2'); + $tp = e107::getParser(); + return $sql->count('user_extended_struct','(*)', "WHERE user_extended_struct_name = '".$tp -> toDB($name, true)."'"); } 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) { - global $sql, $tp; - $this->clear_cache(); - if(is_array($name)) - { - extract($name); - } - if(!is_numeric($type)) - { - $type = $this->typeArray[$type]; - } + 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)) - { - $field_info = $this->user_extended_type_text($type, $default); - - // wrong type - if(false === $field_info) return false; - - if($order === '' && $field_info) + if($this->user_extended_field_exist($name)) { - if($sql->db_Select('user_extended_struct','MAX(user_extended_struct_order) as maxorder','1')) - { - $row = $sql->db_Fetch(); - if(is_numeric($row['maxorder'])) + return TRUE; + } + + 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)."'"); - if ($this->user_extended_field_exist($name)) - { - return TRUE; - } - } - return FALSE; + + return FALSE; } diff --git a/e107_plugins/forum/forum_class.php b/e107_plugins/forum/forum_class.php index c34966753..638bebf10 100644 --- a/e107_plugins/forum/forum_class.php +++ b/e107_plugins/forum/forum_class.php @@ -102,13 +102,18 @@ class e107forum private $userViewed, $permList; public $modArray, $prefs; - public function __construct() + public function __construct($update= false) { $this->e107 = e107::getInstance(); $tp = e107::getParser(); $this->userViewed = array(); $this->modArray = array(); - $this->loadPermList(); + + if($update === false) + { + $this->loadPermList(); + } + $this->prefs = e107::getPlugConfig('forum'); if(!$this->prefs->get('postspage')) { $this->setDefaults(); @@ -911,7 +916,7 @@ class e107forum } 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 { @@ -1306,6 +1311,8 @@ class e107forum // echo "threadid = $threadId
forum id = $forumId
"; // return; $e107 = e107::getInstance(); + $sql = e107::getDb(); + $threadId = (int)$threadId; $forumId = (int)$forumId; $lastpost = (int)$lastpost; diff --git a/e107_plugins/forum/forum_update.php b/e107_plugins/forum/forum_update.php index 22ccbf168..1bd519af5 100644 --- a/e107_plugins/forum/forum_update.php +++ b/e107_plugins/forum/forum_update.php @@ -23,7 +23,7 @@ if (!getperms('P')) error_reporting(E_ALL); require_once(e_PLUGIN.'forum/forum_class.php'); require_once(e_ADMIN.'auth.php'); -$forum = new e107forum; +$forum = new e107forum(true); $timestart = microtime(); $f = new forumUpgrade; @@ -177,8 +177,8 @@ function step2() function step3() { - $e107 = e107::getInstance(); $ns = e107::getRender(); + $mes = e107::getMessage(); $stepCaption = 'Step 3: Extended user field creation'; if(!isset($_POST['create_extended'])) @@ -208,37 +208,35 @@ function step3() $failed = false; foreach($fieldList as $fieldName => $fieldType) { - $text .= 'Creating extended user field user_'.$fieldName.' -> '; + $result = $ue->user_extended_add_system($fieldName, $fieldType); - if($result) + + if($result === true) { - $text .= 'Success
'; + $mes->addSuccess('Creating extended user field user_'.$fieldName); } else { - $text .= 'Failed
'; + $mes->addError('Creating extended user field user_'.$fieldName); $failed = true; } } if($failed) { - $text .= ' -

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

"; } - $ns->tablerender($stepCaption, $text); + $ns->tablerender($stepCaption, $mes->render(). $text); } @@ -275,7 +273,7 @@ function step4() if(substr($k, 0, 6) == 'forum_') { $nk = substr($k, 6); - echo "Converting $k to $nk
"; + $mes->addDebug("Converting $k to $nk"); $old_prefs[$nk] = $v; $coreConfig->remove($k); } @@ -321,12 +319,13 @@ function step4() $realm = trim($realm, '-.'); $trackList = preg_split('#\D+#', $realm); -// echo 'user_id = '.$userId.'
'; -// echo 'viewed = '.$viewed.'
'; -// echo 'realm = '.$realm.'
'; -// echo 'tracking = ' . implode(',', $trackList).'
'; -// print_a($trackList); -// echo "

"; + + $debug = 'user_id = '.$userId.'
'; + $debug .= 'viewed = '.$viewed.'
'; + $debug .= 'realm = '.$realm.'
'; + $debug .= 'tracking = ' . implode(',', $trackList).'
'; + $debug .= print_a($trackList,true); + $mes->addDebug($debug); if($viewed != '') { @@ -380,10 +379,10 @@ function step5() $stepCaption = 'Step 5: Migrate 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.
+ $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`.
- "); - $text = " +

"; + $text .= "
@@ -392,7 +391,7 @@ function step5() 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')) { @@ -416,10 +415,19 @@ function step5() $tmp['forum_threadclass'] = $tmp['forum_postclass']; $tmp['forum_options'] = '_NULL_'; // $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: