Skip to content

Commit 5391167

Browse files
committed
Merge #20166 - Fix #20152 - XML import when structure is present
Pull-request: #20166 Fixes: #20152 Signed-off-by: William Desportes <williamdes@wdes.fr>
2 parents 015d75c + ded6f99 commit 5391167

2 files changed

Lines changed: 9 additions & 30 deletions

File tree

src/Plugins/Import/ImportXml.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,11 @@ public function doImport(File|null $importHandle = null): array
202202
}
203203

204204
/**
205-
* Only build SQL from data if there is data present.
205+
* Only build SQL from data if there is data present and no structure.
206206
* Set values to NULL if they were not present
207207
* to maintain Import::buildSql() call integrity
208208
*/
209-
if ($tables !== [] && $analyses === null) {
209+
if (! $structPresent && $tables !== []) {
210210
$create = null;
211211
}
212212

tests/unit/Plugins/Import/ImportXmlTest.php

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,9 @@ public function testDoImport(): void
9595
$importXml = $this->getImportXml($dbi);
9696
$importXml->doImport($importHandle);
9797

98-
// If import successfully, PMA will show all databases and tables
99-
// imported as following HTML Page
100-
/*
101-
The following structures have either been created or altered. Here you
102-
can:
103-
View a structure's contents by clicking on its name
104-
Change any of its settings by clicking the corresponding "Options" link
105-
Edit structure by following the "Structure" link
106-
107-
phpmyadmintest (Options)
108-
pma_bookmarktest (Structure) (Options)
109-
*/
110-
11198
//assert that all sql are executed
11299
self::assertSame(
113-
'CREATE DATABASE IF NOT EXISTS `phpmyadmintest` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;'
100+
'CREATE DATABASE IF NOT EXISTS `phpmyadmintest` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;'
114101
. 'USE `phpmyadmintest`;' . "\n"
115102
. 'CREATE TABLE IF NOT EXISTS `pma_bookmarktest` (' . "\n"
116103
. ' `id` int(11) NOT NULL AUTO_INCREMENT,' . "\n"
@@ -122,18 +109,11 @@ public function testDoImport(): void
122109
. ') ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT=\'Bookmarks\';' . "\n"
123110
. ' ;'
124111
. 'INSERT INTO `phpmyadmintest`.`pma_bookmarktest` (`id`, `dbase`, `user`, `label`, `query`) '
125-
. 'VALUES (, \'\', \'\', \'\', \'\');;',
112+
. 'VALUES (1, , , , );',
126113
Current::$sqlQuery,
127114
);
128115

129-
self::assertStringContainsString(
130-
'The following structures have either been created or altered.',
131-
ImportSettings::$importNotice,
132-
);
133-
self::assertStringContainsString('Go to database: `phpmyadmintest`', ImportSettings::$importNotice);
134-
self::assertStringContainsString('Edit settings for `phpmyadmintest`', ImportSettings::$importNotice);
135116
self::assertStringContainsString('Go to table: `pma_bookmarktest`', ImportSettings::$importNotice);
136-
self::assertStringContainsString('Edit settings for `pma_bookmarktest`', ImportSettings::$importNotice);
137117
self::assertTrue(ImportSettings::$finished);
138118
}
139119

@@ -163,8 +143,9 @@ public function testDoImportDataset2(): void
163143
$importXml = $this->getImportXml($dbi);
164144
$importXml->doImport($importHandle);
165145

146+
//assert that all sql are executed
166147
self::assertSame(
167-
'CREATE DATABASE IF NOT EXISTS `phpmyadmintest` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;'
148+
'CREATE DATABASE IF NOT EXISTS `phpmyadmintest` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;'
168149
. 'USE `phpmyadmintest`;' . "\n"
169150
. 'CREATE TABLE IF NOT EXISTS `pma_bookmarktest` (' . "\n"
170151
. ' `id` int(11) NOT NULL AUTO_INCREMENT,' . "\n"
@@ -176,18 +157,16 @@ public function testDoImportDataset2(): void
176157
. ') ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT=\'Bookmarks\';' . "\n"
177158
. ' ;'
178159
. 'INSERT INTO `phpmyadmintest`.`pma_bookmarktest` (`id`, `dbase`, `user`, `label`, `query`) '
179-
. 'VALUES (, \'\', \'\', \'\', \'\');;',
160+
. 'VALUES (1, , , , );',
180161
Current::$sqlQuery,
181162
);
182163

183164
self::assertStringContainsString(
184165
'The following structures have either been created or altered.',
185166
ImportSettings::$importNotice,
186167
);
187-
self::assertStringContainsString('Go to database: `test`', ImportSettings::$importNotice);
188-
self::assertStringContainsString('Edit settings for `test`', ImportSettings::$importNotice);
189-
self::assertStringContainsString('Go to table: `test`', ImportSettings::$importNotice);
190-
self::assertStringContainsString('Edit settings for `test`', ImportSettings::$importNotice);
168+
169+
self::assertStringContainsString('Go to table: `pma_bookmarktest`', ImportSettings::$importNotice);
191170
self::assertTrue(ImportSettings::$finished);
192171
}
193172
}

0 commit comments

Comments
 (0)