|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package Reset |
|
5
|
|
|
* @author Iurii Makukh <[email protected]> |
|
6
|
|
|
* @copyright Copyright (c) 2017, Iurii Makukh <[email protected]> |
|
7
|
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+ |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace gplcart\modules\reset\controllers; |
|
11
|
|
|
|
|
12
|
|
|
use gplcart\core\controllers\backend\Controller; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Handles incoming requests and outputs data related to Reset module |
|
16
|
|
|
*/ |
|
17
|
|
|
class Reset extends Controller |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Route page callback |
|
22
|
|
|
*/ |
|
23
|
|
|
public function editReset() |
|
24
|
|
|
{ |
|
25
|
|
|
$this->controlAccessSuperAdmin(); |
|
26
|
|
|
$this->setTitleEditReset(); |
|
27
|
|
|
$this->setBreadcrumbEditReset(); |
|
28
|
|
|
$this->submitReset(); |
|
29
|
|
|
$this->outputEditReset(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Set title on the reset page |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function setTitleEditReset() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->setTitle($this->text('Reset')); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Set breadcrumbs on the reset page |
|
42
|
|
|
*/ |
|
43
|
|
|
protected function setBreadcrumbEditReset() |
|
44
|
|
|
{ |
|
45
|
|
|
$breadcrumb = array( |
|
46
|
|
|
'url' => $this->url('admin'), |
|
47
|
|
|
'text' => $this->text('Dashboard') |
|
48
|
|
|
); |
|
49
|
|
|
|
|
50
|
|
|
$this->setBreadcrumb($breadcrumb); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Handles submitted data |
|
55
|
|
|
*/ |
|
56
|
|
|
protected function submitReset() |
|
57
|
|
|
{ |
|
58
|
|
|
if ($this->isPosted('submit') && $this->validateReset()) { |
|
59
|
|
|
$this->doReset(); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Validates submitted data |
|
65
|
|
|
* @return boolean |
|
66
|
|
|
*/ |
|
67
|
|
|
protected function validateReset() |
|
68
|
|
|
{ |
|
69
|
|
|
$this->setSubmitted('reset'); |
|
70
|
|
|
|
|
71
|
|
|
if ($this->getSubmitted('confirm') !== $this->getStore('name')) { |
|
72
|
|
|
$this->setError('confirm', $this->text('Wrong confirmation word')); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return !$this->hasErrors(false); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Update module settings |
|
80
|
|
|
*/ |
|
81
|
|
|
protected function doReset() |
|
82
|
|
|
{ |
|
83
|
|
|
$this->controlAccessSuperAdmin(); |
|
84
|
|
|
$this->doDbTablesReset(); |
|
85
|
|
|
$this->doConfigReset(); |
|
86
|
|
|
|
|
87
|
|
|
$this->url->redirect($this->url->get('install', array(), true, true)); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Delete config files created during installation |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function doConfigReset() |
|
94
|
|
|
{ |
|
95
|
|
|
return gplcart_config_delete(GC_FILE_CONFIG_COMPILED); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Delete all tables from the database |
|
100
|
|
|
*/ |
|
101
|
|
|
public function doDbTablesReset() |
|
102
|
|
|
{ |
|
103
|
|
|
$db = $this->config->getDb(); |
|
104
|
|
|
$db->exec('SET FOREIGN_KEY_CHECKS = 0'); |
|
105
|
|
|
|
|
106
|
|
|
foreach ($db->fetchColumnAll('SHOW TABLES') as $table) { |
|
107
|
|
|
$db->query("DROP TABLE $table"); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
$db->exec('SET FOREIGN_KEY_CHECKS = 1'); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Render and output the reset page |
|
115
|
|
|
*/ |
|
116
|
|
|
protected function outputEditReset() |
|
117
|
|
|
{ |
|
118
|
|
|
$this->output('reset|reset'); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
} |
|
122
|
|
|
|