File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 4
4
5
5
use App \Models \Backup ;
6
6
use App \Models \HostingSubscription ;
7
+ use Carbon \Carbon ;
7
8
use Illuminate \Console \Command ;
8
9
use Illuminate \Database \Schema \Blueprint ;
9
10
use Illuminate \Support \Facades \Schema ;
@@ -29,6 +30,29 @@ class RunBackup extends Command
29
30
*/
30
31
public function handle ()
31
32
{
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
+
32
56
// Delete backups older than 7 days
33
57
$ findBackupsForDeleting = Backup::where ('created_at ' , '< ' , now ()->subDays (7 ))->get ();
34
58
foreach ($ findBackupsForDeleting as $ backup ) {
You can’t perform that action at this time.
0 commit comments