由於我們採用的是覆蓋原來的檔案,那麼在執行的時候 呼叫的配置檔案還是原先的配置檔案 (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' 到此升級以完成