app/DoctrineMigrations/Version20210319122142.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. /**
  18. * Auto-generated Migration: Please modify to your needs!
  19. */
  20. final class Version20210319122142 extends AbstractMigration
  21. {
  22. public function up(Schema $schema): void
  23. {
  24. $lang = env('ECCUBE_LOCALE');
  25. $statuses = [
  26. LoginHistoryStatus::FAILURE => $lang === 'en' ? 'Failure' : '失敗',
  27. LoginHistoryStatus::SUCCESS => $lang === 'en' ? 'Success' : '成功',
  28. ];
  29. $sortNo = $this->connection->fetchOne('SELECT MAX(sort_no) + 1 FROM mtb_login_history_status');
  30. if (is_null($sortNo)) {
  31. $sortNo = 0;
  32. }
  33. foreach ($statuses as $id => $name) {
  34. $statusExists = $this->connection->fetchOne(
  35. 'SELECT COUNT(*) FROM mtb_login_history_status WHERE id = :id',
  36. ['id' => $id]
  37. );
  38. if ($statusExists == 0) {
  39. $this->addSql(
  40. "INSERT INTO mtb_login_history_status (id, name, sort_no, discriminator_type) VALUES (?, ?, ?, 'loginhistorystatus')",
  41. [$id, $name, $sortNo++]
  42. );
  43. }
  44. }
  45. }
  46. public function down(Schema $schema): void
  47. {
  48. // this down() migration is auto-generated, please modify it to your needs
  49. }
  50. }