プロジェクト

全般

プロフィール

Bug(バグ) #3250

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

Yuya Watanabe11年以上前に追加. 11年以上前に更新.

ステータス:
New(新規)
優先度:
Normal(通常)
担当者:
-
対象バージョン:
-
開始日:
2012-11-07
期日:
進捗率:

0%

3.6 で発生するか:
Unknown (未調査)
[QA]バグ通知済:
いいえ
3.8 で発生するか:
Unknown (未調査)

説明

概要

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

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

opWebAPIPlugin 側

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();

opDiaryPlugin 側 (142 行目)

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),

再現手順

  1. 管理画面 > プラグイン設定 > opDiaryPlugin 「設定」 > アクティビティ更新設定 > 使用する
  2. 下記のようなファイルを作成(author の指定が id である点については #1911 を参照)
    $ 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>
    
  3. 下記コマンドを実行する
    $ 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" />
    

修正案

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

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();

履歴

#1 Yuya Watanabe11年以上前に更新

  • 説明 を更新 (diff)

他の形式にエクスポート: Atom PDF