forked from phpmyadmin/phpmyadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckRelationsController.php
More file actions
70 lines (55 loc) · 2.36 KB
/
Copy pathCheckRelationsController.php
File metadata and controls
70 lines (55 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Controllers;
use PhpMyAdmin\Config;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Current;
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Identifiers\DatabaseName;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing\Route;
use PhpMyAdmin\Tracking\Tracker;
use const SQL_DIR;
/**
* Displays status of phpMyAdmin configuration storage
*/
#[Route('/check-relations', ['GET', 'POST'])]
final readonly class CheckRelationsController implements InvocableController
{
public function __construct(private ResponseRenderer $response, private Relation $relation, private Config $config)
{
}
public function __invoke(ServerRequest $request): Response
{
$cfgStorageDbName = $this->relation->getConfigurationStorageDbName();
$db = DatabaseName::tryFrom(Current::$database);
// Disable tracking as it requires a working configuration storage.
Tracker::disable();
// If request for creating the pmadb
if ($request->hasBodyParam('create_pmadb') && $this->relation->createPmaDatabase($cfgStorageDbName)) {
$this->relation->fixPmaTables($cfgStorageDbName);
}
// If request for creating all PMA tables.
if ($request->hasBodyParam('fixall_pmadb') && $db !== null) {
$this->relation->fixPmaTables($db->getName());
}
// If request for creating missing PMA tables.
if ($request->hasBodyParam('fix_pmadb')) {
$relationParameters = $this->relation->getRelationParameters();
$this->relation->fixPmaTables((string) $relationParameters->db);
}
// Do not use any previous $relationParameters value as it could have changed after a successful fixPmaTables()
$relationParameters = $this->relation->getRelationParameters();
Tracker::enable();
$this->response->render('relation/check_relations', [
'db' => $db?->getName() ?? '',
'zero_conf' => $this->config->settings['ZeroConf'],
'relation_parameters' => $relationParameters->toArray(),
'sql_dir' => SQL_DIR,
'config_storage_database_name' => $cfgStorageDbName,
'are_config_storage_tables_defined' => $this->relation->arePmadbTablesDefined(),
]);
return $this->response->response();
}
}