48 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace App\Models;
 | 
						|
 | 
						|
use Illuminate\Database\Eloquent\Relations\HasMany;
 | 
						|
use Illuminate\Database\Eloquent\Relations\HasOne;
 | 
						|
use Illuminate\Database\Eloquent\Relations\MorphTo;
 | 
						|
 | 
						|
class ScheduledDatabaseBackup extends BaseModel
 | 
						|
{
 | 
						|
    protected $guarded = [];
 | 
						|
 | 
						|
    public function database(): MorphTo
 | 
						|
    {
 | 
						|
        return $this->morphTo();
 | 
						|
    }
 | 
						|
 | 
						|
    public function latest_log(): HasOne
 | 
						|
    {
 | 
						|
        return $this->hasOne(ScheduledDatabaseBackupExecution::class)->latest();
 | 
						|
    }
 | 
						|
 | 
						|
    public function executions(): HasMany
 | 
						|
    {
 | 
						|
        return $this->hasMany(ScheduledDatabaseBackupExecution::class);
 | 
						|
    }
 | 
						|
 | 
						|
    public function s3()
 | 
						|
    {
 | 
						|
        return $this->belongsTo(S3Storage::class, 's3_storage_id');
 | 
						|
    }
 | 
						|
 | 
						|
    public function get_last_days_backup_status($days = 7)
 | 
						|
    {
 | 
						|
        return $this->hasMany(ScheduledDatabaseBackupExecution::class)->where('created_at', '>=', now()->subDays($days))->get();
 | 
						|
    }
 | 
						|
    public function server()
 | 
						|
    {
 | 
						|
        if ($this->database) {
 | 
						|
            if ($this->database->destination && $this->database->destination->server) {
 | 
						|
                $server = $this->database->destination->server;
 | 
						|
                return $server;
 | 
						|
            }
 | 
						|
        }
 | 
						|
        return null;
 | 
						|
    }
 | 
						|
}
 |