Project

General

Profile

Backport(バックポート) #3178

三項演算子の二項目を省略した記述はPHP5.2環境で動作しない

Added by Yuma Sakata over 11 years ago. Updated about 11 years ago.

Status:
Fixed(完了)
Priority:
Normal(通常)
Target version:
Start date:
2012-07-20
Due date:
% Done:

100%


Description

概要

三項演算子の二項目を省略した記述はPHP5.2環境で動作しない

具体的には下記コード部分がこれに該当する.

lib/util/opActivityQueryBuilder.class.php

 72   public function includeFriends($target_member_id = null)
 73   {
 74     $this->include['friend'] = $target_member_id ?: $this->viewerId;
 75     return $this;
 76   }

apps/api/lib/helper/opJsonApiHelper.php

134     'name' => $community->getName(),
'category' => (string)$community->getCommunityCategory() ?: null,
\136     'community_url' => $communityUrl,

原因

三項演算子の二項目を省略した形で記述できるのは PHP 5.3 以降であるため、 PHP 5.2 環境では利用することができない.

参考URL: http://php.net/manual/ja/language.operators.comparison.php

修正内容

diff --git a/apps/api/lib/helper/opJsonApiHelper.php b/apps/api/lib/helper/opJsonApiHelper.php
index e5fd560..c460778 100644
--- a/apps/api/lib/helper/opJsonApiHelper.php
+++ b/apps/api/lib/helper/opJsonApiHelper.php
@@ -139,7 +139,7 @@ function op_api_community($community)
   return array(
     'id' => $community->getId(),
     'name' => $community->getName(),
-    'category' => (string)$community->getCommunityCategory() ?: null,
+    'category' => $community->getCommunityCategory() ? $community->getCommunityCategory()->getName() : null,
     'community_url' => $communityUrl,
     'community_image_url' => $communityImage,
     'joining' => $communityMember ? !$communityMember->getIsPre() : false,
diff --git a/lib/util/opActivityQueryBuilder.class.php b/lib/util/opActivityQueryBuilder.class.php
index 6841e90..661dec5 100644
--- a/lib/util/opActivityQueryBuilder.class.php
+++ b/lib/util/opActivityQueryBuilder.class.php
@@ -71,7 +71,7 @@ class opActivityQueryBuilder

   public function includeFriends($target_member_id = null)
   {
-    $this->include['friend'] = $target_member_id ?: $this->viewerId;
+    $this->include['friend'] = $target_member_id ? $target_member_id : $this->viewerId;
     return $this;
   }

元本文

三項演算子の省略形がPHP5.2で動作しないので、動作するように変更する。
厳密にはバグではないが、これだけの理由でPHP5.3縛りにしてしまうのはもったいない。安定版中に対応する。
すなわち、OpenPNE3.8の対象バージョンはPHP5.2以上である、ということを定義する。

例 {OpenPNE3.8.0}/apps/api/lib/helper
opJsonApiHelper.php
パラメータ省略は、5.3から可能
135行目
修正前
'category' => (string)$community->getCommunityCategory() ?: null,
修正後
'category' => (string)$community->getCommunityCategory() ? $community->getCommunityCategory() : null,


Related issues

Related to OpenPNE 3 - Bug(バグ) #3121: 三項演算子の二項目を省略した記述はPHP5.2環境で動作しない Won't fix(対応せず) 2012-07-20

Associated revisions

Revision c8a4f449 (diff)
Added by Youichi Kimura over 11 years ago

fix compatibility with PHP 5.2.x (fixes #3178, BP from #3121)

Revision 8e28d934 (diff)
Added by Youichi Kimura about 11 years ago

fix coding style issue (refs #3178, BP from #3121)

(cherry picked from commit 28c087935d5eb411ded3b902333c30608ef2a845)

History

#1 Updated by Youichi Kimura over 11 years ago

  • Status changed from New(新規) to Pending Review(レビュー待ち)
  • % Done changed from 0 to 50

更新履歴 c8a4f4499fe0066e64b8b72a04825690d5730e89 で適用されました。

#2 Updated by Yuma Sakata over 11 years ago

  • Description updated (diff)

#3 Updated by Yuma Sakata over 11 years ago

  • Description updated (diff)

#4 Updated by Yuma Sakata over 11 years ago

  • Description updated (diff)

#5 Updated by Yuma Sakata over 11 years ago

・json_encodeのPRETTY_PRINT

については #3028 にて既に修正されているため、

・三項演算子の省略形

のみを当チケットでの修正対象とします。

#6 Updated by Yuma Sakata about 11 years ago

  • Status changed from Pending Review(レビュー待ち) to Rejected(差し戻し)
  • Assignee set to Youichi Kimura

テスト実施しましたが、修正が必要な点がありましたので確認お願いします。

コミュニティカテゴリ未設定の場合、API値の確認

  • 試験手順
    1. カテゴリを指定しないで、コミュニティを作成する
    2. SNSトップページで、ページのソースを表示する
    3. 手順2 のソースよりAPIキーを取得する
    (例:var openpne = {"apiKey":"ここにAPIキーが表示されます")
    4. 次のURLのAPIキーの部分に手順3で取得したAPIキーを入力する
    (例:http://sns.example.com/api.php/community/search.json?apiKey=<APIキー>)
    5. API の category の値を確認する
  • 試験結果
    "category":"" と表示される
  • 修正方針
    "category":null と表示されるように修正お願いします。

#7 Updated by Yuya Watanabe about 11 years ago

  • Subject changed from PHP5.2環境で動作するようにする to 三項演算子の二項目を省略した記述はPHP5.2環境で動作しない
  • Description updated (diff)

#8 Updated by Yuya Watanabe about 11 years ago

差し戻し内容

コーディング規約違反. http://www.openpne.jp/coding-standards-ja/

関数およびメソッド:return 文の直前には可読性向上のために空行を入れるべきです
変数:変数名に含めることができるのは英数字のみです。アンダースコアを使用してはいけません。

lib/util/opActivityQueryBuilder.class.php

 72   public function includeFriends($target_member_id = null)
 73   {
 74     $this->include['friend'] = $target_member_id ? $target_member_id : $this->viewerId;
 75     return $this;
 76   }

#9 Updated by Youichi Kimura about 11 years ago

  • Status changed from Rejected(差し戻し) to Accepted(着手)
  • % Done changed from 50 to 0

#10 Updated by Youichi Kimura about 11 years ago

  • Status changed from Accepted(着手) to Pending Review(レビュー待ち)
  • % Done changed from 0 to 50

https://redmine.openpne.jp/issues/3121#note-11 と同様にコーディング規約違反の箇所を修正しました。

#11 Updated by Yuya Watanabe about 11 years ago

  • Status changed from Pending Review(レビュー待ち) to Pending Testing(テスト待ち)
  • % Done changed from 50 to 70

#12 Updated by Yuma Sakata about 11 years ago

  • Status changed from Pending Testing(テスト待ち) to Fixed(完了)
  • % Done changed from 70 to 100

テストOKです。
note-6 指摘は本チケットで扱う問題でないので、別チケットで対応します。

Also available in: Atom PDF