1. NC1.xから2.4.0.xへの移行

投稿日時: 2016/11/14 牟田口
こんにちは。牟田口です。
NC1.xから2.4.0.xへの移行をする機会があったので、
メモを残しておきます。
 

--- 環境

 
windows8.1
XAMPPlite 1.6.2
 

--- NCMigration1.0.3を使う

 
Get NCMigration1.0.3 for Windows
 

--- 準備NC1

 
・NC1.xは NetCommons1.1.4 にする
・サイト閉鎖中にする
 

--- 準備NC2

 
・NetCommons2.4.0.0.zipを用意する
・NetCommons2.4.0.0を同じサーバの別ディレクトリにインストール
・サイト閉鎖中にする
 

--- 準備NCMigration

 
・NCMigration1.0.3を同じサーバの別ディレクトリに設置
 

--- サイト構成

 
NC1         ⇒ http://localhost/
NC2         ⇒ http://localhost/nc2/
NCMigration ⇒ http://localhost/NCMigration/
 

--- データ移行

 
http://localhost/NCMigration/
・「同意する>>」押下
 
http://localhost/NCMigration/index.php?action=entry
 
NetCommons1.1ルートディレクトリ:C:/Projects/xampp_lite/htdocs
NetCommons1.1管理者ログインID:(NC1の管理者ID)
NetCommons1.1管理者パスワード:(NC1のパスワード)
 
NetCommons2.4ルートディレクトリ:C:/Projects/xampp_lite/htdocs/nc2
NetCommons1.1管理者ログインID:(NC2の管理者ID)
NetCommons1.1管理者パスワード:(NC2のパスワード)
 
「設定内容の確認>>」押下
 
http://localhost/NCMigration/index.php
全てOKなら
「データ移行開始>>」押下
 

--- エラー1

 
「データ移行開始>>」押下後、下記URLになって白画面のまま動かない。
http://localhost/NCMigration/index.php?action=result
 

--- 対応1

 
・NCMigration1.0.3
 \NCMigration1.0.3\templates_c\ にsmartyの古いファイルが残っていて、マイグレーション実行できなかった。
 ⇒ 古いファイルを消せば解消した。
 

--- エラー2

 
データ移行中に下記エラーで止まる。
 
INSERT INTO netcommons2_pages_users_link(`room_id`,`user_id`,`role_authority_id`,`createroom_flag`,`insert_time`,`insert_site_id`,`insert_user_id`,`insert_user_name`,`update_time`,`update_site_id`,`update_user_id`,`update_user_name`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?);:Array ( [room_id] => 9615 [user_id] => 6d2ec6f4f918347aef5cfb189bfedcd8d85ff44d [role_authority_id] => 4 [createroom_flag] => 0 [insert_time] => 20150327233503 [insert_site_id] => 0621068e454f23fc44c714e8eaef6f27f41b2662 [insert_user_id] => 6f08a38bcb67340f22bb7122d5e4ebdbe8c4c58d [insert_user_name] => XX5200 [update_time] => 20150327233503 [update_site_id] => 0621068e454f23fc44c714e8eaef6f27f41b2662 [update_user_id] => 6f08a38bcb67340f22bb7122d5e4ebdbe8c4c58d [update_user_name] => HA5217 ) :Duplicate entry '9615-6d2ec6f4f918347aef5cfb189bfedcd8d85ff44d' for key 1:C:\projects\xampp_lite\htdocs\NCMigration\model\utility.php:393
 

--- 対応2

 
NC2のテーブル「netcommons2_pages_users_link」で本来重複しないはずのデータが重複していた。
エラーメッセージ「Duplicate entry '9615-6d2ec6f4f918347aef5cfb189bfedcd8d85ff44d' for key 1」
 
移行元のNC1テーブル「nc1_rooms_members_link」を確認した処、ルーム参加データに重複があったため、
重複データを削除した処、解消した。
 

--- エラー3

 
移行が完了したけど、日本語が文字化けしていた。
 

--- 対応3

 
本来、MYSQL側の文字コード設定を EUC になっていれば文字化けしない。
 
しかし、手元の古いxamppのmysqlに設定が反映されないため、
暫定対応で、NC1のDB接続は、SET NAMES 'ujis' を強制的に行うようにした。
 
\NCMigration\model\database.php
 
/**
 * NC1データベースコネクションオブジェクト設定
 *
 * @param string $dsn データソース名称(dbType://user:password@host/dbName?new)
 * @return void
 * @access public
 */
function setNC1ADOConnection($dsn)
{
	$dsn = $this->addDSNNew($dsn);
	$this->nc1ADOConnection = NewADOConnection($dsn);
	if (!empty($this->nc1ADOConnection)) {

		// 追記箇所
		$adoConnection = $this->nc1ADOConnection;
		if (strpos($adoConnection->dataProvider, "mysql") === 0) {
			$serverInfo = $adoConnection->ServerInfo();
			if (floatval($serverInfo["version"]) >= 4.01) {
				$adoConnection->Execute("SET NAMES 'ujis';");
			}
		}

		$this->nc1ADOConnection->SetFetchMode(ADODB_FETCH_ASSOC);
	}
}
 
これで文字化けは解消した。

2. Re: NC1.xから2.4.0.xへの移行

投稿日時: 2016/11/14 牟田口
>> 1

--- エラー4

 
移行が完了したけど、﨑(たちさき)、髙(はしごだか)が文字化ける。
 

--- 対応4

 
▼ PHPで「EUC-JP」から「UTF-8」への文字コード変換
 
▼ EUC-JPからUTF8への変換の際にCP51932を使う - a long log
 
mb_convert_encodingで「EUC-JP」から「UTF-8」に文字変換時に文字化けしていた。
 
\NCMigration\model\utility.php
 
/**
* EUCからUTF-8へ文字コードを変換
*
* @param string $str 変換対象文字列
* @return string 変換後文字列
* @access public
*/
function &convertEncoding($str)
{
if (!function_exists("mb_convert_encoding")) {
require_once ROOT_PATH . 'library' . DIRECTORY_SEPARATOR. 'jcode_1.35a' . DIRECTORY_SEPARATOR. 'jcode_wrapper.php';
$str = jcode_convert_encoding($str, NC2_ENCODING, NC1_ENCODING);
} else {
//$str = mb_convert_encoding($str, NC2_ENCODING, NC1_ENCODING);
$str = mb_convert_encoding(mb_convert_encoding($str, "CP51932", NC1_ENCODING), NC2_ENCODING, "CP51932");
}

return $str;
}
 
 
ネット上の記事を参考に上記に修正して、再度移行を実行した処、文字化けが解消した。