Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 106 additions & 25 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI for Databackup4
name: CI for Databackup44
on:
push:
branches:
Expand All @@ -17,35 +17,38 @@ on:
jobs:
run-on-linux:
name: Run on Linux
runs-on: ${{ matrix.operating-system }}
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
operating-system: [ ubuntu-18.04 ]
php: [ '7.3', '7.4' ]
db: [ 'mysql', 'pgsql' ]
eccube_version: [ '4.0', '4.1' ]
plugin_code: [ 'Databackup4' ]
eccube_version: [ '4.4' ]
php: [ '8.2', '8.3', '8.4', '8.5' ]
db: [ 'mysql8', 'pgsql' ]
plugin_code: [ 'Databackup44' ]
include:
- db: mysql
database_url: mysql://root:password@127.0.0.1:3306/eccube_db
database_server_version: 5.7
- db: mysql8
database_url: mysql://root:password@127.0.0.1:3308/eccube_db
database_server_version: 8
database_charset: utf8mb4
- db: pgsql
database_url: postgres://postgres:password@127.0.0.1:5432/eccube_db
database_server_version: 14
database_charset: utf8
services:
mysql:
image: mysql:5.7
mysql8:
image: mysql:8
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: ${{ matrix.dbname }}
ports:
- 3306:3306
- 3308:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
postgres:
image: postgres:14
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: ${{ matrix.dbname }}
Comment on lines +42 to +51

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

マトリクス変数 dbname が未定義です。

strategy.matrixinclude 内で dbname が定義されていないため、matrix.dbname は空として評価されてしまいます。これにより、データベースが正しく作成されずテストが失敗する原因となります。

database_url 内の指定に合わせて、固定値の eccube_db を指定してください。

🐛 修正案
       mysql8:
         image: mysql:8
         env:
           MYSQL_ROOT_PASSWORD: password
-          MYSQL_DATABASE: ${{ matrix.dbname }}
+          MYSQL_DATABASE: eccube_db
         ports:
           - 3308:3306
         options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
       postgres:
         image: postgres:14
         env:
           POSTGRES_USER: postgres
           POSTGRES_PASSWORD: password
-          POSTGRES_DB: ${{ matrix.dbname }}
+          POSTGRES_DB: eccube_db
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
MYSQL_DATABASE: ${{ matrix.dbname }}
ports:
- 3306:3306
- 3308:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
postgres:
image: postgres:14
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: ${{ matrix.dbname }}
MYSQL_DATABASE: eccube_db
ports:
- 3308:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
postgres:
image: postgres:14
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: eccube_db
🧰 Tools
🪛 actionlint (1.7.12)

[error] 42-42: property "dbname" is not defined in object type {database_charset: string; database_server_version: number; database_url: string; db: string; eccube_version: number; php: number; plugin_code: string}

(expression)


[error] 51-51: property "dbname" is not defined in object type {database_charset: string; database_server_version: number; database_url: string; db: string; eccube_version: number; php: number; plugin_code: string}

(expression)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/ci.yaml around lines 42 - 51, Update the MySQL and
PostgreSQL service database environment values in the CI workflow to use the
fixed database name eccube_db instead of the undefined matrix.dbname reference,
matching the database_url configuration.

