プロジェクト

全般

プロフィール

Bug(バグ) #3543

Youichi Kimura約10年前に更新

h3. 現象

MySQLの "Strict Mode":http://dev.mysql.com/doc/refman/5.1/ja/server-sql-mode.html が有効な環境でメンバーの新規登録を行う際に *プリセット* でかつ *日付* の項目を入力すると、次のようなエラーが発生する。

<pre>
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '' for column 'value_datetime' at row 1
</pre>

エラーが発生した SQL は下記の通り。

<pre>
12月 27 17:23:12 symfony [info] {Doctrine_Connection_Statement} execute : INSERT INTO member_profile (value, member_id, profile_id, value_datetime, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?) - (, 6, 2, , 2013-12-27 17:23:12, 2013-12-27 17:23:12)
</pre>

h3. 再現手順

# MySQL の my.cnf に下記の設定を加える
<pre>
[mysqld]
sql_mode=STRICT_ALL_TABLES
</pre>
# 管理画面から招待メールを送信し、メールに記載されたURLから新規登録ページ (/member/register) を開く
# プロフィール入力 (/member/registerInput) へ進む
# 必須項目と *誕生日* を入力する
# 「送信」をクリックすると500エラーが発生する

h3. 原因

@MemberProfile::preSave()@ 内の下記のコードが直接の原因となっている。

<pre><code class="php">
elseif ('date' === $this->getFormType() && isset($modified['value']) && $this->getProfile()->isPreset())
{
$this->_set('value_datetime', $this->_get('value'));
}
</code></pre>

@config/doctrine/schema.yml@ に @MemberProfile.value@ のデフォルト値が @""@ であると記述されているため、value に変更が加えられたか否かに係わらず @MemberProfile::preSave()@ 内で @isset($modified['value'])@ は常に true になる(UPDATE の場合を除く)。
すると @MemberProfile.value_datetime@ に空文字列がそのままセットされてしまい、前述の @Invalid datetime format@ エラーが発生してしまう。

なお、プリセットではない日付型のプロフィール項目については value_datetime は使用されない (参照: commit:b6445a0a) ためこの問題は発生しない。

h3. 修正内容

@MemberProfile::preSave()@ 内で @value_datetime@ に対するから文字列の代入が行われないように @$modified['value']@ のチェックを行う。

戻る