由於我們採用的是覆蓋原來的文件,那麼在執行的時候 調用的配置文件還是原先的配置文件 (config 目錄下)
首先初始化環境變量
- include_once('../source/class/class_core.php');
- include_once('../source/function/function_core.php');
- @set_time_limit(0);
- $cachelist = array();
- $discuz = & discuz_core::instance();
- $discuz->cachelist = $cachelist;
- $discuz->init_cron = false;
- $discuz->init_setting = false;
- $discuz->init_user = false;
- $discuz->init_session = false;
- $discuz->init_misc = false;
- $discuz->init();
- $config = array(
- 'dbcharset' => $_G['config']['db']['1']['dbcharset'],
- 'charset' => $_G['config']['output']['charset'],
- 'tablepre' => $_G['config']['db']['1']['tablepre']
- );
其中在升級過程中,調用的還是原來的表前綴。檢查 update.lock 文件是否存在
- $devmode = file_exists(DISCUZ_ROOT.'./install/data/install_dev.sql');
- $sqlfile = DISCUZ_ROOT.($devmode ? './install/data/install_dev.sql' : './install/data/install.sql')
調用 x2 的標準數據庫結果文件,用於在 x1.5 或 x2RC 版中進行數據表結果的創建和必要的初始化數據
當進行升級操作的時候,點擊 「準備完畢,開始升級」 訪問路徑 「update.php?step=prepare」
準備完畢之後,show_msg('準備完畢,進入下一步數據庫結構升級', $theurl.'?step=sql'); show_msg 函數用於提示執行的過程和進入下一升級過程
$_GET['step'] == 'sql' 時 ,進入數據庫結構升級,在原有的基礎上對數據庫結構進行升級
當數據結構升級完畢
- if($i>=$count_i) {
- show_msg('數據庫結構升級完畢,進入下一步數據升級操作', $theurl.'?step=data');
- }
進入數據轉換過程
$_GET['step'] == 'data'
在數據轉換過程中通過 類似這種方式 show_msg("實名功能升級完畢", "$theurl?step=data&op=$nextop"),循環的進行數據轉換,其中容易出問題的地方是附件的轉換 $_GET['op'] == 'forumattach'
- $limit = 10000;
- $start = !empty($_GET['start']) ? $_GET['start'] : 0;
- $needupgrade = DB::query("SELECT COUNT(*) FROM ".DB::table('forum_attachmentfield'), 'SILENT');
- $count = DB::result_first("SELECT COUNT(*) FROM ".DB::table('forum_attachment'));
- if($needupgrade && $count) {
- if(!$start) {
- for($i = 0;$i < 10;$i++) {
- DB::query("TRUNCATE ".DB::table('forum_attachment_'.$i));
- }
- }
- $query = DB::query("SELECT a.*,af.description FROM ".DB::table('forum_attachment')." a
- LEFT JOIN ".DB::table('forum_attachmentfield')." af USING(aid)
- ORDER BY aid LIMIT $start, $limit");
- if(DB::num_rows($query)) {
- while($row = DB::fetch($query)) {
- $row = daddslashes($row);
- $tid = (string)$row['tid'];
- $tableid = $tid{strlen($tid)-1};
- DB::update('forum_attachment', array('tableid' => $tableid), array('aid' => $row['aid']));
- DB::insert('forum_attachment_'.$tableid, array(
- 'aid' => $row['aid'],
- 'tid' => $row['tid'],
- 'pid' => $row['pid'],
- 'uid' => $row['uid'],
- 'dateline' => $row['dateline'],
- 'filename' => $row['filename'],
- 'filesize' => $row['filesize'],
- 'attachment' => $row['attachment'],
- 'remote' => $row['remote'],
- 'description' => $row['description'],
- 'readperm' => $row['readperm'],
- 'price' => $row['price'],
- 'isimage' => $row['isimage'],
- 'width' => $row['width'],
- 'thumb' => $row['thumb'],
- 'picid' => $row['picid'],
- ));
- }
- $start += $limit;
- show_msg("論壇附件表升級中 ... $start/$count", "$theurl?step=data&op=forumattach&start=$start");
- }
- DB::query("DROP TABLE `".DB::table('forum_attachmentfield')."`");
- DB::query("ALTER TABLE ".DB::table('forum_attachment')."
- DROP `width`,
- DROP `dateline`,
- DROP `readperm`,
- DROP `price`,
- DROP `filename`,
- DROP `filetype`,
- DROP `filesize`,
- DROP `attachment`,
- DROP `isimage`,
- DROP `thumb`,
- DROP `remote`,
- DROP `picid`
- ");
- }
- show_msg("論壇附件表升級完畢", "$theurl?step=data&op=$nextop");
程序先是對 forum_attachmentfield 、 forum_attachment 表進行查詢統計
這裏主要是針對 x1.5 的處理,如果 $needupgrade && $count 都成立,對附件表
attachment0_9(這在數據結構升級中以完成處理) 進行滯空。然後,對兩表 forum_attachmentfield 、
forum_attachment 進行關聯查詢將數據插入到 x2 的數據表中,由於 x2 的附件表進行了分表 所以在插入附件表的時候要進行處理
$tid = (string)$row['tid'];$tableid = $tid{strlen($tid)-1}; 取得每個主題最後一位,從而插入到對應的附件表中
附件轉換完成之後。 用户檢驗附件升級是否成功可以查看
attachment0_9 中的數據是否存在,x1.5 的附件表是否還存在。如果從 x2RC 版升級到 X2 正式版,在升級的時候 x1.5 的
forum_attachmentfield 表還存在的話,會將 attachment0_9 表中的數據給清空這樣會導致附件轉換失敗
$_GET['step'] == 'delete' 將進入數據庫冗餘數據進行分析並顯示,當用户提交刪除之後
進入 $_POST['delsubmit'] 對錶進行刪除, 如果沒有多餘數據或者用户忽略
將進入 $_GET['step'] == 'style' 對樣式進行更新
最後進行緩存更新 $_GET['step'] == 'cache' 到此升級以完成