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

ログイン履歴機能のマイグレーションを追加 #5010

Merged
merged 5 commits into from
Aug 30, 2021
Merged
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
80 changes: 80 additions & 0 deletions app/DoctrineMigrations/Version20210412073123.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

declare(strict_types=1);

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Eccube\Entity\Master\LoginHistoryStatus;
use Eccube\Util\StringUtil;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210412073123 extends AbstractMigration
{
public function up(Schema $schema): void
{
if ($schema->hasTable('plg_admin_record_config')) {
$denyHostsPlugin = $this->connection->fetchColumn('select admin_deny_hosts FROM plg_admin_record_config') ?: '';
$denyHostsPlugin = array_filter(\explode("\n", StringUtil::convertLineFeed($denyHostsPlugin)), function ($str) {
return StringUtil::isNotBlank($str);
});

$denyHosts = array_merge(env('ECCUBE_ADMIN_DENY_HOSTS', []), $denyHostsPlugin);
$denyHosts = array_values(array_unique($denyHosts));

$denyHosts = \json_encode($denyHosts);

$envFile = __DIR__.'/../../.env';
$env = file_get_contents($envFile);

$env = StringUtil::replaceOrAddEnv($env, [
'ECCUBE_ADMIN_DENY_HOSTS' => "'${denyHosts}'",
]);

file_put_contents($envFile, $env);
}

if ($schema->hasTable('plg_admin_record')) {
$stmt = $this->connection->createQueryBuilder()
->select('*')
->from('plg_admin_record')
->orderBy('id', 'ASC')
->execute();

while ($row = $stmt->fetch()) {
$this->addSql(
"INSERT INTO dtb_login_history (user_name, client_ip, create_date, update_date, login_history_status_id, member_id, discriminator_type) VALUES (?, ?, ?, ?, ?, ?, 'loginhistory')",
[
$row['user_name'],
$row['client_ip'],
$row['create_date'],
$row['update_date'],
$row['success_flg'] ? LoginHistoryStatus::SUCCESS : LoginHistoryStatus::FAILURE,
$row['member_id'],
]
);
}
}
}

public function down(Schema $schema): void
{
if ($schema->hasTable('dtb_login_history')) {
$this->addSql('DELETE FROM dtb_login_history');
}
}
}