Completed
Push — master ( 6afbe3...6afbe3 )
by ARCANEDEV
07:48 queued 05:51
created

BackupsController::backup()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 0
dl 0
loc 19
ccs 0
cts 15
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
1
<?php namespace Arcanesoft\Foundation\Http\Controllers\Admin\System;
2
3
use Arcanesoft\Core\Traits\Notifyable;
4
use Arcanesoft\Foundation\Services\Backups;
5
6
/**
7
 * Class     BackupsController
8
 *
9
 * @package  Arcanesoft\Foundation\Http\Controllers\Admin\System
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class BackupsController extends Controller
13
{
14
    /* ------------------------------------------------------------------------------------------------
15
     |  Traits
16
     | ------------------------------------------------------------------------------------------------
17
     */
18
    use Notifyable;
19
20
    /* ------------------------------------------------------------------------------------------------
21
     |  Constructor
22
     | ------------------------------------------------------------------------------------------------
23
     */
24
    /**
25
     * BackupsController constructor.
26
     */
27
    public function __construct()
28
    {
29
        parent::__construct();
30
31
        $this->setCurrentPage('foundation-system-backups');
32
        $this->addBreadcrumbRoute('Backups', 'admin::foundation.system.backups.index');
33
    }
34
35
    /* ------------------------------------------------------------------------------------------------
36
     |  Main Functions
37
     | ------------------------------------------------------------------------------------------------
38
     */
39
    public function index()
40
    {
41
        // TODO: Add authorization check
42
        $this->setTitle('Backups');
43
        $this->addBreadcrumb('List of all backup statuses');
44
45
        $statuses = Backups::statuses();
46
47
        return $this->view('admin.system.backups.index', compact('statuses'));
48
    }
49
50
    public function show($index)
51
    {
52
        // TODO: Add authorization check
53
        $status = Backups::getStatus($index);
54
55
        if (is_null($status)) self::pageNotFound();
56
57
        $this->setTitle('Backups');
58
        $this->addBreadcrumb('List of all backups');
59
60
        $backups = $status->backupDestination()->backups();
61
62
        return $this->view('admin.system.backups.show', compact('status', 'backups'));
63
    }
64
65
    public function backup()
66
    {
67
        // TODO: Add authorization check
68
        self::onlyAjax();
69
70
        if (Backups::runBackups()) {
71
            $ajax = ['status' => 'success'];
72
73
            $this->notifySuccess('', 'Backups created !');
74
        }
75
        else {
76
            $ajax = [
77
                'status'  => 'error',
78
                'message' => 'There is an error while running the backups.'
79
            ];
80
        }
81
82
        return response()->json($ajax);
83
    }
84
85
    public function clear()
86
    {
87
        // TODO: Add authorization check
88
        self::onlyAjax();
89
90
        if (Backups::clearBackups()) {
91
            $ajax = ['status' => 'success'];
92
93
            $this->notifySuccess('The Backups was cleared successfully !', 'Backups cleared !');
94
        }
95
        else {
96
            $ajax = [
97
                'status'  => 'error',
98
                'message' => 'There is an error while clearing the backups.'
99
            ];
100
        }
101
102
        return response()->json($ajax);
103
    }
104
}
105