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

BackupsController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 93
ccs 0
cts 52
cp 0
rs 10
c 1
b 0
f 0
wmc 8
lcom 2
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A index() 0 10 1
A show() 0 14 2
A backup() 0 19 2
A clear() 0 19 2
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