app/DoctrineMigrations/Version20210412073123.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of EC-CUBE
  5. *
  6. * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  7. *
  8. * http://www.ec-cube.co.jp/
  9. *
  10. * For the full copyright and license information, please view the LICENSE
  11. * file that was distributed with this source code.
  12. */
  13. namespace DoctrineMigrations;
  14. use Doctrine\DBAL\Schema\Schema;
  15. use Doctrine\Migrations\AbstractMigration;
  16. use Eccube\Entity\Master\LoginHistoryStatus;
  17. use Eccube\Util\StringUtil;
  18. /**
  19. * Auto-generated Migration: Please modify to your needs!
  20. */
  21. final class Version20210412073123 extends AbstractMigration
  22. {
  23. public function up(Schema $schema): void
  24. {
  25. if ($schema->hasTable('plg_admin_record_config')) {
  26. $denyHostsPlugin = $this->connection->fetchOne('select admin_deny_hosts FROM plg_admin_record_config') ?: '';
  27. $denyHostsPlugin = array_filter(\explode("\n", StringUtil::convertLineFeed($denyHostsPlugin)), function ($str) {
  28. return StringUtil::isNotBlank($str);
  29. });
  30. $denyHosts = array_merge(env('ECCUBE_ADMIN_DENY_HOSTS', []), $denyHostsPlugin);
  31. $denyHosts = array_values(array_unique($denyHosts));
  32. $denyHosts = \json_encode($denyHosts);
  33. $envFile = __DIR__.'/../../.env';
  34. $env = file_get_contents($envFile);
  35. $env = StringUtil::replaceOrAddEnv($env, [
  36. 'ECCUBE_ADMIN_DENY_HOSTS' => "'${denyHosts}'",
  37. ]);
  38. file_put_contents($envFile, $env);
  39. }
  40. if ($schema->hasTable('plg_admin_record')) {
  41. $stmt = $this->connection->createQueryBuilder()
  42. ->select('*')
  43. ->from('plg_admin_record')
  44. ->orderBy('id', 'ASC')
  45. ->execute();
  46. while ($row = $stmt->fetch()) {
  47. $this->addSql(
  48. "INSERT INTO dtb_login_history (user_name, client_ip, create_date, update_date, login_history_status_id, member_id, discriminator_type) VALUES (?, ?, ?, ?, ?, ?, 'loginhistory')",
  49. [
  50. $row['user_name'],
  51. $row['client_ip'],
  52. $row['create_date'],
  53. $row['update_date'],
  54. $row['success_flg'] ? LoginHistoryStatus::SUCCESS : LoginHistoryStatus::FAILURE,
  55. $row['member_id'],
  56. ]
  57. );
  58. }
  59. }
  60. }
  61. public function down(Schema $schema): void
  62. {
  63. if ($schema->hasTable('dtb_login_history')) {
  64. $this->addSql('DELETE FROM dtb_login_history');
  65. }
  66. }
  67. }