|
- <?php
-
- namespace App\Console\Commands\Migration;
-
- use App\Codes\EnvironmentName;
- use App\Codes\QueueName;
- use App\Console\Commands\BaseCommand;
- use App\Models\Htpms\MstCustomer;
- use App\Models\HtpmsCustomer\HtpmsCustomerConnectionSwitch;
- use Exception;
- use Illuminate\Support\Facades\Artisan;
- use Illuminate\Support\Facades\DB;
-
- class 全顧客マイグレーション extends BaseCommand
- {
-
- const COMMAND = "migrate:customer-all";
-
-
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = self::COMMAND;
-
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '全顧客毎テーブルをマイグレーションする';
-
- static public function getCommand()
- {
- return self::COMMAND;
- }
-
-
-
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
- /**
- * Execute the console command.
- *
- * @return int
- */
- public function service(): int
- {
- if (!app()->environment([EnvironmentName::PRODUCTOIN->value])) {
- $this->outputWarn("本番環境でないため、520以外はスキップします");
- }
- $customers = MstCustomer::query()
- ->orderBy(MstCustomer::COL_NAME_ID)
- ->get();
- foreach ($customers as $customer) {
- $this->handleCustomer($customer);
- }
-
-
- return self::RESULTCODE_SUCCESS;
- }
-
- private function handleCustomer(MstCustomer $customer)
- {
-
- // 本番環境のみ全顧客をマイグレーションする
- if (!app()->environment([EnvironmentName::PRODUCTOIN->value])) {
- if (
- $customer->id !== 520
- ) {
- return;
- }
- }
-
- if (!HtpmsCustomerConnectionSwitch::isEnable($customer->id)) {
- $this->outputWarn(sprintf("存在しないスキーマのためスキップ htpms_%d (%s:%s)", $customer->id, $customer->customer_name, $customer->customer_id));
- return;
- }
- try {
- Artisan::queue("migrate:customer", ["customerId" => $customer->id])
- ->onQueue(QueueName::MIGRATE->value);
- } catch (Exception $e) {
- print_r(DB::getConfig());
- throw $e;
- }
- }
- }
|