1 | <?php |
||
18 | class Backup extends BackendController |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * @var \gplcart\modules\backup\models\Backup $backup |
||
23 | */ |
||
24 | protected $backup; |
||
25 | |||
26 | /** |
||
27 | * Pager limit |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $data_limit; |
||
31 | |||
32 | /** |
||
33 | * @param ModuleBackupModel $backup |
||
34 | */ |
||
35 | public function __construct(ModuleBackupModel $backup) |
||
36 | { |
||
37 | parent::__construct(); |
||
38 | |||
39 | $this->backup = $backup; |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Displays the backup overview page |
||
44 | */ |
||
45 | public function listBackup() |
||
46 | { |
||
47 | $this->downloadListBackup(); |
||
48 | $this->actionListBackup(); |
||
49 | |||
50 | $this->setTitleListBackup(); |
||
51 | $this->setBreadcrumbListBackup(); |
||
52 | |||
53 | $this->setFilterListBackup(); |
||
54 | $this->setPagerListBackup(); |
||
55 | |||
56 | $this->setData('backups', $this->getListBackup()); |
||
57 | $this->setData('handlers', $this->backup->getHandlers()); |
||
58 | |||
59 | $this->outputListBackup(); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Sets filter parameters |
||
64 | */ |
||
65 | protected function setFilterListBackup() |
||
66 | { |
||
67 | $allowed = array('created', 'name', 'user_id', 'type', |
||
68 | 'version', 'id', 'backup_id'); |
||
69 | |||
70 | $this->setFilter($allowed); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * Downloads a backup |
||
75 | */ |
||
76 | protected function downloadListBackup() |
||
77 | { |
||
78 | $backup_id = $this->getQuery('download'); |
||
79 | |||
80 | if (empty($backup_id)) { |
||
81 | return null; |
||
82 | } |
||
83 | |||
84 | $this->controlAccess('backup_download'); |
||
85 | |||
86 | $backup = $this->backup->get($backup_id); |
||
87 | |||
88 | if (!empty($backup['path'])) { |
||
89 | $this->download(gplcart_file_absolute($backup['path'])); |
||
90 | } |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * Applies an action to the selected backups |
||
95 | */ |
||
96 | protected function actionListBackup() |
||
97 | { |
||
98 | list($selected, $action) = $this->getPostedAction(); |
||
99 | |||
100 | $deleted = 0; |
||
101 | foreach ($selected as $id) { |
||
102 | if ($action === 'delete' && $this->access('backup_delete')) { |
||
103 | $deleted += (int) $this->backup->delete($id); |
||
104 | } |
||
105 | } |
||
106 | |||
107 | if ($deleted > 0) { |
||
108 | $message = $this->text('Deleted %num item(s)', array('%num' => $deleted)); |
||
109 | $this->setMessage($message, 'success'); |
||
110 | } |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * Sets title on the backup overview page |
||
115 | */ |
||
116 | protected function setTitleListBackup() |
||
120 | |||
121 | /** |
||
122 | * Sets breadcrumbs on the backup overview page |
||
123 | */ |
||
124 | protected function setBreadcrumbListBackup() |
||
128 | |||
129 | /** |
||
130 | * Render and output the backup overview page |
||
131 | */ |
||
132 | protected function outputListBackup() |
||
136 | |||
137 | /** |
||
138 | * Returns an array of backups |
||
139 | * @return array |
||
140 | */ |
||
141 | protected function getListBackup() |
||
147 | |||
148 | /** |
||
149 | * Sets pager |
||
150 | * @return array |
||
151 | */ |
||
152 | protected function setPagerListBackup() |
||
164 | |||
165 | } |
||
166 |