You've already forked Atomcms-edit
Remove all auto-update functionality (commands, services, widgets, blades, translations)
This commit is contained in:
@@ -1,343 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Services\EmulatorUpdateService;
|
||||
use App\Services\NitroUpdateService;
|
||||
use App\Services\RconService;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Widgets\Widget;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class UpdateCheckerWidget extends Widget
|
||||
{
|
||||
#[\Override]
|
||||
protected string $view = 'filament.widgets.update-checker';
|
||||
|
||||
#[\Override]
|
||||
protected int|string|array $columnSpan = 'full';
|
||||
|
||||
#[\Override]
|
||||
protected static ?int $sort = 0;
|
||||
|
||||
public ?string $emulatorVersion = null;
|
||||
|
||||
public ?string $latestEmulatorVersion = null;
|
||||
|
||||
public bool $emulatorUpdate = false;
|
||||
|
||||
public ?string $nitroVersion = null;
|
||||
|
||||
public ?string $latestNitroVersion = null;
|
||||
|
||||
public bool $nitroUpdate = false;
|
||||
|
||||
public int $onlineUsers = 0;
|
||||
|
||||
public string $dbSize = '0 MB';
|
||||
|
||||
public bool $hasAnyUpdate = false;
|
||||
|
||||
public int $sqlApplied = 0;
|
||||
|
||||
public int $sqlPending = 0;
|
||||
|
||||
public bool $sqlTableExists = false;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->emulatorVersion = setting('emulator_version', '?');
|
||||
$this->nitroVersion = setting('nitro_client_version', '?');
|
||||
|
||||
try {
|
||||
$this->onlineUsers = (int) DB::connection('mysql')->table('users')->where('online', '1')->count();
|
||||
$sizeResult = DB::connection('mysql')->select('SELECT ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) as db_size FROM information_schema.tables WHERE table_schema = DATABASE()');
|
||||
$this->dbSize = ($sizeResult[0]->db_size ?? '0') . ' MB';
|
||||
} catch (\Exception) {
|
||||
$this->dbSize = '? MB';
|
||||
}
|
||||
|
||||
$this->loadSqlStatus();
|
||||
|
||||
$cached = Cache::get('all_updates_check');
|
||||
|
||||
if ($cached !== null) {
|
||||
$this->emulatorUpdate = $cached['emulator'] ?? false;
|
||||
$this->latestEmulatorVersion = $cached['emulator_version'] ?? null;
|
||||
$this->nitroUpdate = $cached['nitro'] ?? false;
|
||||
$this->latestNitroVersion = $cached['nitro_version'] ?? null;
|
||||
$this->hasAnyUpdate = $this->emulatorUpdate || $this->nitroUpdate;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->performCheck();
|
||||
}
|
||||
|
||||
private function loadSqlStatus(): void
|
||||
{
|
||||
try {
|
||||
$updateService = new EmulatorUpdateService;
|
||||
$sqlDiagnosis = $updateService->diagnoseSqlUpdates();
|
||||
|
||||
$this->sqlTableExists = $sqlDiagnosis['table_exists'] ?? false;
|
||||
$this->sqlApplied = $sqlDiagnosis['applied_count'] ?? 0;
|
||||
$this->sqlPending = $sqlDiagnosis['pending_count'] ?? 0;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('[UpdateChecker] SQL status failed: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function performCheck(): void
|
||||
{
|
||||
try {
|
||||
$updateService = new EmulatorUpdateService;
|
||||
$check = $updateService->checkForUpdates();
|
||||
$this->emulatorUpdate = $check['update_available'] ?? false;
|
||||
$this->latestEmulatorVersion = $check['latest_version'] ?? null;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('[UpdateChecker] Emulator check failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$nitroService = new NitroUpdateService;
|
||||
$nitroCheck = $nitroService->checkForUpdates();
|
||||
$this->nitroUpdate = $nitroCheck['has_updates'] ?? false;
|
||||
if ($this->nitroUpdate) {
|
||||
$parts = [];
|
||||
if ($nitroCheck['client_update'] ?? false) {
|
||||
$parts[] = 'Client';
|
||||
}
|
||||
if ($nitroCheck['renderer_update'] ?? false) {
|
||||
$parts[] = 'Renderer';
|
||||
}
|
||||
$this->latestNitroVersion = implode(' + ', $parts);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('[UpdateChecker] Nitro check failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
$this->hasAnyUpdate = $this->emulatorUpdate || $this->nitroUpdate;
|
||||
|
||||
Cache::put('all_updates_check', [
|
||||
'emulator' => $this->emulatorUpdate,
|
||||
'emulator_version' => $this->latestEmulatorVersion,
|
||||
'nitro' => $this->nitroUpdate,
|
||||
'nitro_version' => $this->latestNitroVersion,
|
||||
], now()->addMinutes(15));
|
||||
}
|
||||
|
||||
public function forceCheck(): void
|
||||
{
|
||||
try {
|
||||
Cache::forget('all_updates_check');
|
||||
$updateService = new EmulatorUpdateService;
|
||||
$updateService->resetInstalledDate();
|
||||
$this->performCheck();
|
||||
|
||||
if ($this->hasAnyUpdate) {
|
||||
Notification::make()->success()->title('Updates Gevonden!')->body('Klik op "Alles Updaten" om te installeren')->send();
|
||||
} else {
|
||||
Notification::make()->info()->title('Geen Updates')->body('Alles is al up-to-date')->send();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Notification::make()->danger()->title('Fout')->body($e->getMessage())->send();
|
||||
}
|
||||
}
|
||||
|
||||
public function repairSystem(): void
|
||||
{
|
||||
try {
|
||||
Cache::forget('all_updates_check');
|
||||
|
||||
$messages = [];
|
||||
$errors = [];
|
||||
|
||||
try {
|
||||
$emuService = new EmulatorUpdateService;
|
||||
$repairResult = $emuService->repairEmulator();
|
||||
|
||||
if ($repairResult['success']) {
|
||||
$messages[] = '🖥️ Emulator: ' . ($repairResult['message'] ?? 'Gerepareerd');
|
||||
} else {
|
||||
$errors[] = 'Emulator: ' . ($repairResult['error'] ?? 'Onbekende fout');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$errors[] = 'Emulator: ' . $e->getMessage();
|
||||
}
|
||||
|
||||
try {
|
||||
$nitroService = new NitroUpdateService;
|
||||
$repairResult = $nitroService->repair();
|
||||
|
||||
if ($repairResult['success']) {
|
||||
$messages[] = '🎮 Nitro: ' . ($repairResult['message'] ?? 'Gerepareerd');
|
||||
} else {
|
||||
$errors[] = 'Nitro: ' . ($repairResult['error'] ?? 'Onbekende fout');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$errors[] = 'Nitro: ' . $e->getMessage();
|
||||
}
|
||||
|
||||
if ($messages !== []) {
|
||||
Notification::make()->success()->title('Reparatie Voltooid!')->body(implode(' | ', $messages))->send();
|
||||
}
|
||||
|
||||
if ($errors !== []) {
|
||||
Notification::make()->danger()->title('Reparatie Fout')->body(implode(' | ', $errors))->send();
|
||||
}
|
||||
|
||||
Cache::forget('all_updates_check');
|
||||
$this->mount();
|
||||
} catch (\Exception $e) {
|
||||
Notification::make()->danger()->title('Fout')->body($e->getMessage())->send();
|
||||
}
|
||||
}
|
||||
|
||||
public function diagnoseSystem(): void
|
||||
{
|
||||
try {
|
||||
$emuService = new EmulatorUpdateService;
|
||||
$nitroService = new NitroUpdateService;
|
||||
|
||||
$emuDiagnosis = $emuService->diagnose();
|
||||
$nitroDiagnosis = $nitroService->diagnose();
|
||||
|
||||
$issues = array_merge(
|
||||
$emuDiagnosis['issues'] ?? [],
|
||||
$nitroDiagnosis['issues'] ?? [],
|
||||
);
|
||||
|
||||
$recommendations = array_merge(
|
||||
$emuDiagnosis['recommendations'] ?? [],
|
||||
$nitroDiagnosis['recommendations'] ?? [],
|
||||
);
|
||||
|
||||
if ($issues === []) {
|
||||
Notification::make()->info()->title('Diagnose')->body('Geen problemen gevonden')->send();
|
||||
} else {
|
||||
$body = 'Problemen: ' . implode(', ', $issues);
|
||||
if ($recommendations !== []) {
|
||||
$body .= "\n\nAanbevelingen: " . implode(', ', $recommendations);
|
||||
}
|
||||
Notification::make()->warning()->title('Diagnose Resultaat')->body($body)->send();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Notification::make()->danger()->title('Fout')->body($e->getMessage())->send();
|
||||
}
|
||||
}
|
||||
|
||||
public function updateAll(): void
|
||||
{
|
||||
try {
|
||||
Cache::forget('all_updates_check');
|
||||
Cache::forget('website_settings');
|
||||
|
||||
$messages = [];
|
||||
$errors = [];
|
||||
$updateService = new EmulatorUpdateService;
|
||||
|
||||
try {
|
||||
$result = $updateService->updateEmulator();
|
||||
if ($result['success']) {
|
||||
$messages[] = '🖥️ ' . ($result['message'] ?? 'Emulator geüpdatet');
|
||||
} else {
|
||||
$error = $result['error'] ?? '';
|
||||
if (str_contains($error, 'al up-to-date')) {
|
||||
$messages[] = '🖥️ Emulator al up-to-date';
|
||||
} else {
|
||||
$errors[] = 'Emulator: ' . $error;
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$errors[] = 'Emulator: ' . $e->getMessage();
|
||||
}
|
||||
|
||||
try {
|
||||
$nitroService = new NitroUpdateService;
|
||||
$nitroCheck = $nitroService->checkForUpdates();
|
||||
|
||||
if ($nitroCheck['has_updates'] ?? false) {
|
||||
$result = $nitroService->updateNitro();
|
||||
if ($result['success']) {
|
||||
$parts = [];
|
||||
if ($result['renderer_updated'] ?? false) {
|
||||
$parts[] = 'Renderer';
|
||||
}
|
||||
if ($result['client_updated'] ?? false) {
|
||||
$parts[] = 'Client';
|
||||
}
|
||||
if ($result['built'] ?? false) {
|
||||
$parts[] = 'Build';
|
||||
}
|
||||
if ($result['deployed'] ?? false) {
|
||||
$parts[] = 'Deploy';
|
||||
}
|
||||
if ($parts !== []) {
|
||||
$messages[] = '🎮 Nitro: ' . implode(', ', $parts);
|
||||
}
|
||||
} elseif (! empty($result['errors'] ?? [])) {
|
||||
$errors = array_merge($errors, $result['errors']);
|
||||
}
|
||||
} else {
|
||||
$messages[] = '🎮 Nitro al up-to-date';
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$errors[] = 'Nitro: ' . $e->getMessage();
|
||||
}
|
||||
|
||||
try {
|
||||
$sqlResult = $updateService->runSqlUpdates();
|
||||
if ($sqlResult['sql_updated'] ?? false) {
|
||||
$count = count($sqlResult['files_run'] ?? []);
|
||||
if ($count > 0) {
|
||||
$messages[] = "📊 {$count} SQL updates";
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$errors[] = 'SQL: ' . $e->getMessage();
|
||||
}
|
||||
|
||||
try {
|
||||
$updateService->restartEmulator();
|
||||
$messages[] = '🔄 Emulator herstart';
|
||||
} catch (\Exception $e) {
|
||||
Log::error('[UpdateChecker] Restart failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$rcon = new RconService;
|
||||
$rcon->sendCommand('updatecatalog');
|
||||
$rcon->sendCommand('updatewordfilter');
|
||||
$messages[] = '📚 Catalogus + filter vernieuwd';
|
||||
} catch (\Exception $e) {
|
||||
Log::error('[UpdateChecker] RCON failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
if ($messages !== []) {
|
||||
Notification::make()->success()->title('Updates Voltooid!')->body(implode(' | ', $messages))->send();
|
||||
}
|
||||
|
||||
if ($errors !== []) {
|
||||
Notification::make()->danger()->title('Sommige Updates Mislukt')->body(implode(' | ', $errors))->send();
|
||||
}
|
||||
|
||||
if ($messages === [] && $errors === []) {
|
||||
Notification::make()->info()->title('Geen Updates')->body('Alles was al up-to-date')->send();
|
||||
}
|
||||
|
||||
Cache::forget('all_updates_check');
|
||||
$this->mount();
|
||||
} catch (\Exception $e) {
|
||||
Notification::make()->danger()->title('Fout')->body($e->getMessage())->send();
|
||||
}
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public static function canView(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user