From 85b1272a92532061e61491233ccddb125ba24499 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Thu, 25 Jan 2024 17:40:02 +0100 Subject: [PATCH 1/3] Fix import of empty tables from MediaWiki Signed-off-by: Kamil Tekiela --- libraries/classes/Import.php | 4 ++ .../Plugins/Import/ImportMediawiki.php | 6 ++- psalm-baseline.xml | 15 +++--- .../Plugins/Import/ImportMediawikiTest.php | 47 +++++++++++++++++++ test/test_data/__slashes.mediawiki | 12 +++++ 5 files changed, 75 insertions(+), 9 deletions(-) create mode 100644 test/test_data/__slashes.mediawiki diff --git a/libraries/classes/Import.php b/libraries/classes/Import.php index 48eccd25b0..a9146782fa 100644 --- a/libraries/classes/Import.php +++ b/libraries/classes/Import.php @@ -1125,6 +1125,10 @@ class Import $numCols = count($tables[$i][self::COL_NAMES]); $numRows = count($tables[$i][self::ROWS]); + if ($numRows === 0) { + break; + } + $tempSQLStr = 'INSERT INTO ' . Util::backquote($dbName) . '.' . Util::backquote($tables[$i][self::TBL_NAME]) . ' ('; diff --git a/libraries/classes/Plugins/Import/ImportMediawiki.php b/libraries/classes/Plugins/Import/ImportMediawiki.php index 17bfd6ac1d..6e7733613e 100644 --- a/libraries/classes/Plugins/Import/ImportMediawiki.php +++ b/libraries/classes/Plugins/Import/ImportMediawiki.php @@ -302,8 +302,10 @@ class ImportMediawiki extends ImportPlugin // Set the table name $this->setTableName($table[0]); - // Set generic names for table headers if they don't exist - $this->setTableHeaders($table[1], $table[2][0]); + // Set generic names for table headers if they don't exist and the table has some data + if ($table[2] !== []) { + $this->setTableHeaders($table[1], $table[2][0]); + } // Create the tables array to be used in Import::buildSql() $tables = []; diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 6fdeed3ccb..0dc4954bdf 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -3056,14 +3056,9 @@ - - $rows + $start - - $_REQUEST['pos'] - $_REQUEST['session_max_rows'] - $db $db @@ -3079,6 +3074,11 @@ $url_params['db'] + + $_REQUEST['pos'] + $_REQUEST['session_max_rows'] + $rows + $_REQUEST['pos'] $_REQUEST['pos'] @@ -16133,7 +16133,8 @@ - + + $import_notice $import_notice diff --git a/test/classes/Plugins/Import/ImportMediawikiTest.php b/test/classes/Plugins/Import/ImportMediawikiTest.php index 7c2423609b..791773f435 100644 --- a/test/classes/Plugins/Import/ImportMediawikiTest.php +++ b/test/classes/Plugins/Import/ImportMediawikiTest.php @@ -125,4 +125,51 @@ class ImportMediawikiTest extends AbstractTestCase $this->assertStringContainsString('Edit settings for `pma_bookmarktest`', $import_notice); $this->assertTrue($GLOBALS['finished']); } + + /** + * Test for doImport + * + * @group medium + */ + public function testDoImportWithEmptyTable(): void + { + //$import_notice will show the import detail result + global $import_notice; + + //Mock DBI + $dbi = $this->getMockBuilder(DatabaseInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $GLOBALS['dbi'] = $dbi; + + $importHandle = new File('test/test_data/__slashes.mediawiki'); + $importHandle->open(); + + //Test function called + $this->object->doImport($importHandle); + + // If import successfully, PMA will show all databases and + // tables imported as following HTML Page + /* + The following structures have either been created or altered. Here you + can: + View a structure's contents by clicking on its name + Change any of its settings by clicking the corresponding "Options" link + Edit structure by following the "Structure" link + + mediawiki_DB (Options) + pma_bookmarktest (Structure) (Options) + */ + + //asset that all databases and tables are imported + $this->assertStringContainsString( + 'The following structures have either been created or altered.', + $import_notice + ); + $this->assertStringContainsString('Go to database: `mediawiki_DB`', $import_notice); + $this->assertStringContainsString('Edit settings for `mediawiki_DB`', $import_notice); + $this->assertStringContainsString('Go to table: `empty`', $import_notice); + $this->assertStringContainsString('Edit settings for `empty`', $import_notice); + $this->assertTrue($GLOBALS['finished']); + } } diff --git a/test/test_data/__slashes.mediawiki b/test/test_data/__slashes.mediawiki new file mode 100644 index 0000000000..6d2b6bc381 --- /dev/null +++ b/test/test_data/__slashes.mediawiki @@ -0,0 +1,12 @@ + + + +{| class="wikitable sortable" style="text-align:center;" +|+'''empty''' +|- + ! \'table + ! \\column +|} + From 54a57da5c745c4f2d7084842f31dc866cd47593c Mon Sep 17 00:00:00 2001 From: sebastians17 Date: Mon, 5 Feb 2024 08:27:21 +0000 Subject: [PATCH 2/3] Translated using Weblate (Polish) Currently translated at 86.6% (2969 of 3427 strings) [ci skip] Translation: phpMyAdmin/5.2 Translate-URL: https://hosted.weblate.org/projects/phpmyadmin/5-2/pl/ Signed-off-by: sebastians17 --- po/pl.po | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/po/pl.po b/po/pl.po index f28c84e67d..1dc052ab3d 100644 --- a/po/pl.po +++ b/po/pl.po @@ -4,8 +4,8 @@ msgstr "" "Project-Id-Version: phpMyAdmin 5.2.2-dev\n" "Report-Msgid-Bugs-To: translators@phpmyadmin.net\n" "POT-Creation-Date: 2023-11-12 15:23-0300\n" -"PO-Revision-Date: 2023-12-11 09:06+0000\n" -"Last-Translator: Adrian Wanic \n" +"PO-Revision-Date: 2024-02-05 13:10+0000\n" +"Last-Translator: sebastians17 \n" "Language-Team: Polish \n" "Language: pl\n" @@ -14,7 +14,7 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 " "|| n%100>=20) ? 1 : 2;\n" -"X-Generator: Weblate 5.3-dev\n" +"X-Generator: Weblate 5.4-dev\n" #: libraries/advisory_rules_generic.php:9 msgid "Uptime below one day" @@ -5945,7 +5945,6 @@ msgid "Total memory" msgstr "Pamięć ogółem" #: libraries/classes/Controllers/JavaScriptMessagesController.php:176 -#, fuzzy msgid "Cached memory" msgstr "Pamięć podręczna" @@ -10853,10 +10852,8 @@ msgid "The table name is empty!" msgstr "Nazwa tabeli jest pusta!" #: libraries/classes/Partitioning/Maintenance.php:141 -#, fuzzy -#| msgid "This is a read-only variable and can not be edited" msgid "This table is a view, it can not be truncated." -msgstr "Jest to zmienna tylko do odczytu i nie można jej edytować" +msgstr "Ta tabela jest tylko do odczytu, i nie można jej wyczyścić." #: libraries/classes/Pdf.php:136 #, fuzzy From 7759ec30dbb206b42e94fff880e8c4bd5bbaf660 Mon Sep 17 00:00:00 2001 From: Szymon Burnejko Date: Wed, 7 Feb 2024 23:05:03 +0000 Subject: [PATCH 3/3] Translated using Weblate (Polish) Currently translated at 86.6% (2969 of 3427 strings) [ci skip] Translation: phpMyAdmin/5.2 Translate-URL: https://hosted.weblate.org/projects/phpmyadmin/5-2/pl/ Signed-off-by: Szymon Burnejko --- po/pl.po | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/po/pl.po b/po/pl.po index 1dc052ab3d..46bdc6b6ad 100644 --- a/po/pl.po +++ b/po/pl.po @@ -4,8 +4,8 @@ msgstr "" "Project-Id-Version: phpMyAdmin 5.2.2-dev\n" "Report-Msgid-Bugs-To: translators@phpmyadmin.net\n" "POT-Creation-Date: 2023-11-12 15:23-0300\n" -"PO-Revision-Date: 2024-02-05 13:10+0000\n" -"Last-Translator: sebastians17 \n" +"PO-Revision-Date: 2024-02-09 00:01+0000\n" +"Last-Translator: Szymon Burnejko \n" "Language-Team: Polish \n" "Language: pl\n"