去评论
dz插件网

Discuz! X3.4 X3.5 转 Discuz! Q转换程序正式发布

admin
2020/12/23 20:18:36
[md]## Discuz! X3.4 X3.5 杞 Discuz! Q

## 鎿嶄綔鍦烘櫙

鏈枃妗e皢鎸囧鎮ㄥ浣曞皢 Discuz! X3.4 X3.5 搴旂敤绋嬪簭鏁版嵁杩佺Щ鑷矰iscuz! Q 搴旂敤绋嬪簭锛岄氳繃璇ユ搷浣滃彲浠ュ皢 Discuz! X3.4 X3.5涓殑鐢ㄦ埛銆佺増鍧椼佹櫘閫氫富棰樸佸洖澶嶃侀檮浠跺浘鐗囩瓑鏁版嵁杞崲鑷 Discuz! Q銆

WARNING

* 鍦ㄨ浆鎹㈢▼搴忓紑濮嬪墠锛屼负纭繚鍥犳搷浣滃け璇紝瀵艰嚧鏁版嵁涓㈠け绛夐棶棰橈紝璇锋彁鍓嶅仛濂芥暟鎹浠姐
* 鍦ㄨ浆鎹㈢▼搴忓紑濮嬪墠锛岃淇濊瘉 Discuz! Q 鏁版嵁搴撲负鍏ㄦ柊瀹夎锛屾垨鑰呭彧閫氳繃鏈搷浣滄彁渚涚殑杞崲绋嬪簭杞崲杩囨暟鎹傚惁鍒欏皢鍙兘浼氬鑷存暟鎹涪澶憋紝鎴栬浆鎹㈤敊璇
* 杞崲绋嬪簭宸ュ叿闇瑕佸湪 PHP 7.2.5 鍙婁互涓婄幆澧冭繍琛岋紝璇风‘淇濆凡閰嶇疆璇ョ幆澧冦傚缓璁湪閮ㄧ讲鐨 Discuz! Q 绔欑偣杩愯銆傛湰鏂囨。浠ュ湪閮ㄧ讲鐨 Discuz! Q 鐨勬湇鍔″櫒涓婅繘琛岃浆鍖栦负渚嬨

## 鍓嶆彁鏉′欢

* 宸查儴缃 Discuz! Q銆
* 鍏峰 PHP 7.2.5 鍙婁互涓婄幆澧冪殑涓绘満銆

## 鎿嶄綔姝ラ

### 姝ラ涓锛氫笅杞藉苟瑙e帇杞寲宸ュ叿

