Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

109 řádky
2.8KB

  1. <?php
  2. namespace App\Console\Commands\Migration;
  3. use App\Codes\EnvironmentName;
  4. use App\Console\Commands\BaseCommand;
  5. use App\Models\Htpms\MstCustomer;
  6. use App\Models\HtpmsCustomer\Existing\Parking;
  7. use App\Models\HtpmsCustomer\HtpmsCustomerConnectionSwitch;
  8. use Exception;
  9. use Illuminate\Database\QueryException;
  10. use Illuminate\Support\Facades\DB;
  11. class 全顧客マイグレーション extends BaseCommand
  12. {
  13. const COMMAND = "migrate:customer-all";
  14. /**
  15. * The name and signature of the console command.
  16. *
  17. * @var string
  18. */
  19. protected $signature = self::COMMAND;
  20. /**
  21. * The console command description.
  22. *
  23. * @var string
  24. */
  25. protected $description = '全顧客毎テーブルをマイグレーションする';
  26. static public function getCommand()
  27. {
  28. return self::COMMAND;
  29. }
  30. /**
  31. * Create a new command instance.
  32. *
  33. * @return void
  34. */
  35. public function __construct()
  36. {
  37. parent::__construct();
  38. }
  39. /**
  40. * Execute the console command.
  41. *
  42. * @return int
  43. */
  44. public function service(): int
  45. {
  46. if (!app()->environment([EnvironmentName::PRODUCTOIN->value])) {
  47. $this->outputWarn("本番環境でないため、520以外はスキップします");
  48. }
  49. $customers = MstCustomer::query()
  50. ->orderBy(MstCustomer::COL_NAME_ID)
  51. ->get();
  52. foreach ($customers as $customer) {
  53. $this->handleCustomer($customer);
  54. }
  55. return self::RESULTCODE_SUCCESS;
  56. }
  57. private function handleCustomer(MstCustomer $customer)
  58. {
  59. // 本番環境のみ全顧客をマイグレーションする
  60. if (!app()->environment([EnvironmentName::PRODUCTOIN->value])) {
  61. if (
  62. $customer->id !== 520
  63. ) {
  64. return;
  65. }
  66. }
  67. // ## 暫定的に対象を絞り中 テスト中
  68. if (!in_array($customer->id, [1, 520], true)) {
  69. return;
  70. }
  71. if (!HtpmsCustomerConnectionSwitch::isEnable($customer->id)) {
  72. $this->outputWarn(sprintf("存在しないスキーマのためスキップ htpms_%d (%s:%s)", $customer->id, $customer->customer_name, $customer->customer_id));
  73. return;
  74. }
  75. HtpmsCustomerConnectionSwitch::switch($customer->id);
  76. try {
  77. $this->outputInfo(sprintf("start htpms_%d migration (%s:%s) ", $customer->id, $customer->customer_name, $customer->customer_id));
  78. $this->call("migrate", ["--force" => true]);
  79. $this->outputInfo(sprintf("end htpms_%d migration (%s:%s)", $customer->id, $customer->customer_name, $customer->customer_id));
  80. } catch (Exception $e) {
  81. print_r(DB::getConfig());
  82. throw $e;
  83. }
  84. }
  85. }