Skip to content

Commit ce8e44d

Browse files
Update RunBackup.php
1 parent e25aaf0 commit ce8e44d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

web/app/Console/Commands/RunBackup.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Models\Backup;
66
use App\Models\HostingSubscription;
7+
use Carbon\Carbon;
78
use Illuminate\Console\Command;
89
use Illuminate\Database\Schema\Blueprint;
910
use Illuminate\Support\Facades\Schema;
@@ -29,6 +30,29 @@ class RunBackup extends Command
2930
*/
3031
public function handle()
3132
{
33+
34+
// Find Hosting Subscriptions
35+
$findHostingSubscriptions = HostingSubscription::all();
36+
if ($findHostingSubscriptions->count() > 0) {
37+
foreach ($findHostingSubscriptions as $hostingSubscription) {
38+
39+
$findBackup = Backup::where('hosting_subscription_id', $hostingSubscription->id)
40+
->where('backup_type', 'hosting_subscription')
41+
->where('created_at', '>=', Carbon::now()->subHours(24))
42+
->first();
43+
if (! $findBackup) {
44+
$backup = new Backup();
45+
$backup->hosting_subscription_id = $hostingSubscription->id;
46+
$backup->backup_type = 'hosting_subscription';
47+
$backup->status = 'pending';
48+
$backup->save();
49+
} else {
50+
$this->info('Backup already exists for ' . $hostingSubscription->domain);
51+
$this->info('Created before: ' . $findBackup->created_at->diffForHumans());
52+
}
53+
}
54+
}
55+
3256
// Delete backups older than 7 days
3357
$findBackupsForDeleting = Backup::where('created_at', '<', now()->subDays(7))->get();
3458
foreach ($findBackupsForDeleting as $backup) {

0 commit comments

Comments
 (0)