Source: Linters/SAST tools

ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
Expand All @@ -56,9 +59,8 @@ jobs:
- 1080:1080
- 1025:1025
steps:
- run: sudo apt-get purge -y hhvm
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: nanasess/setup-php@master
Expand All @@ -71,7 +73,7 @@ jobs:
run: |
tar cvzf ${GITHUB_WORKSPACE}/${PLUGIN_CODE}.tar.gz ./*
- name: Checkout EC-CUBE
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
repository: 'EC-CUBE/ec-cube'
ref: ${{ matrix.eccube_version }}
Expand All @@ -80,28 +82,26 @@ jobs:
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v1
echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"
- uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- if: ${{ startsWith(matrix.eccube_version, '4.0') }}
working-directory: 'ec-cube'
run: sudo composer selfupdate --1

- name: Install to composer
working-directory: 'ec-cube'
run: composer install --no-interaction -o --apcu-autoloader
# Symfony 7.4 の symfony/cache が ext-redis <6.1 と衝突するが、ランナーには
# 古い php-redis(5.3.7) が入っている。本プラグイン/本体テストは redis 未使用のため無視する。
run: composer install --no-interaction -o --apcu-autoloader --ignore-platform-req=ext-redis

- name: Setup EC-CUBE
env:
APP_ENV: 'test'
APP_DEBUG: 0
DATABASE_URL: ${{ matrix.database_url }}
DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }}
DATABASE_CHARSET: ${{ matrix.database_charset }}
working-directory: 'ec-cube'
run: |
bin/console doctrine:database:create
Expand All @@ -113,28 +113,38 @@ jobs:
APP_DEBUG: 0
DATABASE_URL: ${{ matrix.database_url }}
DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }}
DATABASE_CHARSET: ${{ matrix.database_charset }}
PLUGIN_CODE: ${{ matrix.plugin_code }}
working-directory: 'ec-cube'
run: |
bin/console eccube:plugin:install --code=${PLUGIN_CODE} --path=${GITHUB_WORKSPACE}/${PLUGIN_CODE}.tar.gz
bin/console eccube:plugin:enable --code=${PLUGIN_CODE}
bin/console cache:clear --no-warmup
- name: Run PHPUnit
env:
APP_ENV: 'test'
APP_DEBUG: 0
DATABASE_URL: ${{ matrix.database_url }}
DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }}
DATABASE_CHARSET: ${{ matrix.database_charset }}
PLUGIN_CODE: ${{ matrix.plugin_code }}
working-directory: 'ec-cube'
run: |
bin/phpunit -c app/Plugin/${PLUGIN_CODE}/phpunit.xml.dist app/Plugin/${PLUGIN_CODE}/Tests
# 有効化したプラグインのルーティングはコンテナのコンパイル時に確定する。
# phpunit プロセスでの遅延コンパイルに任せると DB/タイミングで有効プラグイン一覧を
# 取りこぼし RouteNotFound になることがあるため、クリーンなプロセスで warmup して確定させる。
bin/console cache:clear --no-warmup
bin/console cache:warmup
./vendor/bin/phpunit -c app/Plugin/${PLUGIN_CODE}/phpunit.xml.dist app/Plugin/${PLUGIN_CODE}/Tests

- name: Disable Plugin
working-directory: 'ec-cube'
env:
APP_ENV: 'test'
APP_DEBUG: 0
DATABASE_URL: ${{ matrix.database_url }}
DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }}
DATABASE_CHARSET: ${{ matrix.database_charset }}
PLUGIN_CODE: ${{ matrix.plugin_code }}
run: bin/console eccube:plugin:disable --code=${PLUGIN_CODE}

Expand All @@ -144,6 +154,77 @@ jobs:
APP_DEBUG: 0
DATABASE_URL: ${{ matrix.database_url }}
DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }}
DATABASE_CHARSET: ${{ matrix.database_charset }}
PLUGIN_CODE: ${{ matrix.plugin_code }}
working-directory: 'ec-cube'
run: bin/console eccube:plugin:uninstall --code=${PLUGIN_CODE}

static-analysis:
name: Static Analysis
runs-on: ubuntu-24.04
env:
PLUGIN_CODE: Databackup44
APP_ENV: 'test'
APP_DEBUG: 0
DATABASE_URL: 'sqlite:///var/eccube.db'
DATABASE_SERVER_VERSION: 3
DATABASE_CHARSET: 'utf8'
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: nanasess/setup-php@master
with:
php-version: '8.5'

- name: Archive Plugin
run: |
tar cvzf ${GITHUB_WORKSPACE}/${PLUGIN_CODE}.tar.gz ./*
- name: Checkout EC-CUBE
uses: actions/checkout@v4
with:
repository: 'EC-CUBE/ec-cube'
ref: '4.4'
path: 'ec-cube'

- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"
- uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install to composer
working-directory: 'ec-cube'
run: composer install --no-interaction -o --apcu-autoloader --ignore-platform-req=ext-redis

- name: Setup EC-CUBE
working-directory: 'ec-cube'
run: |
bin/console doctrine:database:create
bin/console doctrine:schema:create
bin/console eccube:fixtures:load
- name: Setup Plugin
working-directory: 'ec-cube'
run: |
bin/console eccube:plugin:install --code=${PLUGIN_CODE} --path=${GITHUB_WORKSPACE}/${PLUGIN_CODE}.tar.gz
bin/console eccube:plugin:enable --code=${PLUGIN_CODE}
bin/console cache:clear --no-warmup

- name: Run php-cs-fixer
working-directory: 'ec-cube'
run: ./vendor/bin/php-cs-fixer fix --config=app/Plugin/${PLUGIN_CODE}/Resource/.php-cs-fixer.dist.php --dry-run --diff

- name: Run Rector
working-directory: 'ec-cube'
run: ./vendor/bin/rector process --config=app/Plugin/${PLUGIN_CODE}/Resource/rector.php --dry-run

- name: Run PHPStan
working-directory: 'ec-cube'
run: |
bin/console cache:clear --no-warmup
./vendor/bin/phpstan analyse -c app/Plugin/${PLUGIN_CODE}/phpstan.neon.dist --no-progress
10 changes: 6 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@

name: Packaging for EC-CUBE Plugin
on:
release:
types: [ published ]
jobs:
deploy:
name: Build
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Packaging
working-directory: ../
run: |
rm -rf $GITHUB_WORKSPACE/.github
rm -rf $GITHUB_WORKSPACE/Tests

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Testsは除外のままでよいと思いますが、何かパッケージにいれる理由がありますでしょうか。

# 開発・テスト用ファイルは配布パッケージに含めない
rm -rf $GITHUB_WORKSPACE/docker-compose*.yml $GITHUB_WORKSPACE/dockerbuild
rm -f $GITHUB_WORKSPACE/CLAUDE.md $GITHUB_WORKSPACE/phpstan.neon.dist
rm -f $GITHUB_WORKSPACE/Resource/rector.php "$GITHUB_WORKSPACE/Resource/.php-cs-fixer.dist.php"
find $GITHUB_WORKSPACE -name "dummy" -delete
find $GITHUB_WORKSPACE -name ".git*" -and ! -name ".gitkeep" -print0 | xargs -0 rm -rf
chmod -R o+w $GITHUB_WORKSPACE
Expand Down
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
composer.phar
/vendor/

# 本プラグインはライブラリ (type: eccube-plugin) のため composer.lock はコミットしない
# https://getcomposer.org/doc/02-libraries.md#lock-file
composer.lock

# 静的解析・整形ツールのキャッシュ
.php-cs-fixer.cache

# Playwright MCP の一時生成物
/.playwright-mcp/
42 changes: 42 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with this repository.

## このリポジトリについて

EC-CUBE 4 系の**データバックアッププラグイン**。管理画面から全テーブルを CSV ダンプし tar.gz でダウンロードする。

- 管理画面: `/%eccube_admin_route%/databackup44/config`(`Controller/Admin/Databackup4Controller.php`)
- サービス: `Service/Databackup4Service.php`(DBAL SchemaManager / CSV dump)

プラグインコードは `Databackup44`、Composer パッケージ名は `ec-cube/databackup44`。

### ブランチ運用

`4.2`/`4.3` = Databackup42(アノテーション / DBAL 2)。`4.4` = Databackup44(Attribute / DBAL 3 / PHP 8.2+)。非互換のため別ブランチ保守。

## 開発・テスト

本体に組み込んだ状態で動作する。`docker-compose.dev.yml` の entrypoint がインストール・有効化を行う。

```bash
export COMPOSE_FILE=docker-compose.yml:docker-compose.dev.yml
docker compose up -d --wait
```

### PHPUnit

```bash
docker compose exec ec-cube bash -lc \
"APP_ENV=test bin/console cache:clear --no-warmup && ./vendor/bin/phpunit -c app/Plugin/Databackup44/phpunit.xml.dist app/Plugin/Databackup44/Tests"
```

**注意**: 有効化後・PHPUnit 前に `APP_ENV=test` で cache:clear すること。

## 規約・移行メモ

- 開発ツール設定(`rector.php` / `.php-cs-fixer.dist.php`)は `Resource/` 配下に置く(ルート直下禁止)
- Docker は `APP_ENV=dev`(test だとセッションがモックでログイン不可)
- HTTP 開発時は `dockerbuild/dev-framework.yaml` で cookie SameSite を緩和
- プラグイン有効化後 `cache:clear` を 2 回
- DBAL 3: `createSchemaManager()` / `executeQuery()` / `fetchAllAssociative()` / `fetchNumeric()`
32 changes: 11 additions & 21 deletions Controller/Admin/Databackup4Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,39 @@
* file that was distributed with this source code.
*/

