Skip to content

Commit 772648a

Browse files
committed
Use DatabaseName object for ExportRelationSchema::$db
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 785f8c1 commit 772648a

14 files changed

Lines changed: 53 additions & 56 deletions

libraries/classes/Plugins/Schema/Dia/DiaRelationSchema.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace PhpMyAdmin\Plugins\Schema\Dia;
99

10+
use PhpMyAdmin\Dbal\DatabaseName;
1011
use PhpMyAdmin\Plugins\Schema\ExportRelationSchema;
1112

1213
use function in_array;
@@ -55,10 +56,8 @@ class DiaRelationSchema extends ExportRelationSchema
5556
* @see Dia
5657
* @see TableStatsDia
5758
* @see RelationStatsDia
58-
*
59-
* @param string $db database name
6059
*/
61-
public function __construct($db)
60+
public function __construct(DatabaseName $db)
6261
{
6362
parent::__construct($db, new Dia());
6463

@@ -85,7 +84,7 @@ public function __construct($db)
8584

8685
$this->tables[$table] = new TableStatsDia(
8786
$this->diagram,
88-
$this->db,
87+
$this->db->getName(),
8988
$table,
9089
$this->pageNumber,
9190
$this->showKeys,
@@ -95,7 +94,7 @@ public function __construct($db)
9594

9695
$seen_a_relation = false;
9796
foreach ($alltables as $one_table) {
98-
$exist_rel = $this->relation->getForeigners($this->db, $one_table, '', 'both');
97+
$exist_rel = $this->relation->getForeigners($this->db->getName(), $one_table, '', 'both');
9998
if (! $exist_rel) {
10099
continue;
101100
}
@@ -174,7 +173,7 @@ private function addRelation(
174173
if (! isset($this->tables[$masterTable])) {
175174
$this->tables[$masterTable] = new TableStatsDia(
176175
$this->diagram,
177-
$this->db,
176+
$this->db->getName(),
178177
$masterTable,
179178
$this->pageNumber,
180179
$showKeys
@@ -184,7 +183,7 @@ private function addRelation(
184183
if (! isset($this->tables[$foreignTable])) {
185184
$this->tables[$foreignTable] = new TableStatsDia(
186185
$this->diagram,
187-
$this->db,
186+
$this->db->getName(),
188187
$foreignTable,
189188
$this->pageNumber,
190189
$showKeys

libraries/classes/Plugins/Schema/Eps/EpsRelationSchema.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace PhpMyAdmin\Plugins\Schema\Eps;
99

10+
use PhpMyAdmin\Dbal\DatabaseName;
1011
use PhpMyAdmin\Plugins\Schema\ExportRelationSchema;
1112
use PhpMyAdmin\Version;
1213

@@ -44,10 +45,8 @@ class EpsRelationSchema extends ExportRelationSchema
4445
* user will be prompted for download as .eps extension
4546
*
4647
* @see Eps
47-
*
48-
* @param string $db database name
4948
*/
50-
public function __construct($db)
49+
public function __construct(DatabaseName $db)
5150
{
5251
parent::__construct($db, new Eps());
5352

@@ -60,7 +59,7 @@ public function __construct($db)
6059
$this->diagram->setTitle(
6160
sprintf(
6261
__('Schema of the %s database - Page %s'),
63-
$this->db,
62+
$this->db->getName(),
6463
$this->pageNumber
6564
)
6665
);
@@ -75,7 +74,7 @@ public function __construct($db)
7574
if (! isset($this->tables[$table])) {
7675
$this->tables[$table] = new TableStatsEps(
7776
$this->diagram,
78-
$this->db,
77+
$this->db->getName(),
7978
$table,
8079
$this->diagram->getFont(),
8180
$this->diagram->getFontSize(),
@@ -96,7 +95,7 @@ public function __construct($db)
9695

9796
$seen_a_relation = false;
9897
foreach ($alltables as $one_table) {
99-
$exist_rel = $this->relation->getForeigners($this->db, $one_table, '', 'both');
98+
$exist_rel = $this->relation->getForeigners($this->db->getName(), $one_table, '', 'both');
10099
if (! $exist_rel) {
101100
continue;
102101
}
@@ -187,7 +186,7 @@ private function addRelation(
187186
if (! isset($this->tables[$masterTable])) {
188187
$this->tables[$masterTable] = new TableStatsEps(
189188
$this->diagram,
190-
$this->db,
189+
$this->db->getName(),
191190
$masterTable,
192191
$font,
193192
$fontSize,
@@ -201,7 +200,7 @@ private function addRelation(
201200
if (! isset($this->tables[$foreignTable])) {
202201
$this->tables[$foreignTable] = new TableStatsEps(
203202
$this->diagram,
204-
$this->db,
203+
$this->db->getName(),
205204
$foreignTable,
206205
$font,
207206
$fontSize,

libraries/classes/Plugins/Schema/ExportRelationSchema.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace PhpMyAdmin\Plugins\Schema;
1010

1111
use PhpMyAdmin\ConfigStorage\Relation;
12+
use PhpMyAdmin\Dbal\DatabaseName;
1213
use PhpMyAdmin\Url;
1314
use PhpMyAdmin\Util;
1415

@@ -23,9 +24,6 @@
2324
*/
2425
class ExportRelationSchema
2526
{
26-
/** @var string */
27-
protected $db;
28-
2927
/** @var Dia\Dia|Eps\Eps|Pdf\Pdf|Svg\Svg|null */
3028
protected $diagram;
3129

@@ -56,12 +54,10 @@ class ExportRelationSchema
5654
protected Relation $relation;
5755

5856
/**
59-
* @param string $db database name
6057
* @param Pdf\Pdf|Svg\Svg|Eps\Eps|Dia\Dia|null $diagram schema diagram
6158
*/
62-
public function __construct($db, $diagram)
59+
public function __construct(protected DatabaseName $db, $diagram)
6360
{
64-
$this->db = $db;
6561
$this->diagram = $diagram;
6662
$this->setPageNumber((int) $_REQUEST['page_number']);
6763
$this->setOffline(isset($_REQUEST['offline_export']));

libraries/classes/Plugins/Schema/Pdf/PdfRelationSchema.php

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace PhpMyAdmin\Plugins\Schema\Pdf;
99

10+
use PhpMyAdmin\Dbal\DatabaseName;
1011
use PhpMyAdmin\Pdf as PdfLib;
1112
use PhpMyAdmin\Plugins\Schema\ExportRelationSchema;
1213
use PhpMyAdmin\Transformations;
@@ -99,11 +100,9 @@ class PdfRelationSchema extends ExportRelationSchema
99100
private Transformations $transformations;
100101

101102
/**
102-
* @see Schema\Pdf
103-
*
104-
* @param string $db database name
103+
* @see Pdf
105104
*/
106-
public function __construct($db)
105+
public function __construct(DatabaseName $db)
107106
{
108107
$this->transformations = new Transformations();
109108

@@ -126,13 +125,13 @@ public function __construct($db)
126125
$this->paper,
127126
$this->pageNumber,
128127
$this->withDoc,
129-
$db
128+
$db->getName()
130129
)
131130
);
132131
$this->diagram->setTitle(
133132
sprintf(
134133
__('Schema of the %s database'),
135-
$this->db
134+
$this->db->getName()
136135
)
137136
);
138137
$this->diagram->setCMargin(0);
@@ -170,7 +169,7 @@ public function __construct($db)
170169
if (! isset($this->tables[$table])) {
171170
$this->tables[$table] = new TableStatsPdf(
172171
$this->diagram,
173-
$this->db,
172+
$this->db->getName(),
174173
$table,
175174
null,
176175
$this->pageNumber,
@@ -215,7 +214,7 @@ public function __construct($db)
215214
// and finding its foreigns is OK (then we can support innodb)
216215
$seen_a_relation = false;
217216
foreach ($alltables as $one_table) {
218-
$exist_rel = $this->relation->getForeigners($this->db, $one_table, '', 'both');
217+
$exist_rel = $this->relation->getForeigners($this->db->getName(), $one_table, '', 'both');
219218
if (! $exist_rel) {
220219
continue;
221220
}
@@ -354,7 +353,7 @@ private function addRelation(
354353
if (! isset($this->tables[$masterTable])) {
355354
$this->tables[$masterTable] = new TableStatsPdf(
356355
$this->diagram,
357-
$this->db,
356+
$this->db->getName(),
358357
$masterTable,
359358
null,
360359
$this->pageNumber,
@@ -368,7 +367,7 @@ private function addRelation(
368367
if (! isset($this->tables[$foreignTable])) {
369368
$this->tables[$foreignTable] = new TableStatsPdf(
370369
$this->diagram,
371-
$this->db,
370+
$this->db->getName(),
372371
$foreignTable,
373372
null,
374373
$this->pageNumber,
@@ -509,7 +508,7 @@ public function dataDictionaryDoc(array $alltables): void
509508
$this->diagram->customLinks['doc'][$table]['-']
510509
);
511510
// $this->diagram->Ln(1);
512-
$fields = $GLOBALS['dbi']->getColumns($this->db, $table);
511+
$fields = $GLOBALS['dbi']->getColumns($this->db->getName(), $table);
513512
foreach ($fields as $row) {
514513
$this->diagram->setX(20);
515514
$field_name = $row['Field'];
@@ -569,15 +568,15 @@ public function dataDictionaryDoc(array $alltables): void
569568
$this->diagram->Ln();
570569

571570
$relationParameters = $this->relation->getRelationParameters();
572-
$comments = $this->relation->getComments($this->db, $table);
571+
$comments = $this->relation->getComments($this->db->getName(), $table);
573572
if ($relationParameters->browserTransformationFeature !== null) {
574-
$mime_map = $this->transformations->getMime($this->db, $table, true);
573+
$mime_map = $this->transformations->getMime($this->db->getName(), $table, true);
575574
}
576575

577576
/**
578577
* Gets table information
579578
*/
580-
$showtable = $GLOBALS['dbi']->getTable($this->db, $table)
579+
$showtable = $GLOBALS['dbi']->getTable($this->db->getName(), $table)
581580
->getStatusInfo();
582581
$show_comment = $showtable['Comment'] ?? '';
583582
$create_time = isset($showtable['Create_time'])
@@ -599,11 +598,11 @@ public function dataDictionaryDoc(array $alltables): void
599598
/**
600599
* Gets fields properties
601600
*/
602-
$columns = $GLOBALS['dbi']->getColumns($this->db, $table);
601+
$columns = $GLOBALS['dbi']->getColumns($this->db->getName(), $table);
603602

604603
// Find which tables are related with the current one and write it in
605604
// an array
606-
$res_rel = $this->relation->getForeigners($this->db, $table);
605+
$res_rel = $this->relation->getForeigners($this->db->getName(), $table);
607606

608607
/**
609608
* Displays the comments of the table if MySQL >= 3.23
@@ -729,7 +728,7 @@ public function dataDictionaryDoc(array $alltables): void
729728
$linksTo = '';
730729
if ($foreigner) {
731730
$linksTo = '-> ';
732-
if ($foreigner['foreign_db'] != $this->db) {
731+
if ($foreigner['foreign_db'] != $this->db->getName()) {
733732
$linksTo .= $foreigner['foreign_db'] . '.';
734733
}
735734

libraries/classes/Plugins/Schema/SchemaDia.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected function setProperties(): SchemaPluginProperties
8383
*/
8484
public function getExportInfo(DatabaseName $db): array
8585
{
86-
$export = new DiaRelationSchema($db->getName());
86+
$export = new DiaRelationSchema($db);
8787
$exportInfo = $export->getExportInfo();
8888

8989
return [

libraries/classes/Plugins/Schema/SchemaEps.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected function setProperties(): SchemaPluginProperties
8484
*/
8585
public function getExportInfo(DatabaseName $db): array
8686
{
87-
$export = new EpsRelationSchema($db->getName());
87+
$export = new EpsRelationSchema($db);
8888
$exportInfo = $export->getExportInfo();
8989

9090
return [

libraries/classes/Plugins/Schema/SchemaPdf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ protected function setProperties(): SchemaPluginProperties
118118
*/
119119
public function getExportInfo(DatabaseName $db): array
120120
{
121-
$export = new PdfRelationSchema($db->getName());
121+
$export = new PdfRelationSchema($db);
122122
$exportInfo = $export->getExportInfo();
123123

124124
return [

libraries/classes/Plugins/Schema/SchemaSvg.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected function setProperties(): SchemaPluginProperties
7171
*/
7272
public function getExportInfo(DatabaseName $db): array
7373
{
74-
$export = new SvgRelationSchema($db->getName());
74+
$export = new SvgRelationSchema($db);
7575
$exportInfo = $export->getExportInfo();
7676

7777
return [

libraries/classes/Plugins/Schema/Svg/SvgRelationSchema.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace PhpMyAdmin\Plugins\Schema\Svg;
99

10+
use PhpMyAdmin\Dbal\DatabaseName;
1011
use PhpMyAdmin\Plugins\Schema\Dia\TableStatsDia;
1112
use PhpMyAdmin\Plugins\Schema\Eps\TableStatsEps;
1213
use PhpMyAdmin\Plugins\Schema\ExportRelationSchema;
@@ -60,11 +61,9 @@ class SvgRelationSchema extends ExportRelationSchema
6061
* Upon instantiation This starts writing the SVG XML document
6162
* user will be prompted for download as .svg extension
6263
*
63-
* @see PMA_SVG
64-
*
65-
* @param string $db database name
64+
* @see Svg
6665
*/
67-
public function __construct($db)
66+
public function __construct(DatabaseName $db)
6867
{
6968
parent::__construct($db, new Svg());
7069

@@ -76,7 +75,7 @@ public function __construct($db)
7675
$this->diagram->setTitle(
7776
sprintf(
7877
__('Schema of the %s database - Page %s'),
79-
$this->db,
78+
$this->db->getName(),
8079
$this->pageNumber
8180
)
8281
);
@@ -90,7 +89,7 @@ public function __construct($db)
9089
if (! isset($this->tables[$table])) {
9190
$this->tables[$table] = new TableStatsSvg(
9291
$this->diagram,
93-
$this->db,
92+
$this->db->getName(),
9493
$table,
9594
$this->diagram->getFont(),
9695
$this->diagram->getFontSize(),
@@ -119,7 +118,7 @@ public function __construct($db)
119118

120119
$seen_a_relation = false;
121120
foreach ($alltables as $one_table) {
122-
$exist_rel = $this->relation->getForeigners($this->db, $one_table, '', 'both');
121+
$exist_rel = $this->relation->getForeigners($this->db->getName(), $one_table, '', 'both');
123122
if (! $exist_rel) {
124123
continue;
125124
}
@@ -222,7 +221,7 @@ private function addRelation(
222221
if (! isset($this->tables[$masterTable])) {
223222
$this->tables[$masterTable] = new TableStatsSvg(
224223
$this->diagram,
225-
$this->db,
224+
$this->db->getName(),
226225
$masterTable,
227226
$font,
228227
$fontSize,
@@ -237,7 +236,7 @@ private function addRelation(
237236
if (! isset($this->tables[$foreignTable])) {
238237
$this->tables[$foreignTable] = new TableStatsSvg(
239238
$this->diagram,
240-
$this->db,
239+
$this->db->getName(),
241240
$foreignTable,
242241
$font,
243242
$fontSize,

test/classes/Plugins/Schema/DiaRelationSchemaTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpMyAdmin\Tests\Plugins\Schema;
66

7+
use PhpMyAdmin\Dbal\DatabaseName;
78
use PhpMyAdmin\Plugins\Schema\Dia\DiaRelationSchema;
89
use PhpMyAdmin\Tests\AbstractTestCase;
910

@@ -40,7 +41,7 @@ protected function setUp(): void
4041
$GLOBALS['db'] = 'test_db';
4142
$GLOBALS['cfg']['Server']['DisableIS'] = true;
4243

43-
$this->object = new DiaRelationSchema('test_db');
44+
$this->object = new DiaRelationSchema(DatabaseName::fromValue('test_db'));
4445
}
4546

4647
/**

0 commit comments

Comments
 (0)