api.so-manager-dev.com/app/Console/Commands/ShjTwoCommand.php
unhi.go e1073e2577
All checks were successful
Deploy api / deploy (push) Successful in 24s
SH-6 SHJ-9 実装
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 20:16:47 +08:00

117 lines
3.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use App\Services\ShjTwoService;
/**
* SHJ-2 データバックアップコマンド
*
* データベースの夜間自動バックアップを実行する
* フルバックアップを5世代保持する
* 定期実行(日次 02:45またはオンデマンド実行
*/
class ShjTwoCommand extends Command
{
/**
* コンソールコマンドの名前とシグネチャ
*
* 引数なし - 全自動でバックアップを実行
*
* @var string
*/
protected $signature = 'shj:2';
/**
* コンソールコマンドの説明
*
* @var string
*/
protected $description = 'SHJ-2 データバックアップ - データベースとソースコードのフルバックアップを実行5世代保持';
/**
* SHJ-2サービスクラス
*
* @var ShjTwoService
*/
protected $shjTwoService;
/**
* コンストラクタ
*
* @param ShjTwoService $shjTwoService
*/
public function __construct(ShjTwoService $shjTwoService)
{
parent::__construct();
$this->shjTwoService = $shjTwoService;
}
/**
* コンソールコマンドを実行
*
* 処理フロー:
* <JOB1> 現時点の世代シフトを行う
* <JOB2> フルバックアップを行う
* <JOB3> バッチ処理ログを作成する
*
* @return int
*/
public function handle()
{
try {
// 開始ログ出力
$startTime = now();
$this->info('SHJ-2 データバックアップ処理を開始します。');
Log::info('SHJ-2 データバックアップ処理開始', [
'start_time' => $startTime
]);
// SHJ-2メイン処理実行
$result = $this->shjTwoService->execute();
$endTime = now();
// 処理結果に応じた出力
if ($result['success']) {
$this->info('SHJ-2 データバックアップ処理が正常に完了しました。');
$this->info("処理時間: {$startTime->diffInSeconds($endTime)}");
$this->info("ステータス: {$result['status']}");
$this->info("コメント: {$result['status_comment']}");
Log::info('SHJ-2 データバックアップ処理完了', [
'end_time' => $endTime,
'duration_seconds' => $startTime->diffInSeconds($endTime),
'status' => $result['status'],
'status_comment' => $result['status_comment']
]);
return self::SUCCESS;
} else {
$this->error('SHJ-2 データバックアップ処理でエラーが発生しました: ' . $result['status_comment']);
Log::error('SHJ-2 データバックアップ処理エラー', [
'status' => $result['status'],
'status_comment' => $result['status_comment']
]);
return self::FAILURE;
}
} catch (\Exception $e) {
$this->error('SHJ-2 データバックアップ処理で予期しないエラーが発生しました: ' . $e->getMessage());
Log::error('SHJ-2 データバックアップ処理例外エラー', [
'exception' => $e->getMessage(),
'trace' => $e->getTraceAsString()
]);
return self::FAILURE;
}
}
}