|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Oc\Controller\Backend; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Connection; |
|
8
|
|
|
use Oc\Form\SupportSQLFlexForm; |
|
9
|
|
|
use Oc\Repository\CacheReportsRepository; |
|
10
|
|
|
use Oc\Repository\CacheStatusModifiedRepository; |
|
11
|
|
|
use Oc\Repository\CacheStatusRepository; |
|
12
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
14
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
15
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class SupportController |
|
19
|
|
|
* |
|
20
|
|
|
* @package Oc\Controller\Backend |
|
21
|
|
|
*/ |
|
22
|
|
|
class SupportController extends AbstractController |
|
23
|
|
|
{ |
|
24
|
|
|
/** @var Connection */ |
|
25
|
|
|
private $connection; |
|
26
|
|
|
|
|
27
|
|
|
/** @var CacheReportsRepository */ |
|
28
|
|
|
private $cacheReportsRepository; |
|
29
|
|
|
|
|
30
|
|
|
/** @var CacheStatusModifiedRepository */ |
|
31
|
|
|
private $cacheStatusModifiedRepository; |
|
32
|
|
|
|
|
33
|
|
|
/** @var CacheStatusRepository */ |
|
34
|
|
|
private $cacheStatusRepository; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* SupportController constructor. |
|
38
|
|
|
* |
|
39
|
|
|
* @param Connection $connection |
|
40
|
|
|
* @param CacheReportsRepository $cacheReportsRepository |
|
41
|
|
|
* @param CacheStatusModifiedRepository $cacheStatusModifiedRepository |
|
42
|
|
|
* @param CacheStatusRepository $cacheStatusRepository |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct( |
|
45
|
|
|
Connection $connection, |
|
46
|
|
|
CacheReportsRepository $cacheReportsRepository, |
|
47
|
|
|
CacheStatusModifiedRepository $cacheStatusModifiedRepository, |
|
48
|
|
|
CacheStatusRepository $cacheStatusRepository |
|
49
|
|
|
) { |
|
50
|
|
|
$this->connection = $connection; |
|
51
|
|
|
$this->cacheReportsRepository = $cacheReportsRepository; |
|
52
|
|
|
$this->cacheStatusModifiedRepository = $cacheStatusModifiedRepository; |
|
53
|
|
|
$this->cacheStatusRepository = $cacheStatusRepository; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return Response |
|
58
|
|
|
* @Route("/support", name="support_index") |
|
59
|
|
|
*/ |
|
60
|
|
|
public function index() |
|
61
|
|
|
: Response |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->render('backend/support/index.html.twig'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return Response |
|
68
|
|
|
* @Route("/supportSearch", name="support_search") |
|
69
|
|
|
*/ |
|
70
|
|
|
public function serchCachesAndUser() |
|
71
|
|
|
: Response |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->render('backend/support/KOMMTDEMNAECHST.html.twig'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return Response |
|
78
|
|
|
* @throws \Oc\Repository\Exception\RecordsNotFoundException |
|
79
|
|
|
* @Route("/reportedCaches", name="support_reported_caches") |
|
80
|
|
|
*/ |
|
81
|
|
|
public function listReportedCaches() |
|
82
|
|
|
: Response |
|
83
|
|
|
{ |
|
84
|
|
|
$fetchedReports = $this->getReportedCaches(); |
|
85
|
|
|
|
|
86
|
|
|
return $this->render('backend/support/reportedCaches.html.twig', ['reportedCaches_by_id' => $fetchedReports]); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param Request $request |
|
91
|
|
|
* |
|
92
|
|
|
* @return Response |
|
93
|
|
|
* @Route("/dbQueries", name="support_db_queries") |
|
94
|
|
|
*/ |
|
95
|
|
|
public function listDbQueries(Request $request) |
|
96
|
|
|
: Response { |
|
97
|
|
|
$fetchedInformation = []; |
|
98
|
|
|
|
|
99
|
|
|
$form = $this->createForm(SupportSQLFlexForm::class); |
|
100
|
|
|
|
|
101
|
|
|
$form->handleRequest($request); |
|
102
|
|
|
|
|
103
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
104
|
|
|
$inputData = $form->getData(); |
|
105
|
|
|
|
|
106
|
|
|
$fetchedInformation = $this->executeSQL_flexible($inputData['content_WHAT'], $inputData['content_TABLE']); |
|
107
|
|
|
|
|
108
|
|
|
for ($i = 0; $i < count($fetchedInformation); $i ++) { |
|
|
|
|
|
|
109
|
|
|
if (array_key_exists('password', $fetchedInformation[$i])) { |
|
110
|
|
|
$fetchedInformation[$i]['password'] = '-'; |
|
111
|
|
|
} |
|
112
|
|
|
if (array_key_exists('admin_password', $fetchedInformation[$i])) { |
|
113
|
|
|
$fetchedInformation[$i]['admin_password'] = '-'; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
// dd($fetchedInformation); |
|
117
|
|
|
// die(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
return $this->render( |
|
121
|
|
|
'backend/support/databaseQueries.html.twig', ['SQLFlexForm' => $form->createView(), 'suppSQLqueryFlex' => $fetchedInformation] |
|
122
|
|
|
); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @param string $repID |
|
127
|
|
|
* |
|
128
|
|
|
* @return Response |
|
129
|
|
|
* @throws \Oc\Repository\Exception\RecordNotFoundException |
|
130
|
|
|
* @throws \Oc\Repository\Exception\RecordsNotFoundException |
|
131
|
|
|
* @Route("/repCaches/{repID}", name="support_reported_cache") |
|
132
|
|
|
*/ |
|
133
|
|
|
public function list_reported_cache_details(string $repID) |
|
134
|
|
|
: Response { |
|
135
|
|
|
$fetchedReport = $this->cacheReportsRepository->fetchOneBy(['id' => $repID]); |
|
136
|
|
|
|
|
137
|
|
|
$fetchedStatus = $this->cacheStatusRepository->fetchAll(); |
|
138
|
|
|
|
|
139
|
|
|
$fetchedStatusModfied = $this->cacheStatusModifiedRepository->fetchBy(['cache_id' => $fetchedReport->cacheid]); |
|
140
|
|
|
|
|
141
|
|
|
return $this->render( |
|
142
|
|
|
'backend/support/reportedCacheDetails.html.twig', [ |
|
143
|
|
|
'reported_cache_by_id' => $fetchedReport, |
|
144
|
|
|
'cache_status' => $fetchedStatus, |
|
145
|
|
|
'report_status_modified' => $fetchedStatusModfied |
|
146
|
|
|
] |
|
147
|
|
|
); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @return array |
|
152
|
|
|
* @throws \Oc\Repository\Exception\RecordsNotFoundException |
|
153
|
|
|
*/ |
|
154
|
|
|
public function getReportedCaches() |
|
155
|
|
|
: array |
|
156
|
|
|
{ |
|
157
|
|
|
return $this->cacheReportsRepository->fetchAll(); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @param int $days |
|
162
|
|
|
* |
|
163
|
|
|
* @return Response |
|
164
|
|
|
* @Route("/dbQueries1/{days}", name="support_db_queries_1") |
|
165
|
|
|
*/ |
|
166
|
|
View Code Duplication |
public function executeSQL_caches_old_reg_date(int $days = 31) // List caches from users whose registration date is not older than x days. |
|
|
|
|
|
|
167
|
|
|
: Response |
|
168
|
|
|
{ |
|
169
|
|
|
$qb = $this->connection->createQueryBuilder(); |
|
170
|
|
|
$qb->select('caches.name', 'user.username', 'user.date_created', 'user.last_login') |
|
171
|
|
|
->from('caches') |
|
172
|
|
|
->innerJoin('caches', 'user', 'user', 'caches.user_id = user.user_id') |
|
173
|
|
|
->where('user.date_created > now() - interval :searchTerm DAY') |
|
174
|
|
|
->andWhere('caches.user_id = user.user_id') |
|
175
|
|
|
->setParameters(['searchTerm' => $days]) |
|
176
|
|
|
->orderBy('date_created', 'DESC'); |
|
177
|
|
|
|
|
178
|
|
|
return $this->render('backend/support/databaseQueries.html.twig', ['suppSQLquery1' => $qb->execute()->fetchAll()]); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* @param int $days |
|
183
|
|
|
* |
|
184
|
|
|
* @return Response |
|
185
|
|
|
* @Route("/dbQueries2/{days}", name="support_db_queries_2") |
|
186
|
|
|
*/ |
|
187
|
|
|
public function executeSQL_old_reg_date(int $days) // List user whose registration date is no older than x days. |
|
188
|
|
|
: Response |
|
189
|
|
|
{ |
|
190
|
|
|
$qb = $this->connection->createQueryBuilder(); |
|
191
|
|
|
$qb->select('username', 'date_created', 'last_login') |
|
192
|
|
|
->from('user') |
|
193
|
|
|
->where('date_created > now() - interval :searchTerm DAY') |
|
194
|
|
|
->setParameters(['searchTerm' => $days]) |
|
195
|
|
|
->orderBy('date_created', 'DESC'); |
|
196
|
|
|
|
|
197
|
|
|
return $this->render('backend/support/databaseQueries.html.twig', ['suppSQLquery2' => $qb->execute()->fetchAll()]); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* @return Response |
|
202
|
|
|
* @Route("/dbQueries4", name="support_db_queries_4") |
|
203
|
|
|
*/ |
|
204
|
|
View Code Duplication |
public function executeSQL_caches_old_login_date( |
|
|
|
|
|
|
205
|
|
|
) // List (non-archived, non-locked) caches from users whose last login date is older than one year. |
|
206
|
|
|
: Response |
|
207
|
|
|
{ |
|
208
|
|
|
$qb = $this->connection->createQueryBuilder(); |
|
209
|
|
|
$qb->select('caches.name', 'caches.cache_id', 'caches.status', 'user.username', 'user.last_login') |
|
210
|
|
|
->from('caches') |
|
211
|
|
|
->innerJoin('caches', 'user', 'user', 'caches.user_id = user.user_id') |
|
212
|
|
|
->where('user.last_login < now() - interval :searchTerm YEAR') |
|
213
|
|
|
->andWhere('caches.status <= 2') |
|
214
|
|
|
->andWhere(('caches.user_id = user.user_id')) |
|
215
|
|
|
->setParameters(['searchTerm' => 1]) |
|
216
|
|
|
->orderBy('user.last_login', 'ASC'); |
|
217
|
|
|
|
|
218
|
|
|
return $this->render('backend/support/databaseQueries.html.twig', ['suppSQLquery4' => $qb->execute()->fetchAll()]); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* @param string $what |
|
223
|
|
|
* @param string $table |
|
224
|
|
|
* |
|
225
|
|
|
* @return array |
|
226
|
|
|
*/ |
|
227
|
|
|
public function executeSQL_flexible(string $what, string $table) |
|
228
|
|
|
: array { |
|
229
|
|
|
$qb = $this->connection->createQueryBuilder(); |
|
230
|
|
|
$qb->select($what) |
|
231
|
|
|
->from($table); |
|
232
|
|
|
|
|
233
|
|
|
return ($qb->execute()->fetchAll()); |
|
234
|
|
|
} |
|
235
|
|
|
} |
|
236
|
|
|
|
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: