|
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
|
|
|
$countFetched = count($fetchedInformation); |
|
109
|
|
|
for ($i = 0; $i < $countFetched; $i++) { |
|
110
|
|
|
if (array_key_exists('password', $fetchedInformation[$i])) { |
|
111
|
|
|
$fetchedInformation[$i]['password'] = '-'; |
|
112
|
|
|
} |
|
113
|
|
|
if (array_key_exists('admin_password', $fetchedInformation[$i])) { |
|
114
|
|
|
$fetchedInformation[$i]['admin_password'] = '-'; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
return $this->render( |
|
120
|
|
|
'backend/support/databaseQueries.html.twig', ['SQLFlexForm' => $form->createView(), 'suppSQLqueryFlex' => $fetchedInformation] |
|
121
|
|
|
); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @param string $repID |
|
126
|
|
|
* |
|
127
|
|
|
* @return Response |
|
128
|
|
|
* @throws \Oc\Repository\Exception\RecordNotFoundException |
|
129
|
|
|
* @throws \Oc\Repository\Exception\RecordsNotFoundException |
|
130
|
|
|
* @Route("/repCaches/{repID}", name="support_reported_cache") |
|
131
|
|
|
*/ |
|
132
|
|
|
public function list_reported_cache_details(string $repID) |
|
133
|
|
|
: Response { |
|
134
|
|
|
$fetchedReport = $this->cacheReportsRepository->fetchOneBy(['id' => $repID]); |
|
135
|
|
|
|
|
136
|
|
|
$fetchedStatus = $this->cacheStatusRepository->fetchAll(); |
|
137
|
|
|
|
|
138
|
|
|
$fetchedStatusModfied = $this->cacheStatusModifiedRepository->fetchBy(['cache_id' => $fetchedReport->cacheid]); |
|
139
|
|
|
|
|
140
|
|
|
return $this->render( |
|
141
|
|
|
'backend/support/reportedCacheDetails.html.twig', [ |
|
142
|
|
|
'reported_cache_by_id' => $fetchedReport, |
|
143
|
|
|
'cache_status' => $fetchedStatus, |
|
144
|
|
|
'report_status_modified' => $fetchedStatusModfied |
|
145
|
|
|
] |
|
146
|
|
|
); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @return array |
|
151
|
|
|
* @throws \Oc\Repository\Exception\RecordsNotFoundException |
|
152
|
|
|
*/ |
|
153
|
|
|
public function getReportedCaches() |
|
154
|
|
|
: array |
|
155
|
|
|
{ |
|
156
|
|
|
return $this->cacheReportsRepository->fetchAll(); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @param int $days |
|
161
|
|
|
* |
|
162
|
|
|
* @return Response |
|
163
|
|
|
* @Route("/dbQueries1/{days}", name="support_db_queries_1") |
|
164
|
|
|
*/ |
|
165
|
|
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. |
|
|
|
|
|
|
166
|
|
|
: Response |
|
167
|
|
|
{ |
|
168
|
|
|
$qb = $this->connection->createQueryBuilder(); |
|
169
|
|
|
$qb->select('caches.name', 'user.username', 'user.date_created', 'user.last_login') |
|
170
|
|
|
->from('caches') |
|
171
|
|
|
->innerJoin('caches', 'user', 'user', 'caches.user_id = user.user_id') |
|
172
|
|
|
->where('user.date_created > now() - interval :searchTerm DAY') |
|
173
|
|
|
->andWhere('caches.user_id = user.user_id') |
|
174
|
|
|
->setParameters(['searchTerm' => $days]) |
|
175
|
|
|
->orderBy('date_created', 'DESC'); |
|
176
|
|
|
|
|
177
|
|
|
return $this->render('backend/support/databaseQueries.html.twig', ['suppSQLquery1' => $qb->execute()->fetchAll()]); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* @param int $days |
|
182
|
|
|
* |
|
183
|
|
|
* @return Response |
|
184
|
|
|
* @Route("/dbQueries2/{days}", name="support_db_queries_2") |
|
185
|
|
|
*/ |
|
186
|
|
|
public function executeSQL_old_reg_date(int $days) // List user whose registration date is no older than x days. |
|
187
|
|
|
: Response |
|
188
|
|
|
{ |
|
189
|
|
|
$qb = $this->connection->createQueryBuilder(); |
|
190
|
|
|
$qb->select('username', 'date_created', 'last_login') |
|
191
|
|
|
->from('user') |
|
192
|
|
|
->where('date_created > now() - interval :searchTerm DAY') |
|
193
|
|
|
->setParameters(['searchTerm' => $days]) |
|
194
|
|
|
->orderBy('date_created', 'DESC'); |
|
195
|
|
|
|
|
196
|
|
|
return $this->render('backend/support/databaseQueries.html.twig', ['suppSQLquery2' => $qb->execute()->fetchAll()]); |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* @return Response |
|
201
|
|
|
* @Route("/dbQueries4", name="support_db_queries_4") |
|
202
|
|
|
*/ |
|
203
|
|
View Code Duplication |
public function executeSQL_caches_old_login_date( |
|
|
|
|
|
|
204
|
|
|
) // List (non-archived, non-locked) caches from users whose last login date is older than one year. |
|
205
|
|
|
: Response |
|
206
|
|
|
{ |
|
207
|
|
|
$qb = $this->connection->createQueryBuilder(); |
|
208
|
|
|
$qb->select('caches.name', 'caches.cache_id', 'caches.status', 'user.username', 'user.last_login') |
|
209
|
|
|
->from('caches') |
|
210
|
|
|
->innerJoin('caches', 'user', 'user', 'caches.user_id = user.user_id') |
|
211
|
|
|
->where('user.last_login < now() - interval :searchTerm YEAR') |
|
212
|
|
|
->andWhere('caches.status <= 2') |
|
213
|
|
|
->andWhere(('caches.user_id = user.user_id')) |
|
214
|
|
|
->setParameters(['searchTerm' => 1]) |
|
215
|
|
|
->orderBy('user.last_login', 'ASC'); |
|
216
|
|
|
|
|
217
|
|
|
return $this->render('backend/support/databaseQueries.html.twig', ['suppSQLquery4' => $qb->execute()->fetchAll()]); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* @param string $what |
|
222
|
|
|
* @param string $table |
|
223
|
|
|
* |
|
224
|
|
|
* @return array |
|
225
|
|
|
*/ |
|
226
|
|
|
public function executeSQL_flexible(string $what, string $table) |
|
227
|
|
|
: array { |
|
228
|
|
|
$qb = $this->connection->createQueryBuilder(); |
|
229
|
|
|
$qb->select($what) |
|
230
|
|
|
->from($table); |
|
231
|
|
|
|
|
232
|
|
|
return ($qb->execute()->fetchAll()); |
|
233
|
|
|
} |
|
234
|
|
|
} |
|
235
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.