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
139 changes: 103 additions & 36 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI for Maker42
name: CI for Maker44
on:
push:
branches:
Expand All @@ -14,22 +14,23 @@ on:
paths:
- '**'
- '!*.md'

# GITHUB_TOKEN は最小権限(読み取りのみ)にする
permissions:
contents: read

jobs:
run-on-linux:
name: Run on Linux
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
eccube_version: [ '4.2', '4.3' ]
php: [ '7.4', '8.0', '8.1', '8.2', '8.3']
db: [ 'mysql', 'mysql8', 'pgsql' ]
plugin_code: [ 'Maker42' ]
eccube_version: [ '4.4' ]
php: [ '8.2', '8.3', '8.4', '8.5' ]
db: [ 'mysql8', 'pgsql' ]
plugin_code: [ 'Maker44' ]
include:
- db: mysql
database_url: mysql://root:password@127.0.0.1:3306/eccube_db
database_server_version: 5.7
database_charset: utf8mb4
- db: mysql8
database_url: mysql://root:password@127.0.0.1:3308/eccube_db
database_server_version: 8
Expand All @@ -38,29 +39,11 @@ jobs:
database_url: postgres://postgres:password@127.0.0.1:5432/eccube_db
database_server_version: 14
database_charset: utf8
exclude:
- eccube_version: 4.2
php: 8.2
- eccube_version: 4.2
php: 8.3
- eccube_version: 4.3
php: 7.4
- eccube_version: 4.3
php: 8.0
services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: ${{ matrix.dbname }}
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
mysql8:
image: mysql:8
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: ${{ matrix.dbname }}
ports:
- 3308:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
Expand All @@ -69,7 +52,6 @@ jobs:
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: ${{ matrix.dbname }}
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
Expand All @@ -81,38 +63,42 @@ jobs:
- 1025:1025
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Setup PHP
uses: nanasess/setup-php@master
with:
php-version: ${{ matrix.php }}

- name: Archive Plugin
env:
PLUGIN_CODE: ${{ matrix.plugin_code }}
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 }}
path: 'ec-cube'
persist-credentials: false

- 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-
- 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 が入っている。本プラグイン/本体テストは redis 未使用のため無視する。
run: composer install --no-interaction -o --apcu-autoloader --ignore-platform-req=ext-redis

- name: Setup EC-CUBE
env:
Expand All @@ -137,8 +123,8 @@ jobs:
working-directory: 'ec-cube'
run: |
bin/console eccube:plugin:install --code=${PLUGIN_CODE} --path=${GITHUB_WORKSPACE}/${PLUGIN_CODE}.tar.gz
bin/console cache:clear --no-warmup
bin/console eccube:plugin:enable --code=${PLUGIN_CODE}
bin/console cache:clear --no-warmup
- name: Run PHPUnit
env:
APP_ENV: 'test'
Expand All @@ -149,7 +135,11 @@ jobs:
PLUGIN_CODE: ${{ matrix.plugin_code }}
working-directory: 'ec-cube'
run: |
# 有効化したプラグインのルーティングはコンテナのコンパイル時に確定する。
# 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
Expand All @@ -173,3 +163,80 @@ jobs:
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
# 静的解析は DB 種別に依存しないため、SQLite 1 構成で一度だけ実行する。
# (php-cs-fixer / rector は DB 不要だが、phpstan は objectManagerLoader が
# カーネルを起動し EccubeExtension が dtb_plugin を読むため本体+DBが必要)
env:
PLUGIN_CODE: Maker44
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
with:
persist-credentials: false

- 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'
persist-credentials: false

- 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
# プラグイン有効化時に DeviceType 等のマスタデータを参照するため fixtures を投入する
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
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ jobs:
run: |
rm -rf $GITHUB_WORKSPACE/doc
rm -rf $GITHUB_WORKSPACE/.github
rm -rf $GITHUB_WORKSPACE/Tests
# 開発・テスト用ファイルは配布パッケージに含めない
rm -f $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
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
composer.phar
/vendor/

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

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

# Playwright MCP の一時生成物
/.playwright-mcp/
84 changes: 27 additions & 57 deletions Controller/MakerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,38 @@
* file that was distributed with this source code.
*/

namespace Plugin\Maker42\Controller;
namespace Plugin\Maker44\Controller;

use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
use Eccube\Controller\AbstractController;
use Plugin\Maker42\Entity\Maker;
use Plugin\Maker42\Form\Type\MakerType;
use Plugin\Maker42\Repository\MakerRepository;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Plugin\Maker44\Entity\Maker;
use Plugin\Maker44\Form\Type\MakerType;
use Plugin\Maker44\Repository\MakerRepository;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Bridge\Twig\Attribute\Template;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

/**
* Class MakerController.
*/
class MakerController extends AbstractController
{
/**
* @var MakerRepository
*/
protected $makerRepository;

/**
* MakerController constructor.
*
* @param MakerRepository $makerRepository
*/
public function __construct(MakerRepository $makerRepository)
{
$this->makerRepository = $makerRepository;
public function __construct(
protected MakerRepository $makerRepository,
) {
}

/**
* List, add, edit maker.
*
* @param Request $request
*
* @return array|\Symfony\Component\HttpFoundation\RedirectResponse
*
* @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
* @throws \Doctrine\ORM\OptimisticLockException
*
* @Route("/%eccube_admin_route%/maker", name="maker_admin_index")
* @Template("@Maker42/admin/maker.twig")
* @return array<string, mixed>|RedirectResponse
*/
public function index(Request $request)
#[Route('/%eccube_admin_route%/maker', name: 'maker_admin_index')]
#[Template('@Maker44/admin/maker.twig')]
public function index(Request $request): array|RedirectResponse
{
$Maker = new Maker();
$Makers = $this->makerRepository->findBy([], ['sort_no' => 'DESC']);
Expand Down Expand Up @@ -120,19 +106,9 @@ public function index(Request $request)

/**
* Delete Maker.
*
* @param Request $request
* @param Maker $Maker
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*
* @Route(
* "/%eccube_admin_route%/maker/{id}/delete",
* name="maker_admin_delete", requirements={"id":"\d+"},
* methods={"DELETE"}
* )
*/
public function delete(Request $request, Maker $Maker)
#[Route('/%eccube_admin_route%/maker/{id}/delete', name: 'maker_admin_delete', requirements: ['id' => '\d+'], methods: ['DELETE'])]
public function delete(#[MapEntity(id: 'id')] Maker $Maker): RedirectResponse
{
$this->isTokenValid();

Expand All @@ -142,8 +118,10 @@ public function delete(Request $request, Maker $Maker)
$this->addSuccess('maker.admin.delete.complete', 'admin');

log_info('メーカー削除完了', ['Maker id' => $Maker->getId()]);
} catch (\Exception $e) {
log_info('メーカー削除エラー', ['Maker id' => $Maker->getId(), $e]);
} catch (ForeignKeyConstraintViolationException $e) {
// 商品から参照されている場合のみ外部キー制約エラーとして扱う。
// それ以外の例外(DB 障害等)は握り潰さず伝播させる。
log_warning('メーカー削除エラー: 外部キー制約により削除できません', ['Maker id' => $Maker->getId(), 'exception' => $e]);

$message = trans('admin.common.delete_error_foreign_key', ['%name%' => $Maker->getName()]);
$this->addError($message, 'admin');
Expand All @@ -154,25 +132,17 @@ public function delete(Request $request, Maker $Maker)

/**
* Move sort no with ajax.
*
* @param Request $request
*
* @return Response
*
* @throws \Exception
*
* @Route(
* "/%eccube_admin_route%/maker/move_sort_no",
* name="maker_admin_move_sort_no",
* methods={"POST"}
* )
*/
public function moveSortNo(Request $request)
#[Route('/%eccube_admin_route%/maker/move_sort_no', name: 'maker_admin_move_sort_no', methods: ['POST'])]
public function moveSortNo(Request $request): Response
{
if ($request->isXmlHttpRequest() && $this->isTokenValid()) {
$sortNos = $request->request->all();
foreach ($sortNos as $makerId => $sortNo) {
$Maker = $this->makerRepository->find($makerId);
if (null === $Maker) {
continue;
}
$Maker->setSortNo($sortNo);
$this->entityManager->persist($Maker);
}
Expand Down
Loading
Loading