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; } 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(); if(isset($_POST) && count($_POST)) { if(isset($_POST['skip_attach'])) { $f->updateInfo['skip_attach'] = 1; $f->updateInfo['currentStep'] = 2; $f->setUpdateInfo(); } var_dump($_POST); 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 : ''); 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.

"; $e107->ns->tablerender('Step 2: Forum table creation', $text); return; } 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 = ''; foreach($tabList as $name => $rename) { $text .= 'Creating table '.($rename ? $rename : $name).' -> '; $result = $db->createTable(e_PLUGIN.'forum/forum_sql.php', $name, true, $rename); if($result) { $text .= 'Success
'; } else { $text .= 'Failed
'; $failed = true; } } if($failed) { $text .= "

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


"; $e107->ns->tablerender($stepCaption, $text); return; } require_once(e_HANDLER.'user_extended_class.php'); $ue = new e107_user_extended; $fieldList = array( 'plugin_forum_posts' => EUF_INTEGER, 'plugin_forum_viewed' => EUF_TEXTAREA ); $failed = false; foreach($fieldList as $fieldName => $fieldType) { $text .= 'Creating extended user field user_'.$fieldName.' -> '; $result = $ue->user_extended_add_system($fieldName, $fieldType); if($result) { $text .= 'Success
'; } else { $text .= 'Failed
'; $failed = true; } } if($failed) { $text .= '

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

"; } $e107->ns->tablerender($stepCaption, $text); } function step4() { $e107 = e107::getInstance(); $stepCaption = 'Step 4: Move user specific forum data'; if(!isset($_POST['move_user_data'])) { $text = " This step will move the 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.

"; $e107->ns->tablerender($stepCaption, $text); return; } $result = array( 'usercount' => 0, 'viewcount' => 0, 'trackcount' => 0 ); $db = new db; if($db->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)) { $result['usercount']++; $userId = (int)$row['user_id']; $viewed = $row['user_viewed']; $viewed = trim($viewed, '.'); $tmp = preg_split('#\.+#', $viewed); $viewed = implode(',', $tmp); $realm = $row['user_realm']; $realm - str_replace('USERREALM', '', $realm); $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 "

"; 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; $tmp['_FIELD_TYPES']['track_userid'] = 'int'; $tmp['_FIELD_TYPES']['track_thread'] = 'int'; $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); } class forumUpgrade { var $newVersion = '2.0'; var $error = array(); var $updateInfo; function forumUpgrade() { $this->getUpdateInfo(); } function checkAttachmentDirs() { $dirs = array( e_PLUGIN.'forum/attachments/', e_PLUGIN.'forum/attachments/thumb' ); foreach($dirs as $dir) { if(!file_exists($dir)) { if(!mkdir($dir)) { $this->error['attach'][] = "Directory '{$dir}' does not exist and I was unable to create it"; } } else { if(!is_writable($dir)) { $this->error['attach'][] = "Directory '{$dir}' exits, but is not writeable"; } } } } function getUpdateInfo() { $e107 = e107::getInstance(); if($e107->sql->db_Select('generic', '*', "gen_type = 'forumUpgrade'")) { $row = $e107->sql->db_Fetch(MYSQL_ASSOC); $this->updateInfo = unserialize($row['gen_chardata']); } else { $qry = "INSERT INTO `#generic` (gen_type) VALUES ('forumUpgrade')"; $e107->sql->db_Select_gen($qry); $this->updateInfo = array(); } } function setUpdateInfo() { $e107 = e107::getInstance(); $info = mysql_real_escape_string(serialize($this->updateInfo)); $qry = "UPDATE `#generic` Set gen_chardata = '{$info}' WHERE gen_type = 'forumUpgrade'"; $e107->sql->db_Select_gen($qry); } function setNewVersion() { $e107 = e107::getInstance(); $e107->sql->db_Update('plugin',"plugin_version = '{$this->newVersion}' WHERE plugin_name='Forum'"); return "Forum Version updated to version: {$this->newVersion}
"; } } function forum_update_adminmenu() { global $currentStep; $var[1]['text'] = 'Step 1 - Permissions'; $var[1]['link'] = '#'; $var[2]['text'] = 'Step 2 - Create new tables'; $var[2]['link'] = '#'; $var[3]['text'] = 'Step 3 - Create extended fields'; $var[3]['link'] = '#'; $var[4]['text'] = 'Step 4 - Move user data'; $var[4]['link'] = '#'; $var[5]['text'] = 'Step 5 - Migrate forum configuration'; $var[5]['link'] = '#'; $var[6]['text'] = 'Step 6 - Migrate threads/replies'; $var[6]['link'] = '#'; $var[7]['text'] = 'Step 7 - Calc counts/lastpost data'; $var[7]['link'] = '#'; $var[8]['text'] = 'Step 8 - Migrate any poll information'; $var[8]['link'] = '#'; $var[9]['text'] = 'Step 9 - Migrate any attachments'; $var[9]['link'] = '#'; $var[10]['text'] = 'Step 10 - Migrate any attachments'; $var[10]['link'] = '#'; $var[11]['text'] = 'Step 11 - Delete old forum data'; $var[11]['link'] = '#'; for($i=1; $i < $currentStep; $i++) { $var[$i]['text'] = "{$var[$i]['text']}"; } show_admin_menu('Forum Upgrade', $currentStep, $var); } ?>