1. 鎮ㄥ彲浠 [鍗曞嚮姝ゅ **(opens new window)**](https://discuzq-docs-1258344699. ... nvert/xconvertq.zip)涓嬭浇杞寲宸ュ叿鑷 宸查儴缃茬殑 Discuz! Q 鐨勬湇鍔″櫒涓娿

TIP

濡傛灉鎮ㄦ槸 Linux 鏈嶅姟鍣紝鎮ㄥ彲浠ュ湪鏈嶅姟鍣ㄧ殑缁堢涓紝閫氳繃璇ュ懡浠よ繘琛屼笅杞 `wget -c https://discuzq-docs-1258344699. ... vert/xconvertq.zip`

2. 浣跨敤瑙e帇宸ュ叿瑙e帇鍘嬬缉鍖呫

TIP

濡傛灉鎮ㄦ槸 Linux 鏈嶅姟鍣紝鎮ㄥ彲浠ュ湪鏈嶅姟鍣ㄧ殑缁堢涓紝閫氳繃璇ュ懡浠よ繘琛岃В鍘 `unzip xconvertq.zip`銆

### 姝ラ浜岋細閰嶇疆杞寲宸ュ叿

#### 閰嶇疆杞寲宸ュ叿鏁版嵁搴撲俊鎭

1. 鍦ㄨВ鍘嬪嚭鐨 `xconvertq` 鏂囦欢澶逛腑锛屾壘鍒 `config` 鐩綍涓嬬殑`database.php`鏂囦欢锛屽苟浣跨敤鏂囨湰缂栬緫鍣ㄦ垨浣跨敤 WinSCP 绛夊伐鍏锋墦寮璇ユ枃浠躲
2. 鍦 `database.php` 鏂囦欢涓厤缃暟鎹簱淇℃伅銆備俊鎭唴瀹瑰彲鏍规嵁鏂囦欢涓敞閲婅繘琛屽~鍐欍傚涓嬫墍绀猴細

```text codecopy-enabled
<?php

return [
    'discuzq' => [
        'driver'    => 'mysql',
        'host'      => 'localhost', //Q鏁版嵁搴撳湴鍧
        'port' => '3306', //Q鏁版嵁搴撶鍙
        'prefix'    => 'pre_', //Q琛ㄥ墠缂锛屾病鏈夊垯鐣欑┖
        'database'  => '', //Q鏁版嵁搴撳悕
        'username'  => '', //Q鏁版嵁搴撶敤鎴
        'password'  => '', //Q鏁版嵁搴撳瘑鐮
        'charset'   => 'utf8', //Q鏁版嵁缂栫爜
        'collation' => 'utf8mb4_unicode_ci', //Q鏁版嵁搴撳瓧绗﹂泦
    ],
    'discuzx' => [
        'driver'    => 'mysql',
        'host'      => 'localhost', //X鏁版嵁搴撳湴鍧
        'port' => '3306', //X鏁版嵁搴撶鍙
        'prefix'    => 'pre_', //X琛ㄥ墠缂锛屾病鏈夊垯鐣欑┖
        'database'  => '', //X鏁版嵁搴撳悕
        'username'  => '', //X鏁版嵁搴撶敤鎴
        'password'  => '', //X鏁版嵁搴撳瘑鐮
        'charset'   => 'utf8', //X鏁版嵁缂栫爜
        'collation' => 'utf8_unicode_ci', //X鏁版嵁搴撳瓧绗﹂泦
    ]
];
```

TIP

* 鍏朵腑 `discuzq` 涓 `Discuz! Q` 鏁版嵁搴撹繛鎺ヤ俊鎭紝 `discuzx` 涓 `Discuz! X3.4 X3.5` 鏁版嵁搴撹繛鎺ヤ俊鎭
* 鑻 `Discuz! X3.4 X3.5` 涓 `gbk` 缂栫爜锛屾暟鎹簱杩炴帴淇℃伅涓殑`X鏁版嵁缂栫爜` 鍜宍X鏁版嵁搴撳瓧绗﹂泦`淇濇寔鐜版湁榛樿閰嶇疆鍗冲彲銆

3. 鍦ㄧ粓绔腑锛屽湪璇ョ▼搴忕殑鏍圭洰褰曚笅杈撳叆鍛戒护 `php discoa app:test` 娴嬭瘯鏁版嵁搴撴槸鍚︽甯歌繛鎺ャ傛彁绀 `success` 鍗充唬琛ㄨ繛鎺ユ甯革紝鑻ユ彁绀哄叾浠栦俊鎭紝璇锋鏌ユ暟鎹簱閰嶇疆淇℃伅鏄惁濉啓姝g‘銆

#### 閰嶇疆杞寲宸ュ叿杞崲妯″紡

1. 鍦ㄨВ鍘嬪嚭鐨 `xconvertq` 鏂囦欢澶逛腑锛屾壘鍒癭config`鐩綍涓嬬殑`config.php`鏂囦欢锛屽苟浣跨敤鏂囨湰缂栬緫鍣ㄦ垨浣跨敤 WinSCP 绛夊伐鍏锋墦寮璇ユ枃浠躲
2. 閰嶇疆 `breakpoint_continuation`瀛楁锛屽彲閫夊间负 true 涓 false銆傝鏄庡涓嬶細

* 褰 `breakpoint_continuation` 瀛楁鐨勫间负 `true`鏃讹紝琛ㄧず寮鍚柇鐐圭画杞ā寮忥紝鍦ㄦ妯″紡涓嬫墽饩忚浆鎹㈠懡浠わ紝绋嬪簭浼氬拷鐣ヤ箣鍓嶈浆鎹㈣繃鐨勬暟鎹
* 褰 `breakpoint_continuation` 鐨勫间负 false 鏃讹紝绋嬪簭浼氬厛妫鏌饨爣琛ㄦ槸鍚︽湁澶氫綑鏁版嵁锛屽鏋滄湁鍒欏仠 饨屾墽饩忓搴旂殑杞崲浠诲姟

### 姝ラ涓夛細閰嶇疆 Discuz! Q 鏁版嵁搴

1. 鍦 Discuz! Q 浣跨敤鐨勬暟鎹簱涓繍饩忎互涓 sql 鍛戒护锛

WARNING

璇锋偍娉ㄦ剰淇敼浠ヤ笅 sql 鍛戒护涓 `pre_users` 鐨勮〃鏍煎墠缂锛屽鏋滄病鏈夊墠缂锛屽幓鎺 pre_ 鍗冲彲銆

```sql codecopy-enabled
ALTER TABLE `pre_users` ADD `salt` CHAR(6) NULL AFTER `password`;
ALTER TABLE `pre_posts` CHANGE `content` `content` MEDIUMTEXT CHARACTER SET
utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '鍐呭';
```

### 姝ラ鍥涳細淇敼 Discuz! Q 鏂囦欢

#### 鏇存柊 Discuz! Q 鐧婚檰楠岃瘉饨備欢

1. 鍦 Discuz! Q 鏂囦欢鐩綍涓紝鎵惧埌 `app/Listeners/User/CheckLogin.php` 鏂囦欢锛屽苟浣跨敤鏂囨湰缂栬緫鍣ㄦ垨浣跨敤 WinSCP 绛夊伐鍏锋墦寮璇ユ枃浠躲
2. 缂栬緫 `CheckLogin.php` 鏂囦欢锛屾煡鎵句互涓嬩唬鐮侊紙72饩忛檮杩戯級銆

```php codecopy-enabled
if ($event->password !== '' && !$event->user->checkPassword($event->password)) {
```

3. 鍦ㄤ互涓婁唬鐮佸墠娣诲姞濡備笅浠g爜锛

```php codecopy-enabled
$this->checkSaltPassword($event);
```

4. 鍦 `CheckLogin.php`绋嬪簭饨備欢鏈鍚庘紑涓激鎷彿`}`鍓嶏紝缁欐湰饨備欢娣诲姞濡備笅浠g爜锛**娉ㄦ剰锛**澶嶅埗绮樿创鍚庯紝鎹㈣澶勪細澶氬嚭绌烘牸锛屼緥濡俙->`浼氬彉鎴恅- >`锛岃娉ㄦ剰鍘婚櫎锛夛細

```php codecopy-enabled
/**
     * @param $event
     * Discuz! X3.4 X3.5 瀵嗙爜杞崲
     */
private function checkSaltPassword($event) {
  if (!empty($event->user->salt) && !empty($event->password)) {
    $passwordmd5 = preg_match('/^\w{32}$/', $event->password) ? $event->password : md5($event->password);
    $passwordmd5 = md5($passwordmd5 . $event->user->salt);
    if ($event->user->password == $passwordmd5) {
      $event->user->password = $event->password;
      $event->user->salt = '';
      $event->user->save();
    }
  }
}
```

5. 灏嗚浆鎹㈢▼搴忊茎鐨勨絺浠 `app/Formatter/CustomerConfigurator.php` 澶嶅埗鍒 Discuz! Q 绋嬪簭 `app/Formatter`饨綍涓嬶紝骞跺湪 Discuz! Q 绋嬪簭饨備欢 `app/Formatter/Formatter.php` 涓**38饩** 宸﹀彸鎵惧埌濡備笅浠g爜锛

```php codecopy-enabled
parent::confTopic($configurator);
```

鍦ㄥ叾鍚庢坊鍔犲涓嬩唬鐮侊細

```php codecopy-enabled
CustomerConfigurator::Customer($configurator);
```

6. 鍒犻櫎 Discuz! Q 绋嬪簭`storage/Formatter` 饨綍涓嬬殑鎵鏈夌紦瀛樷絺浠躲

### 姝ラ浜旓細涓婁紶闄勪欢鏂囦欢

* 灏 Discuz! X3.4 X3.5 饨綍 `uc_server/data/avatar` 涓殑鎵鏈夆絺浠朵笂浼犫緞 Discuz! Q 饨綍`storage/app/public/avatars`鏂囦欢澶逛笅锛屽鏋 avatars 涓嶅瓨鍦紝璇封緝饩忓垱寤鸿饨綍銆
* 灏 Discuz! X3.4 X3.5饨綍 `data/attachment/forum` 涓殑鎵鏈夆絺浠朵笂浼犫緞 Discuz! Q 饨綍`storage/app/public/attachments`锛屽鏋 `attachments` 涓嶅瓨鍦紝璇封緝饩忓垱寤鸿饨綍銆
* 灏 Discuz! X3.4 X3.5饨綍 `data/attachment/commom` 饨備欢澶逛笂浼犫緞 Discuz! Q 饨綍 `storage/app/public/attachments`銆
* 灏 Discuz! X3.4 X3.5饨綍 `static/image/smiley` 饨備欢澶逛腑鐨勨絺浠跺す涓婁紶饩 Discuz! Q 饨綍 `public/emoji`饨綍銆

### 姝ラ鍏細杞崲

1. 杞崲宸ュ叿鏀寔浠ヤ笅涓ょ鏂瑰紡杩涜杞寲锛屾偍鍙互鏍规嵁鑷繁鐨勫疄闄呴渶姹傝繘閫夋嫨锛

#### 饧閿浆鎹

鍦ㄥ懡浠も緩妯″紡涓嬶紝鍦ㄨ浆鎹㈢▼搴忔牴饨綍杩愨緩 `php discoa app:xtq` 鍛戒护锛屽皢瀹屾垚鎵鏈夋湰绋嬪簭瀹氫箟杩囩殑鏁版嵁鐨勮浆 鎹紝鍖呭惈锛氣饯鎴锋暟鎹佺増鍧楁暟鎹佷富棰樻暟鎹佸洖澶嶆暟鎹侀檮浠舵暟鎹佽〃鎯呮暟鎹

#### 閫夋嫨杞崲

WARNING

鑻ラ噰饨ら夋嫨杞崲锛屸饯鎴锋暟鎹拰鐗堝潡淇℃伅饧瀹氳鍦ㄤ富棰樸佸洖澶嶄俊鎭箣鍓嶈繘饩忔搷浣溿

鎮ㄥ彲浠モ緝鐢遍夋嫨瑕佽浆鎹㈢殑鏁版嵁銆傛偍鍙互浣库饯 `php discoa app:xtq --option` 鍛戒护锛屸緝鐢遍夋嫨鎮ㄩ渶瑕佽浆鎹㈢殑 鏁版嵁锛宍--option` 鏈変互涓嬪彲浣库饯鍙傛暟锛

* user : 饨ゆ埛淇℃伅杞崲銆
* category : 鐗堝潡淇℃伅杞崲銆
* thread 锛 涓婚淇℃伅杞崲銆
* post 锛 鍥炲淇℃伅杞崲銆
* attachment 锛 闄勪欢淇℃伅杞崲銆
* emoji 锛 琛ㄦ儏杞崲銆
* count 锛氫富棰樸佸笘饧︺佲饯鎴蜂俊鎭粺璁℃洿鏂般

TIP

* `php discoa app:xtq user` 琛ㄧず鍙浆鎹⑩饯鎴蜂俊鎭
* `php discoa app:xtq thread` 琛ㄧず鍙浆鎹富棰樹俊鎭

2. 杞崲宸ュ叿鍛戒护杩愯瀹屾瘯鍚庡嵆鍙浆鎹㈡垚鍔熴傝浆鍖栧伐鍏疯繕鏀寔浠ヤ笅鍔熻兘銆傛偍鍙互鏍规嵁鎮ㄥ緱鍏蜂綋闇姹傝繘琛屼娇鐢ㄣ

#### 杞寲宸ュ叿杈呭姪鍔熻兘

鎮ㄥ彲浠ヤ娇饨 `php discoa app:clean cleanDatabase --option` 鍛戒护娓呯悊 Discuz! Q 涓暟鎹〃鏁版嵁銆傛偍鍙互 閫夋嫨浠ヤ笅 `--option` 鍙傛暟锛

* user : 娓呯悊饨ゆ埛鏁版嵁銆
* userWallet : 娓呯悊饨ゆ埛閽卞寘鏁版嵁銆
* category : 娓呯悊鏉垮潡銆
* thread 锛 娓呯悊涓婚銆
* post 锛 娓呯悊鍥炲笘銆
* emoji: 娓呯悊杞崲鏉ョ殑琛ㄦ儏銆
* attachment 锛 娓呯悊闄勪欢鏁版嵁銆

WARNING

涓嶅~鍐 `option` 鍙傛暟鏃讹紝绋嬪簭灏嗘竻鐞嗕互涓婃墍鏈夋暟鎹

渚嬪锛

* `php discoa app:clean cleanDatabase` 琛ㄧず娓呯悊鎵鏈夋暟鎹
* `php discoa app:clean cleanDatabase user` 琛ㄧず娓呯悊饨ゆ埛鏁版嵁銆

### 姝ラ涓冿細Discuz! X3.4 X3.5 缃戝潃璺宠浆 Discuz! Q

WARNING

* 杞崲鎴愬姛鍚庯紝灏嗗鑷村師 Discuz! X3.4 X3.5 鐨勭綉鍧澶辨晥銆傛偍鍙氳繃浠ヤ笅姝ラ涓庨厤缃紝璁╁師 Discuz! X3.4 X3.5 鐨勭綉鍧琚闂椂锛屽彲椤哄埄鐨勫埄鐢 301 璺宠浆鑷冲搴旂殑 Discuz! Q 缃戝潃銆
* 姝ゆ楠ら潪蹇呴』锛屾偍鍙牴鎹偍鐨勫叿浣撻渶姹傚垽鏂槸鍚﹂厤缃

鐩墠鎻愪緵浠ヤ笅涓夌 Web 鏈嶅姟鐨勯厤缃柟寮忥紝鎮ㄥ彲鏍规嵁鎮ㄧ殑鍏蜂綋鎯呭喌杩涜閫夋嫨閰嶇疆锛

#### Nginx

1. 浣跨敤鏂囨湰缂栬緫鍣ㄦ墦寮鎮ㄧ殑 Nginx 閰嶇疆鏂囦欢锛岄氬父涓 `nginx.conf`鏂囦欢銆
2. 鍦ㄩ厤缃枃浠朵腑鏌ユ壘鍒 `server` 鍧楀苟澧炲姞濡備笅閰嶇疆锛

```nginx codecopy-enabled
# 甯栧瓙鍒楄〃
rewrite ^/forum-(\d+)-\d+\.html /category/$1? redirect;
if ($request_uri ~* ^/forum\.php\?mod=forumdisplay&fid=(\d+)) {
    set $fid $1;
    rewrite ^/ /category/$fid? redirect;
}

# 甯栧瓙璇︽儏
rewrite ^/thread-(\d+)-\d+-\d+\.html /thread/$1? redirect;
if ($request_uri ~* ^/forum\.php\?mod=viewthread&tid=(\d+)) {
    set $tid $1;
    rewrite ^/ /thread/$tid? redirect;
}

# 涓汉涓婚〉
rewrite ^/space-uid-(\d+)\.html /user/$1? redirect;
if ($request_uri ~* ^/home\.php\?mod=space&uid=(\d+)) {
    set $uid $1;
    rewrite ^/ /user/$uid? redirect;
}
```

3. 鎮ㄥ彲浠ヤ娇鐢ㄤ互涓 `nginx` 鍛戒护妫鏌ラ厤缃槸鍚︽纭細

```nginx codecopy-enabled
nginx -t
```

4. 閲嶅惎 Nginx 鏈嶅姟銆傛偍鍙互鍙傝冨懡浠わ細`nginx -s reload` 杩涜閲嶅惎銆

#### Apache

1. 浣跨敤鏂囨湰缂栬緫鍣ㄦ墦寮鎮ㄧ殑 `.htaccess` 閰嶇疆鏂囦欢骞跺鍔犲涓嬮厤缃細

```text codecopy-enabled
RewriteEngine On
# 甯栧瓙鍒楄〃
RewriteRule ^/?forum-(\d+)-\d+\.html /category/$1? [R,L]
RewriteCond %{QUERY_STRING} mod=forumdisplay&fid=(\d+)
RewriteRule ^/?forum\.php /category/%1? [R,L]

# 甯栧瓙璇︽儏
RewriteRule ^/?thread-(\d+)-\d+-\d+\.html /thread/$1? [R,L]
RewriteCond %{QUERY_STRING} mod=viewthread&tid=(\d+)
RewriteRule ^/?forum\.php /thread/%1? [R,L]

# 涓汉涓婚〉
RewriteRule ^/?space-uid-(\d+)\.html /user/$1? [R,L]
RewriteCond %{QUERY_STRING} mod=space&uid=(\d+)
RewriteRule ^/?home\.php /user/%1? [R,L]
```

2. 閲嶅惎 Apache 鏈嶅姟銆傛偍鍙互鍙傝冨懡浠わ細`service httpd restart` 杩涜閲嶅惎銆

#### IIS

1. 浣跨敤鏂囨湰缂栬緫鍣ㄦ墦寮鎮ㄧ殑 `web.config` 閰嶇疆鏂囦欢銆
2. 鍦ㄩ厤缃枃浠朵腑鐨 `rules` 涓鍔犲涓嬮厤缃細

```xml codecopy-enabled
<rule name="甯栧瓙鍒楄〃浼潤鎬" stopProcessing="true">
    <match url="^forum-(\d+)-\d+\.html" ignoreCase="false" />
    <action type="Redirect" url="/category/{R:1}" appendQueryString="false" redirectType="Found" />
</rule>
<rule name="甯栧瓙鍒楄〃" stopProcessing="true">
    <match url="^forum\.php" ignoreCase="false" />
    <conditions logicalGrouping="MatchAll">
        <add input="{QUERY_STRING}" pattern="mod=forumdisplay&fid=(\d+)" ignoreCase="false" />
    </conditions>
    <action type="Redirect" url="/category/{C:1}" appendQueryString="false" redirectType="Found" />
</rule>
<rule name="甯栧瓙璇︽儏浼潤鎬" stopProcessing="true">
    <match url="^thread-(\d+)-\d+-\d+\.html" ignoreCase="false" />
    <action type="Redirect" url="/thread/{R:1}" appendQueryString="false" redirectType="Found" />
</rule>
<rule name="甯栧瓙璇︽儏" stopProcessing="true">
    <match url="^forum\.php" ignoreCase="false" />
    <conditions logicalGrouping="MatchAll">
        <add input="{QUERY_STRING}" pattern="mod=viewthread&tid=(\d+)" ignoreCase="false" />
    </conditions>
    <action type="Redirect" url="/thread/{C:1}" appendQueryString="false" redirectType="Found" />
</rule>
<rule name="涓汉涓婚〉浼潤鎬" stopProcessing="true">
    <match url="^space-uid-(\d+)\.html" ignoreCase="false" />
    <action type="Redirect" url="/user/{R:1}" appendQueryString="false" redirectType="Found" />
</rule>
<rule name="涓汉涓婚〉" stopProcessing="true">
    <match url="^home\.php" ignoreCase="false" />
    <conditions logicalGrouping="MatchAll">
        <add input="{QUERY_STRING}" pattern="mod=space&uid=(\d+)" ignoreCase="false" />
    </conditions>
    <action type="Redirect" url="/user/{C:1}" appendQueryString="false" redirectType="Found" />
</rule>
```

3. 閲嶅惎 IIS 鏈嶅姟銆

### 鍏朵粬娉ㄦ剰浜嬮」

1. 鐩墠闄勪欢鍥剧墖涓嶆敮鎸佷竷鐗涗簯绛夌涓夋柟瀛樺偍銆
2. 鑻ヨ浆鎹㈣繃绋嬪嚭鐜板唴瀛樻孩鍑烘姤閿檂Fatal error: Allowed memory size of ...`鏃讹紝鍙皾璇曚慨鏀筦php.ini`閰嶇疆锛屽皢`memory_limit`閫傚綋璋冨ぇ骞堕噸鍚 PHP 鏈嶅姟銆
[/md]