Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Failing after 3m18s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Failing after 3m27s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Failing after 3m0s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Failing after 2m56s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 4m4s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 4m1s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 3m41s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 3m39s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m10s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
35 lines
1.1 KiB
PHP
35 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Inhaus\Plugins\Speiseplan;
|
|
|
|
use App\Plugins\Plugin;
|
|
use App\Support\Abilities;
|
|
use App\Support\Navigation;
|
|
use Illuminate\Support\Facades\Schedule;
|
|
use Inhaus\Plugins\Speiseplan\Models\Week;
|
|
|
|
class SpeiseplanPlugin extends Plugin
|
|
{
|
|
/** Vergangene Wochen bleiben so lange erhalten, dann werden sie gelöscht. */
|
|
public const KEEP_WEEKS = 2;
|
|
|
|
public function register(): void
|
|
{
|
|
$this->app->make(Navigation::class)->add('speiseplan', 'Speiseplan', '/speiseplan', active: 'speiseplan.*', sort: 70);
|
|
$this->app->make(Abilities::class)->define('speiseplan.manage', 'Speiseplan hochladen', 'Speiseplan');
|
|
}
|
|
|
|
public function boot(): void
|
|
{
|
|
Schedule::call(fn () => self::purge())->dailyAt('03:30')->name('speiseplan-purge')->withoutOverlapping(10);
|
|
}
|
|
|
|
public static function purge(): int
|
|
{
|
|
$cutoff = Week::mondayOf(now())->subWeeks(self::KEEP_WEEKS);
|
|
$old = Week::query()->where('week_start', '<', $cutoff->toDateString())->get();
|
|
$old->each->delete();
|
|
|
|
return $old->count();
|
|
}
|
|
}
|