User 介面 只能看資料不能做修改 Role 介面移除 Branch介面 只能看資料不能做修改 Room 介面 可操控 包廂開關台 Sqgger API 可操控API Room 有操控異動記錄 machine_statuses 需做資料留存需留7 天 20250528
50 lines
1.6 KiB
PHP
50 lines
1.6 KiB
PHP
<?php
|
||
|
||
namespace App\Console\Commands;
|
||
|
||
use Illuminate\Console\Command;
|
||
use Illuminate\Support\Facades\Storage;
|
||
use App\Jobs\TransferSqliteTableJob;
|
||
|
||
class TransferSqliteToMysql extends Command
|
||
{
|
||
protected $signature = 'transfer:sqlite
|
||
{path : SQLite 相對路徑(例:sqlite/song.sqlite)}
|
||
{--sync : 同步執行}';
|
||
|
||
protected $description = '將 SQLite 中的資料表轉移到 MySQL 資料庫中';
|
||
|
||
public function handle(): int
|
||
{
|
||
$start = now();
|
||
$path = ltrim($this->argument('path'), '/');
|
||
$fullPath = Storage::disk('local')->path($path);
|
||
|
||
$this->info("[Transfer] 開始轉移 SQLite 資料:{$fullPath}");
|
||
|
||
if (!file_exists($fullPath)) {
|
||
$this->error("[Transfer] 找不到 SQLite 檔案:{$fullPath}");
|
||
return 1;
|
||
}
|
||
|
||
try {
|
||
if ($this->option('sync')) {
|
||
$this->warn('[Transfer] 使用同步模式執行...');
|
||
(new TransferSqliteTableJob($fullPath))->handle();
|
||
$this->info('[Transfer] 匯出完成(同步)');
|
||
} else {
|
||
TransferSqliteTableJob::dispatch($fullPath);
|
||
$this->info('[Transfer] 匯出任務已派送至 queue');
|
||
}
|
||
|
||
$duration = now()->diffInSeconds($start);
|
||
$this->info("[Transfer] 執行完成,用時 {$duration} 秒");
|
||
|
||
} catch (\Throwable $e) {
|
||
$this->error('[Transfer] 發生錯誤:' . $e->getMessage());
|
||
return 1;
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
} |