1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Controllers; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Commands\ImportReviews; |
6
|
|
|
use GeminiLabs\SiteReviews\Commands\ImportSettings; |
7
|
|
|
use GeminiLabs\SiteReviews\Database; |
8
|
|
|
use GeminiLabs\SiteReviews\Database\CountManager; |
9
|
|
|
use GeminiLabs\SiteReviews\Database\OptionManager; |
10
|
|
|
use GeminiLabs\SiteReviews\Database\SqlSchema; |
11
|
|
|
use GeminiLabs\SiteReviews\Helper; |
12
|
|
|
use GeminiLabs\SiteReviews\Modules\Console; |
13
|
|
|
use GeminiLabs\SiteReviews\Modules\Html\Builder; |
14
|
|
|
use GeminiLabs\SiteReviews\Modules\Migrate; |
15
|
|
|
use GeminiLabs\SiteReviews\Modules\Notice; |
16
|
|
|
use GeminiLabs\SiteReviews\Modules\SystemInfo; |
17
|
|
|
use GeminiLabs\SiteReviews\Request; |
18
|
|
|
use GeminiLabs\SiteReviews\Role; |
19
|
|
|
|
20
|
|
|
class ToolsController extends Controller |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @return void |
24
|
|
|
* @action site-reviews/route/admin/clear-console |
25
|
|
|
*/ |
26
|
|
|
public function clearConsole() |
27
|
|
|
{ |
28
|
|
|
glsr(Console::class)->clear(); |
29
|
|
|
glsr(Notice::class)->addSuccess(_x('Console cleared.', 'admin-text', 'site-reviews')); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return void |
34
|
|
|
* @action site-reviews/route/ajax/clear-console |
35
|
|
|
*/ |
36
|
|
|
public function clearConsoleAjax() |
37
|
|
|
{ |
38
|
|
|
$this->clearConsole(); |
39
|
|
|
wp_send_json_success([ |
40
|
|
|
'console' => glsr(Console::class)->get(), |
41
|
|
|
'notices' => glsr(Notice::class)->get(), |
42
|
|
|
]); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return void |
47
|
|
|
* @action site-reviews/route/admin/convert-table-engine |
48
|
|
|
*/ |
49
|
|
|
public function convertTableEngine(Request $request) |
50
|
|
|
{ |
51
|
|
|
$result = glsr(SqlSchema::class)->convertTableEngine($request->table); |
52
|
|
|
if (true === $result) { |
53
|
|
|
glsr(Notice::class)->addSuccess( |
54
|
|
|
sprintf(_x('The <code>%s</code> table was successfully converted to InnoDB.', 'admin-text', 'site-reviews'), $request->table) |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
if (false === $result) { |
58
|
|
|
glsr(Notice::class)->addError( |
59
|
|
|
sprintf(_x('The <code>%s</code> table could not be converted to InnoDB.', 'admin-text', 'site-reviews'), $request->table) |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
if (-1 === $result) { |
63
|
|
|
glsr(Notice::class)->addWarning( |
64
|
|
|
sprintf(_x('The <code>%s</code> table was not found in the database.', 'admin-text', 'site-reviews'), $request->table) |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return void |
71
|
|
|
* @action site-reviews/route/ajax/convert-table-engine |
72
|
|
|
*/ |
73
|
|
|
public function convertTableEngineAjax(Request $request) |
74
|
|
|
{ |
75
|
|
|
$this->convertTableEngine($request); |
76
|
|
|
wp_send_json_success([ |
77
|
|
|
'notices' => glsr(Notice::class)->get(), |
78
|
|
|
]); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return void |
83
|
|
|
* @action site-reviews/route/admin/detect-ip-address |
84
|
|
|
*/ |
85
|
|
|
public function detectIpAddress() |
86
|
|
|
{ |
87
|
|
|
$link = glsr(Builder::class)->a([ |
88
|
|
|
'data-expand' => '#faq-ipaddress-incorrectly-detected', |
89
|
|
|
'href' => admin_url('edit.php?post_type='.glsr()->post_type.'&page=documentation#tab-faq'), |
90
|
|
|
'text' => _x('FAQ', 'admin-text', 'site-reviews'), |
91
|
|
|
]); |
92
|
|
|
if ('unknown' === $ipAddress = Helper::getIpAddress()) { |
93
|
|
|
glsr(Notice::class)->addWarning(sprintf( |
94
|
|
|
_x('Site Reviews was unable to detect an IP address. To fix this, please see the %s.', 'admin-text', 'site-reviews'), |
95
|
|
|
$link |
96
|
|
|
)); |
97
|
|
|
} else { |
98
|
|
|
glsr(Notice::class)->addSuccess(sprintf( |
99
|
|
|
_x('Your detected IP address is %s. If this looks incorrect, please see the %s.', 'admin-text', 'site-reviews'), |
100
|
|
|
'<code>'.$ipAddress.'</code>', $link |
101
|
|
|
)); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return void |
107
|
|
|
* @action site-reviews/route/ajax/detect-ip-address |
108
|
|
|
*/ |
109
|
|
|
public function detectIpAddressAjax() |
110
|
|
|
{ |
111
|
|
|
$this->detectIpAddress(); |
112
|
|
|
wp_send_json_success([ |
113
|
|
|
'notices' => glsr(Notice::class)->get(), |
114
|
|
|
]); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return void |
119
|
|
|
* @action site-reviews/route/admin/download-console |
120
|
|
|
*/ |
121
|
|
|
public function downloadConsole() |
122
|
|
|
{ |
123
|
|
|
$this->download(glsr()->id.'-console.txt', glsr(Console::class)->get()); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return void |
128
|
|
|
* @action site-reviews/route/admin/download-system-info |
129
|
|
|
*/ |
130
|
|
|
public function downloadSystemInfo() |
131
|
|
|
{ |
132
|
|
|
$this->download(glsr()->id.'-system-info.txt', glsr(SystemInfo::class)->get()); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return void |
137
|
|
|
* @action site-reviews/route/admin/export-settings |
138
|
|
|
*/ |
139
|
|
|
public function exportSettings() |
140
|
|
|
{ |
141
|
|
|
$this->download(glsr()->id.'-settings.json', glsr(OptionManager::class)->json()); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @return void |
146
|
|
|
* @action site-reviews/route/admin/fetch-console |
147
|
|
|
*/ |
148
|
|
|
public function fetchConsole() |
149
|
|
|
{ |
150
|
|
|
glsr(Notice::class)->addSuccess(_x('Console reloaded.', 'admin-text', 'site-reviews')); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @return void |
155
|
|
|
* @action site-reviews/route/ajax/fetch-console |
156
|
|
|
*/ |
157
|
|
|
public function fetchConsoleAjax() |
158
|
|
|
{ |
159
|
|
|
$this->fetchConsole(); |
160
|
|
|
wp_send_json_success([ |
161
|
|
|
'console' => glsr(Console::class)->get(), |
162
|
|
|
'notices' => glsr(Notice::class)->get(), |
163
|
|
|
]); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return void |
168
|
|
|
* @action site-reviews/route/admin/import-reviews |
169
|
|
|
*/ |
170
|
|
|
public function importReviews(Request $request) |
171
|
|
|
{ |
172
|
|
|
$this->execute(new ImportReviews($request)); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @return void |
177
|
|
|
* @action site-reviews/route/admin/import-settings |
178
|
|
|
*/ |
179
|
|
|
public function importSettings() |
180
|
|
|
{ |
181
|
|
|
$this->execute(new ImportSettings()); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @return void |
186
|
|
|
* @action site-reviews/route/admin/migrate-plugin |
187
|
|
|
*/ |
188
|
|
|
public function migratePlugin(Request $request) |
189
|
|
|
{ |
190
|
|
|
if (wp_validate_boolean($request->alt)) { |
191
|
|
|
glsr(Migrate::class)->runAll(); |
192
|
|
|
glsr(Notice::class)->clear()->addSuccess(_x('All plugin migrations have been run successfully, please reload the page.', 'admin-text', 'site-reviews')); |
193
|
|
|
} else { |
194
|
|
|
glsr(Migrate::class)->run(); |
195
|
|
|
glsr(Notice::class)->clear()->addSuccess(_x('The plugin has been migrated sucessfully, please reload the page.', 'admin-text', 'site-reviews')); |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @return void |
201
|
|
|
* @action site-reviews/route/ajax/migrate-plugin |
202
|
|
|
*/ |
203
|
|
|
public function migratePluginAjax(Request $request) |
204
|
|
|
{ |
205
|
|
|
$this->migratePlugin($request); |
206
|
|
|
wp_send_json_success([ |
207
|
|
|
'notices' => glsr(Notice::class)->get(), |
208
|
|
|
]); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @return void |
213
|
|
|
* @action site-reviews/route/admin/repair-review-relations |
214
|
|
|
*/ |
215
|
|
|
public function repairReviewRelations() |
216
|
|
|
{ |
217
|
|
|
glsr(Database::class)->deleteInvalidReviews(); |
218
|
|
|
glsr(Notice::class)->clear()->addSuccess(_x('The review relationships have been repaired.', 'admin-text', 'site-reviews')); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @return void |
223
|
|
|
* @action site-reviews/route/ajax/repair-review-relations |
224
|
|
|
*/ |
225
|
|
|
public function repairReviewRelationsAjax() |
226
|
|
|
{ |
227
|
|
|
$this->repairReviewRelations(); |
228
|
|
|
wp_send_json_success([ |
229
|
|
|
'notices' => glsr(Notice::class)->get(), |
230
|
|
|
]); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* @return void |
235
|
|
|
* @action site-reviews/route/admin/reset-assigned-meta |
236
|
|
|
*/ |
237
|
|
|
public function resetAssignedMeta() |
238
|
|
|
{ |
239
|
|
|
glsr(CountManager::class)->recalculate(); |
240
|
|
|
glsr(Notice::class)->clear()->addSuccess(_x('The assigned meta values have been reset.', 'admin-text', 'site-reviews')); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @return void |
245
|
|
|
* @action site-reviews/route/ajax/reset-assigned-meta |
246
|
|
|
*/ |
247
|
|
|
public function resetAssignedMetaAjax() |
248
|
|
|
{ |
249
|
|
|
$this->resetAssignedMeta(); |
250
|
|
|
wp_send_json_success([ |
251
|
|
|
'notices' => glsr(Notice::class)->get(), |
252
|
|
|
]); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* @return void |
257
|
|
|
* @action site-reviews/route/admin/reset-permissions |
258
|
|
|
*/ |
259
|
|
|
public function resetPermissions(Request $request) |
260
|
|
|
{ |
261
|
|
|
if (wp_validate_boolean($request->alt)) { |
262
|
|
|
glsr(Role::class)->hardResetAll(); |
263
|
|
|
} else { |
264
|
|
|
glsr(Role::class)->resetAll(); |
265
|
|
|
} |
266
|
|
|
glsr(Notice::class)->clear()->addSuccess(_x('The permissions have been reset.', 'admin-text', 'site-reviews')); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* @return void |
271
|
|
|
* @action site-reviews/route/ajax/reset-permissions |
272
|
|
|
*/ |
273
|
|
|
public function resetPermissionsAjax(Request $request) |
274
|
|
|
{ |
275
|
|
|
$this->resetPermissions($request); |
276
|
|
|
$reloadLink = glsr(Builder::class)->a([ |
277
|
|
|
'text' => _x('reload the page', 'admin-text', 'site-reviews'), |
278
|
|
|
'href' => 'javascript:window.location.reload(1)', |
279
|
|
|
]); |
280
|
|
|
glsr(Notice::class)->clear()->addSuccess( |
281
|
|
|
sprintf(_x('The permissions have been reset, please %s for them to take effect.', 'admin-text', 'site-reviews'), $reloadLink) |
282
|
|
|
); |
283
|
|
|
wp_send_json_success([ |
284
|
|
|
'notices' => glsr(Notice::class)->get(), |
285
|
|
|
]); |
286
|
|
|
} |
287
|
|
|
} |
288
|
|
|
|