プロジェクト

全般

プロフィール

Bug(バグ) #3192

Yuya Watanabe11年以上前に更新

h3. 概要

コンバート時にプロフィールの公開範囲デフォルト設定が正しくコンバートされない 公開範囲デフォルト設定値が正しくコンバートされない.

h3. 原因

下記部分で c_profile のテーブルの public_flag_default をそのまま使用しているが,2 系では数値ではなく文字列で管理していたため,そのまま利用すると正しく格納されない.実際には 0 になる

<pre>
mysql> select public_flag_default from c_profile group by public_flag_default;
+---------------------+
| public_flag_default |
+---------------------+
| public |
| friend |
| private |
+---------------------+
3 rows in set (0.00 sec)
</pre>

テーブル定義.

<pre>
mysql> show create table profile\G
*************************** 1. row ***************************
Table: profile
Create Table: CREATE TABLE `profile` (
...
`default_public_flag` tinyint(4) NOT NULL DEFAULT '1' COMMENT 'Default of public flag',
...
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Saves input/select items for the member profile'
1 row in set (0.00 sec)
</pre>

実際に格納している部分.

data/upgrade/2/opUpgradeFrom2MemberProfileStrategy.class.php
<pre>
54 protected function importProfile($ids, $idStr)
55 {
56 $list = $this->conn->fetchAll('SELECT c_profile_id, name, is_required, public_flag_edit, public_flag_default, form_type, val_type, disp_regist, disp_config, disp_search, val_regexp, val_min, val_max, sort_order FROM c_profile WHER E c_profile_id IN ('.$idStr.') LIMIT 16', $ids);
...
62 $this->conn->execute('INSERT INTO profile (id, name, is_required, is_unique, is_edit_public_flag, default_public_flag, form_type, value_type, is_disp_regist, is_disp_config, is_disp_search, value_regexp, value_min, value_max, so rt_order, created_at, updated_at) VALUES (?, ?, ?, 0, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())', array(
63 $profile['c_profile_id'] , $profile['name'] , $profile['is_required'] , $profile['public_flag_edit'] ,
...
66 ));
67 }
68 }
</pre>

実際に格納される値は下記のような形になる.(cast関数参考URL https://dev.mysql.com/doc/refman/5.1/ja/cast-functions.html )

<pre>
mysql> SELECT CAST('public' AS UNSIGNED), CAST('private' AS UNSIGNED), CAST('friend' AS UNSIGNED);
+----------------------------+-----------------------------+----------------------------+
| CAST('public' AS UNSIGNED) | CAST('private' AS UNSIGNED) | CAST('friend' AS UNSIGNED) |
+----------------------------+-----------------------------+----------------------------+
| 0 | 0 | 0 |
+----------------------------+-----------------------------+----------------------------+
1 row in set, 3 warnings (0.00 sec)
</pre>

h3. 修正案

下記設定に従って, opUpgradeFrom2MemberProfileStrategy.class.php の値を正しく設定する.

lib/model/doctrine/ProfileTable.class.php
<pre>
13 const PUBLIC_FLAG_SNS = 1;
14 const PUBLIC_FLAG_FRIEND = 2;
15 const PUBLIC_FLAG_PRIVATE = 3;
16 const PUBLIC_FLAG_WEB = 4;
17
18 protected $publicFlags = array(
19 self::PUBLIC_FLAG_WEB => 'All Users on the Web',
20 self::PUBLIC_FLAG_SNS => 'All Members',
21 self::PUBLIC_FLAG_FRIEND => '%my_friend%',
22 self::PUBLIC_FLAG_PRIVATE => 'Private',
23 );
</pre>

h3. 確認環境

OpenPNE 3.6.5
(OpenPNE 3.8 は 2 系からのアップグレードに対応していない)

戻る