namespace Plugin\Databackup4\Controller\Admin;
namespace Plugin\Databackup44\Controller\Admin;

use Eccube\Controller\AbstractController;
use Plugin\Databackup4\Service\Databackup4Service;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Plugin\Databackup44\Service\Databackup4Service;
use Symfony\Bridge\Twig\Attribute\Template;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpKernel\Event\TerminateEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Attribute\Route;

class Databackup4Controller extends AbstractController
{
/**
* @var Databackup4Service
*/
protected $databackup4Service;

/**
* Databackup4Controller constructor.
*
* @param Databackup4Service $databackup4Service
*/
public function __construct(
Databackup4Service $databackup4Service
private readonly Databackup4Service $databackup4Service,
) {
$this->databackup4Service = $databackup4Service;
}

/**
* @Route("/%eccube_admin_route%/databackup4/config", name="databackup4_admin_config")
* @Template("@Databackup4/admin/index.twig")
* @return array<string, mixed>|BinaryFileResponse
*/
#[Route(path: '/%eccube_admin_route%/databackup44/config', name: 'databackup44_admin_config')]
#[Template('@Databackup44/admin/index.twig')]
public function index(Request $request, EventDispatcherInterface $eventDispatcher)
{
$form = $this->createFormBuilder([])->getForm();
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$backupBaseDir = $this->getParameter('plugin_data_realdir').'/Databackup4';
$backupBaseDir = $this->getParameter('plugin_data_realdir').'/Databackup44';
$backupDir = $backupBaseDir.'/'.date('YmdHis');

$fs = new Filesystem();
Expand All @@ -72,7 +62,7 @@ public function index(Request $request, EventDispatcherInterface $eventDispatche
$phar->compress(\Phar::GZ);

// 終了時に一時ディレクトリを削除.
$eventDispatcher->addListener(KernelEvents::TERMINATE, function (PostResponseEvent $event) use ($backupBaseDir, $fs) {
$eventDispatcher->addListener(KernelEvents::TERMINATE, function (TerminateEvent $event) use ($backupBaseDir, $fs) {
// UnitTest実行時はterminateイベント実行後にファイル出力が行われるため、ここでは削除しない
if (env('APP_ENV') === 'test') {
return;
Expand Down
Loading
Loading