Skip to content

定数定義に defined() ガードを追加し config.php からのオーバーライドを可能にする#1375

Open
nanasess wants to merge 1 commit intoEC-CUBE:masterfrom
nanasess:fix/defined-guard-constants
Open

定数定義に defined() ガードを追加し config.php からのオーバーライドを可能にする#1375
nanasess wants to merge 1 commit intoEC-CUBE:masterfrom
nanasess:fix/defined-guard-constants

Conversation

@nanasess
Copy link
Copy Markdown
Contributor

@nanasess nanasess commented Mar 25, 2026

Summary

mtb_constants.php(自動生成キャッシュ)および mtb_constants_init.php の全定数に defined() ガードを追加し、config.php やテスト用 bootstrap から定数をオーバーライド可能にする。

背景

EC-CUBE2 の定数は複数ファイルから定義されるが、defined() ガードの有無にばらつきがあった:

ファイル ガード
data/config/config.php ✅ あり
data/cache/mtb_constants.php ❌ なし
data/mtb_constants_init.php ❌ なし
html/define.php ❌ なし

config.phpAUTH_TYPE 等の mtb 定数をオーバーライドしたい場合や、テスト時に定数を差し替えたい場合に E_NOTICE が発生していた。

変更内容

ファイル 変更内容
data/class/db/SC_DB_MasterData.php getMasterDataAsDefine() でキャッシュ生成時に defined() ガード付き define 文を出力
data/mtb_constants_init.php 全約245定数に defined() ガード追加
html/define.php 2定数に defined() ガード追加

定数の優先順位(変更後)

最優先 → テスト用 define (テスト実行時)
       → data/config/config.php (ユーザーによるオーバーライド)
       → data/cache/mtb_constants.php (管理画面で設定した値)
       → data/mtb_constants_init.php (キャッシュ未生成時の初期値)
最低   → その他の define

Test plan

  • PHPUnit全テスト通過(MySQL & PostgreSQL)
  • E2Eテスト全テスト通過(MySQL & PostgreSQL)
  • 管理画面のパラメーター設定保存後、キャッシュが defined() ガード付きで再生成されること

🤖 Generated with Claude Code

Summary by CodeRabbit

リリースノート

  • バグ修正
    • 定数の重複定義エラーを修正しました。システムが複数回初期化される場合でも、既に定義された定数は上書きされなくなり、アプリケーションの安定性が向上しました。

mtb_constants.php(自動生成キャッシュ)および mtb_constants_init.php の
全定数に defined() ガードを追加。config.php やテスト用 bootstrap で
先に定義した定数が E_NOTICE なしで優先されるようになる。

- SC_DB_MasterData::getMasterDataAsDefine(): キャッシュ生成時に
  defined() ガード付きの define 文を出力するよう変更
- data/mtb_constants_init.php: 全約245定数にガード追加
- html/define.php: 2定数にガード追加(一貫性のため)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 80774754-0081-474a-b479-c35faa7fbeff

📥 Commits

Reviewing files that changed from the base of the PR and between 9a599f3 and f36854a.

📒 Files selected for processing (3)
  • data/class/db/SC_DB_MasterData.php
  • data/mtb_constants_init.php
  • html/define.php

📝 Walkthrough

ウォークスルー

PHP定数定義をガード形式に統一しました。複数ファイルの無条件なdefine()呼び出しをdefined() or define()パターンに変更し、キャッシュファイルが複数回読み込まれる際の再定義エラーを防止します。

変更内容

コホート / ファイル(s) 概要
定数定義のガード化
data/class/db/SC_DB_MasterData.php, data/mtb_constants_init.php, html/define.php
すべてのdefine()呼び出しをdefined('<キー>') or define('<キー>', <値>);パターンに変更。mtb_constants_init.phpでは245行すべての定数定義が条件付きに統一され、既に定義済みの定数は上書きされなくなります。

推定コード審査工数

🎯 2 (Simple) | ⏱️ ~10分

🐰✨ 定数たちが衣替え
ガード式で身を守り
二度と生まれ変わらぬよう
キャッシュの魔法も安心じゃ
ウサギが祝う改善かな 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PRタイトルは、定数定義にガードを追加し、config.phpからのオーバーライドを可能にするという変更の主要な目的を明確に要約している。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 25, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 54.39%. Comparing base (08f44be) to head (f36854a).
⚠️ Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
data/class/db/SC_DB_MasterData.php 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1375      +/-   ##
==========================================
- Coverage   54.42%   54.39%   -0.03%     
==========================================
  Files          84       84              
  Lines       10817    10822       +5     
==========================================
  Hits         5887     5887              
- Misses       4930     4935       +5     
Flag Coverage Δ
tests 54.39% <0.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant