40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?php
|
||
|
||
namespace App\Console\Commands;
|
||
|
||
use Illuminate\Console\Command;
|
||
|
||
class CheckUpdates extends Command
|
||
{
|
||
protected $signature = 'mailwolt:check-updates';
|
||
protected $description = 'Check for newer MailWolt releases via git tags';
|
||
|
||
public function handle(): int
|
||
{
|
||
$appPath = base_path();
|
||
$current = trim(@file_get_contents(base_path('VERSION'))) ?: '0.0.0';
|
||
// newest tag from origin (sorted semver-friendly)
|
||
$latest = trim(shell_exec(
|
||
"cd {$appPath} && git fetch --tags --quiet origin && git tag --list | sort -V | tail -n1"
|
||
) ?? '');
|
||
|
||
// Tags haben usually ein 'v' Prefix – entfernen
|
||
$latest = ltrim($latest, 'v');
|
||
|
||
if (!$latest) {
|
||
$this->warn('Keine Release-Tags gefunden.');
|
||
cache()->forget('mailwolt.update_available');
|
||
return 0;
|
||
}
|
||
|
||
if (version_compare($latest, $current, '>')) {
|
||
cache()->forever('mailwolt.update_available', $latest);
|
||
$this->info("Update verfügbar: {$latest} (installiert: {$current})");
|
||
} else {
|
||
cache()->forget('mailwolt.update_available');
|
||
$this->info("Aktuell (installiert: {$current}).");
|
||
}
|
||
return 0;
|
||
}
|
||
}
|