Skip to content

fix #4436 custom_entries Web API の page パラメータが機能しない問題を修正 - #4521

Merged
ryuring merged 1 commit into
5.4.xfrom
fix/custom-entries-api-page-param
Sep 3, 2026
Merged

fix #4436 custom_entries Web API の page パラメータが機能しない問題を修正#4521
ryuring merged 1 commit into
5.4.xfrom
fix/custom-entries-api-page-param

Conversation

@ryuring

@ryuring ryuring commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

概要

公開 Web API GET /baser/api/bc-custom-content/custom_entries.jsonpage クエリパラメータを付けても2ページ目以降が取得できない問題(#4436)を修正しました。

原因

CustomEntriesService::getIndex()page の処理が実装されておらず、limit のみが適用されていました。そのため page を変えても常に先頭から limit 件が返っていました。

同プラグインの CustomContentsService::getIndex() には page 対応があり、ドキュメント にも page が使える旨の記載があるため、実装漏れと判断しました。

変更内容

CustomContentsService::getIndex() と同じ方式に揃えました。

if (!empty($options['limit'])) {
    if (!empty($options['page'])) {
        $query->page($options['page'], $options['limit']);
    } else {
        $query->limit($options['limit']);
    }
}

unset($options['order'], $options['direction'], $options['limit'], $options['page']);

unset()page を追加している理由

createIndexConditions() は、既知のキーを取り除いた残りのキーをカスタムフィールド名として扱う実装になっています。order / direction / limit と同様に page も除外しておかないと、page という名前のカスタムフィールドが定義されている環境で意図しない絞り込みが発生します。

limit がない場合に page を無視する理由

CakePHP の Query::page()limit 未指定時に 25 件を暗黙で適用します。

$limit = $this->clause('limit');
if ($limit === null) {
    $limit = 25;
    $this->limit($limit);
}

?page=2 のみを指定した既存の呼び出しが、これまでの「全件返却」から「25件返却」へ静かに変わってしまうため、CustomContentsService と同じく limit 指定時のみ page を適用する挙動としています。この点はテストでも固定しています。

テスト

CustomEntriesServiceTest::test_getIndex() に検証を追加しました。

//pageパラメータを入れる
$params = ['limit' => 2, 'order' => 'id', 'direction' => 'asc'];
$page1 = $this->CustomEntriesService->getIndex($params + ['page' => 1])->all()->toArray();
$page2 = $this->CustomEntriesService->getIndex($params + ['page' => 2])->all()->toArray();
//全3件を2件ずつに分割して取得できる
$this->assertCount(2, $page1);
$this->assertCount(1, $page2);
//2ページ目には1ページ目と異なるデータが返る
$this->assertNotContains($page2[0]->id, [$page1[0]->id, $page1[1]->id]);

//limitがない場合、pageパラメータは無視する
$result = $this->CustomEntriesService->getIndex(['page' => 2])->all();
$this->assertCount(3, $result);

修正を戻した状態でこのテストが失敗することを確認しています(2ページ目に1ページ目と同じ2件が返る)。

Failed asserting that actual size 2 matches expected size 1.

実行結果

対象 結果
CustomEntriesServiceTest OK (31 tests, 97 assertions)
bc-custom-content の API テスト OK (6 tests, 27 assertions)
bc-custom-content 全体 OK (303 tests, 969 assertions)

※ Incomplete は既存のスキップです。

🤖 Generated with Claude Code


Generated by Claude Code

公開 Web API GET /baser/api/bc-custom-content/custom_entries.json に page
クエリパラメータを付けても、常に先頭から limit 件が返り、2ページ目以降の
データが取得できなかった。

CustomEntriesService::getIndex() に page の処理が実装されておらず、limit の
みが適用されていたことが原因。同プラグインの CustomContentsService::getIndex()
には page 対応があり、ドキュメントにも page が使える旨の記載があるため、
実装漏れと判断した。

CustomContentsService::getIndex() と同じ方式で、limit が指定されている場合に
page を適用するようにした。あわせて、条件生成へ渡す前に page を除外している。
createIndexConditions() は残ったキーをカスタムフィールド名として扱うため、
limit や order と同様に除外しておく必要がある。

なお limit の指定がない場合に page を無視する挙動は、CakePHP の Query::page()
が limit 未指定時に 25 件を暗黙で適用してしまうためで、CustomContentsService
と揃えている。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 2, 2026 23:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

既存サービスの実装方針に揃えた最小限の変更で、回帰を防ぐテスト追加も含まれているため。

Pull request overview

公開 Web API(GET /baser/api/bc-custom-content/custom_entries.json)で page クエリパラメータが limit と組み合わせても反映されず、常に先頭から同じ件数が返る問題(#4436)を修正し、既存の CustomContentsService::getIndex() と同様のページング挙動に統一するPRです。

Changes:

  • CustomEntriesService::getIndex()page + limit 指定時のページング(Query::page())を追加
  • createIndexConditions() 側で page が誤って検索条件扱いされないよう、unset() 対象に page を追加
  • CustomEntriesServiceTest::test_getIndex() にページングの期待値(2ページ目が取得できること/limit なしなら page を無視すること)を追加
File summaries
File Description
plugins/bc-custom-content/src/Service/CustomEntriesService.php limit 指定時に限り page を適用してページングできるようにし、page を条件生成から除外
plugins/bc-custom-content/tests/TestCase/Service/CustomEntriesServiceTest.php page が効いてページ分割できること、limit なしでは page を無視することをテストで固定
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@ryuring
ryuring merged commit a26c24b into 5.4.x Sep 3, 2026
13 checks passed
@ryuring
ryuring deleted the fix/custom-entries-api-page-param branch September 3, 2026 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants