Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DBの文字コードをutf8mb4に対応 #4796

Merged
merged 7 commits into from
Jun 9, 2022
Merged
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
5 changes: 4 additions & 1 deletion .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ DATABASE_URL=sqlite:///var/eccube.db

# The version of your database engine
DATABASE_SERVER_VERSION=3

# The charset of your database engine
DATABASE_CHARSET=utf8
###< doctrine/doctrine-bundle ###

###> symfony/mailer ###
Expand Down Expand Up @@ -51,4 +54,4 @@ MAILER_DSN=null://null
#ECCUBE_2FA_COOKIE_NAME=eccube_2fa
#ECCUBE_2FA_EXPIRE=14

###< APPLICATION CONFIG ###
###< APPLICATION CONFIG ###
7 changes: 7 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ jobs:
- db: mysql
database_url: mysql://root:[email protected]:3306/eccube_db
database_server_version: 5
database_charset: utf8mb4
- db: pgsql
database_url: postgres://postgres:[email protected]:5432/eccube_db
database_server_version: 14
database_charset: utf8
- db: sqlite3
database_url: sqlite:///var/eccube.db
database_server_version: 3
database_charset: utf8

services:
mysql:
Expand Down Expand Up @@ -79,6 +82,7 @@ jobs:
APP_ENV: 'test'
DATABASE_URL: ${{ matrix.database_url }}
DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }}
DATABASE_CHARSET: ${{ matrix.database_charset }}
run: |
bin/console doctrine:database:create
bin/console doctrine:schema:create
Expand All @@ -89,13 +93,15 @@ jobs:
APP_ENV: 'test'
DATABASE_URL: ${{ matrix.database_url }}
DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }}
DATABASE_CHARSET: ${{ matrix.database_charset }}
MAILER_URL: 'smtp://127.0.0.11025'
run: bin/phpunit --exclude-group cache-clear,cache-clear-install,update-schema-doctrine,plugin-service
- name: PHPUnit
env:
APP_ENV: 'test'
DATABASE_URL: ${{ matrix.database_url }}
DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }}
DATABASE_CHARSET: ${{ matrix.database_charset }}
MAILER_URL: 'smtp://127.0.0.11025'
run: |
bin/phpunit --group cache-clear
Expand All @@ -118,6 +124,7 @@ jobs:
APP_ENV: 'test'
DATABASE_URL: ${{ matrix.database_url }}
DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }}
DATABASE_CHARSET: ${{ matrix.database_charset }}
MAILER_URL: 'smtp://127.0.0.11025'
run: |
rm -r app/Plugin/*
Expand Down
7 changes: 5 additions & 2 deletions app/config/eccube/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ parameters:
# You should not need to change this value.
env(DATABASE_URL): ''
env(DATABASE_SERVER_VERSION): ~
env(DATABASE_CHARSET): 'utf8'

doctrine:
dbal:
driver: 'pdo_sqlite'
server_version: "%env(DATABASE_SERVER_VERSION)%"
charset: utf8
charset: '%env(DATABASE_CHARSET)%'

# for mysql only
default_table_options:
collate: 'utf8_general_ci'
charset: 'utf8mb4'
collation: 'utf8mb4_bin'

# With Symfony 3.3, remove the `resolve:` prefix
url: '%env(DATABASE_URL)%'
Expand Down
1 change: 1 addition & 0 deletions docker-compose.mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ services:
environment:
DATABASE_URL: "mysql://dbuser:secret@mysql/eccubedb"
DATABASE_SERVER_VERSION: 5.7
DATABASE_CHARSET: 'utf8mb4'

mysql:
image: mysql:5.7
Expand Down
1 change: 1 addition & 0 deletions docker-compose.pgsql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ services:
environment:
DATABASE_URL: "postgres://dbuser:secret@postgres/eccubedb"
DATABASE_SERVER_VERSION: 14
DATABASE_CHARSET: 'utf8'

postgres:
image: postgres:14
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ services:
APP_DEBUG: 1
DATABASE_URL: "sqlite:///var/eccube.db"
DATABASE_SERVER_VERSION: 3
DATABASE_CHARSET: 'utf8'
MAILER_DSN: "smtp://mailcatcher:1025"
ECCUBE_AUTH_MAGIC: "<change.me>"
# TRUSTED_HOSTS: '^127.0.0.1$$,^localhost$$'
Expand Down
5 changes: 5 additions & 0 deletions src/Eccube/Command/InstallerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function __construct(ContainerInterface $container)
public $appDebug;
public $databaseUrl;
public $serverVersion;
public $databaseCharset;
public $mailerDsn;
public $authMagic;
public $adminRoute;
Expand All @@ -74,6 +75,7 @@ private function getEnvParameters()
'APP_DEBUG' => $this->appDebug,
'DATABASE_URL' => $this->databaseUrl,
'DATABASE_SERVER_VERSION' => $this->serverVersion,
'DATABASE_CHARSET' => $this->databaseCharset,
'MAILER_DSN' => $this->mailerDsn,
'ECCUBE_AUTH_MAGIC' => $this->authMagic,
'ECCUBE_ADMIN_ROUTE' => $this->adminRoute,
Expand Down Expand Up @@ -141,6 +143,9 @@ protected function interact(InputInterface $input, OutputInterface $output)
// DATABASE_SERVER_VERSION
$this->envFileUpdater->serverVersion = $this->getDatabaseServerVersion($databaseUrl);

// DATABASE_CHARSET
$this->envFileUpdater->databaseCharset = \str_starts_with($databaseUrl, 'mysql') ? 'utf8mb4' : 'utf8';

// MAILER_DSN
$mailerDsn = $this->container->getParameter('eccube_mailer_dsn');
if (empty($mailerDsn)) {
Expand Down
6 changes: 4 additions & 2 deletions src/Eccube/Controller/Install/InstallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ public function complete(Request $request)
'ECCUBE_TEMPLATE_CODE' => 'default',
'ECCUBE_LOCALE' => 'ja',
'TRUSTED_HOSTS' => '^'.str_replace('.', '\\.', $request->getHost()).'$',
'DATABASE_CHARSET' => \str_starts_with($databaseUrl, 'mysql') ? 'utf8mb4' : 'utf8',
];

$env = StringUtil::replaceOrAddEnv($env, $replacement);
Expand Down Expand Up @@ -563,9 +564,10 @@ protected function checkModules()
protected function createConnection(array $params)
{
if (strpos($params['url'], 'mysql') !== false) {
$params['charset'] = 'utf8';
$params['charset'] = 'utf8mb4';
$params['defaultTableOptions'] = [
'collate' => 'utf8_general_ci',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_bin',
];
}

Expand Down
8 changes: 4 additions & 4 deletions src/Eccube/Entity/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,28 +462,28 @@ public function hasProductClass()
/**
* @var string|null
*
* @ORM\Column(name="note", type="string", length=4000, nullable=true)
* @ORM\Column(name="note", type="text", nullable=true)
*/
private $note;

/**
* @var string|null
*
* @ORM\Column(name="description_list", type="string", length=4000, nullable=true)
* @ORM\Column(name="description_list", type="text", nullable=true)
*/
private $description_list;

/**
* @var string|null
*
* @ORM\Column(name="description_detail", type="string", length=4000, nullable=true)
* @ORM\Column(name="description_detail", type="text", nullable=true)
*/
private $description_detail;

/**
* @var string|null
*
* @ORM\Column(name="search_word", type="string", length=4000, nullable=true)
* @ORM\Column(name="search_word", type="text", nullable=true)
*/
private $search_word;

Expand Down
19 changes: 19 additions & 0 deletions tests/Eccube/Tests/Web/Admin/Product/ProductControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1133,4 +1133,23 @@ public function testDeleteAndDeleteProductImage()
$this->assertTrue(file_exists($dir.$DuplicatedImage->getFileName()));
$this->assertFalse(file_exists($dir.$NotDuplicatedImage->getFileName()));
}

public function test絵文字()
{
$name = '🍣🍺';
$crawler = $this->client->request('GET', $this->generateUrl('product_list', ['name' => $name]));
$this->assertTrue($this->client->getResponse()->isSuccessful());

$message = $crawler->filter('.ec-searchnavRole__counter > span')->text();
$this->assertSame('お探しの商品は見つかりませんでした', $message);

// 絵文字の商品を登録
$this->createProduct($name);

$crawler = $this->client->request('GET', $this->generateUrl('product_list', ['name' => $name]));
$this->assertTrue($this->client->getResponse()->isSuccessful());

$message = $crawler->filter('.ec-searchnavRole__counter > span')->text();
$this->assertSame('1件', $message);
}
}