プロジェクト

全般

プロフィール

Bug(バグ) #3250

Yuya Watanabe11年以上前に更新

h3. 概要

日記投稿時にアクティビティへの投稿が失敗するため日記投稿が行えない

日記を保存する際に SimpleXMLElement のインスタンスである $xml 変数から title と content を取得してきているが,それぞれ $xml と同じように SimpleXMLElement のインスタンスとなる.そのため,Diary オブジェクトの保存を行う際に発生する postSave() の時にアクティビティ投稿の処理が走るが,そのときに title に指定したものをテンプレートのプレースホルダに入れるのだがこれが文字列でないため更新に失敗し,全体として失敗した処理となって API は 500 を返す.

opWebAPIPlugin 側
<pre>
lib/api/opAPIDiary.class.php
51 public function insert(SimpleXMLElement $xml)
...
59 $diary = new Diary();
60 $diary->setTitle($xml->title);
61 $diary->setBody($xml->content);
62 $diary->setMember($member);
63 $diary->save();
</pre>

opDiaryPlugin 側 (142 行目)
<pre>
lib/model/doctrine/PluginDiary.class.php
132 public function postInsert($event)
133 {
134 if (Doctrine::getTable('SnsConfig')->get('op_diary_plugin_update_activity', false))
135 {
136 $body = '[Diary] '.$this->title;
137 $options = array(
138 'public_flag' => sfConfig::get('op_activity_is_open', false) && $this->is_open ? 0 : $this->public_flag,
139 'uri' => '@diary_show?id='.$this->id,
140 'source' => 'Diary',
141 'template' => 'diary',
142 'template_param' => array('%1%' => $this->title),
</pre>

h3. 再現手順

# 管理画面 > プラグイン設定 > opDiaryPlugin 「設定」 > アクティビティ更新設定 > 使用する
# 下記のようなファイルを作成(author の指定が id である点については #1911 を参照)
<pre>
$ cat diary.xml
<?xml version="1.0" encoding="UTF-8" ?>
<entry xmlns="http://www.w3.org/2005/Atom">
<title type="text">日記タイトル</title>
<content type="text">日記本文</content>
<author>
<id>1</id>
</author>
</entry>
</pre>
# 下記コマンドを実行する
<pre>
$ curl http://sns.example.com/api.php/feeds/diary -d "@diary.xml"
<?xml version="1.0" encoding="utf-8" ?>
<error code="500" message="Internal Server Error" />
</pre>

h3.
修正案

オブジェクトへ値を渡す際に明示的に string 側を渡す.下記のものはキャストを行なっているが, SimpleXMLObject を正しく文字列に変換できる方法が望ましい.

<pre>
lib/api/opAPIDiary.class.php
59 $diary = new Diary();
60 $diary->setTitle((string)$xml->title);
61 $diary->setBody((string)$xml->content);
62 $diary->setMember($member);
63 $diary->save();
</pre>

戻る