Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added command to delete deleted saves and added it to the cronjobs #18

Merged
merged 1 commit into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions app/Console/Commands/PurgeDeletedSaves.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace App\Console\Commands;

use App\Models\Save;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Console\Command;

/**
* Kommando, welcher alle Gelöschten Speicherstände löschen, welche zu alt sind.
*
* Um festzulegen, nach welcher Zeit die User gelöscht werden sollen, muss die methode PurgeDeletedSaves::savesPurgeBefore
*
* @see PurgeDeletedSaves::savesPurgeBefore()
*/
class PurgeDeletedSaves extends Command
{
/**
* Name des Kommandos.
*
* @var string
*/
protected $signature = 'purge:saves';

/**
* Beschreibung des Kommandos
*
* @var string
*/
protected $description = 'Does delete all save database entries, which are deleted and passed a speciefed time period';

/**
* Setzt Zeitpunkt fest vor den gelöschte Speicherstände vollständig gelöscht werden.
*
* @var Carbon
*/
public static $purgedBefore;

/**
* Alle gelöschten Speicherstände, welche vor dem übergebenen Datum ihr Löschdatum hatten, werden gelöscht
* @param Carbon $date Muss in der vergangenheit liegen
*/
public static function savesPurgeBefore(Carbon $date)
{
if($date->isPast())
static::$purgedBefore = $date;
}

/**
* Gibt den Wert von $purgedBefore oder den Zeitpunkt vor einem Monat zurück
* @see $purgedBefore
* @return Carbon
*/
public static function getUserPurgedBeforeTime(){
return static::$purgedBefore?:Carbon::now()->subMonth();
}

/**
* Führt das Kommando aus
*/
public function handle()
{
$count = Save::withTrashed()->where('deleted_at', '<', static::getUserPurgedBeforeTime())->forceDelete();
$this->output->success("Deleted " . $count . " rows!");
}
}
1 change: 1 addition & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ protected function schedule(Schedule $schedule)
{
$schedule->command('purge:deleted')->weekly();
$schedule->command('purge:anonymous')->weekly();
$schedule->command("purge:saves")->weekly();
$schedule->command('passport:purge')->monthly();
$schedule->command('notify:userCount')->daily();
}
Expand Down