Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

97 lines
2.4KB

  1. <?php
  2. namespace App\Console\Commands\Migration;
  3. use App\Codes\EnvironmentName;
  4. use App\Codes\QueueName;
  5. use App\Console\Commands\BaseCommand;
  6. use App\Models\Htpms\MstCustomer;
  7. use App\Models\HtpmsCustomer\HtpmsCustomerConnectionSwitch;
  8. use Exception;
  9. use Illuminate\Support\Facades\Artisan;
  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. if (!HtpmsCustomerConnectionSwitch::isEnable($customer->id)) {
  68. $this->outputWarn(sprintf("存在しないスキーマのためスキップ htpms_%d (%s:%s)", $customer->id, $customer->customer_name, $customer->customer_id));
  69. return;
  70. }
  71. try {
  72. Artisan::queue("migrate:customer", ["customerId" => $customer->id])
  73. ->onQueue(QueueName::MIGRATE->value);
  74. } catch (Exception $e) {
  75. print_r(DB::getConfig());
  76. throw $e;
  77. }
  78. }
  79. }