From 4ed383b0ee4ba1cd4b69d43f475b8b6c6db2ee1c Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Mon, 30 Mar 2020 12:39:53 +0200 Subject: [PATCH 01/20] Initial utf8mb4 support in J4 In J4, the version requirements make sure that MySQL or MariaDB databases support utf8mb4, so we can remove the initial check at new installation and initialize the utf8_conversion table with the right value in joomla.sql. --- installation/sql/mysql/joomla.sql | 2 +- installation/src/Model/DatabaseModel.php | 23 ----------------------- 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/installation/sql/mysql/joomla.sql b/installation/sql/mysql/joomla.sql index 1b013f499bc9d..0eb8c3f75e54a 100644 --- a/installation/sql/mysql/joomla.sql +++ b/installation/sql/mysql/joomla.sql @@ -2259,7 +2259,7 @@ CREATE TABLE IF NOT EXISTS `#__utf8_conversion` ( -- Dumping data for table `#__utf8_conversion` -- -INSERT INTO `#__utf8_conversion` (`converted`) VALUES (0); +INSERT INTO `#__utf8_conversion` (`converted`) VALUES (2); -- -- Table structure for table `#__viewlevels` diff --git a/installation/src/Model/DatabaseModel.php b/installation/src/Model/DatabaseModel.php index 29743f2bca88a..a9d9e596a9a61 100644 --- a/installation/src/Model/DatabaseModel.php +++ b/installation/src/Model/DatabaseModel.php @@ -629,29 +629,6 @@ public function createTables($options) return false; } - // Get query object for later database access - $query = $db->getQuery(true); - - // MySQL only: Attempt to update the table #__utf8_conversion. - if ($serverType === 'mysql') - { - $query->clear() - ->update($db->quoteName('#__utf8_conversion')) - ->set($db->quoteName('converted') . ' = ' . ($db->hasUTF8mb4Support() ? 2 : 1)); - $db->setQuery($query); - - try - { - $db->execute(); - } - catch (\RuntimeException $e) - { - Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); - - return false; - } - } - // Attempt to update the table #__schema. $pathPart = JPATH_ADMINISTRATOR . '/components/com_admin/sql/updates/' . $serverType . '/'; From f39e1c8c81fb06395c24e98ef8c1713ce37ec67d Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Fri, 3 Apr 2020 12:22:25 +0200 Subject: [PATCH 02/20] Remove more obsolete utf8mb4 checks --- administrator/components/com_admin/script.php | 9 +-------- administrator/language/en-GB/com_installer.ini | 1 - libraries/src/Schema/ChangeSet.php | 13 ++----------- 3 files changed, 3 insertions(+), 20 deletions(-) diff --git a/administrator/components/com_admin/script.php b/administrator/components/com_admin/script.php index 8cbeebaa9a0b4..c1a597bd13aa1 100644 --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -6233,14 +6233,7 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false) } // Set required conversion status - if ($db->hasUTF8mb4Support()) - { - $converted = 2; - } - else - { - $converted = 1; - } + $converted = 2; // Check conversion status in database $db->setQuery('SELECT ' . $db->quoteName('converted') diff --git a/administrator/language/en-GB/com_installer.ini b/administrator/language/en-GB/com_installer.ini index e19744ab1d301..4ac903015a689 100644 --- a/administrator/language/en-GB/com_installer.ini +++ b/administrator/language/en-GB/com_installer.ini @@ -124,7 +124,6 @@ COM_INSTALLER_MSG_DATABASE_SCHEMA_ERROR="Database version (%1$s COM_INSTALLER_MSG_DATABASE_SCHEMA_VERSION="Database version (in #__schemas): %s." COM_INSTALLER_MSG_DATABASE_SKIPPED="%s database changes did not alter table structure and were skipped." COM_INSTALLER_MSG_DATABASE_UPDATEVERSION_ERROR="Database update version (%1$s) does not match %2$s version (%3$s)." -COM_INSTALLER_MSG_DATABASE_UTF8_CONVERSION_UTF8="The Joomla! Core database tables have not been converted yet to UTF-8." COM_INSTALLER_MSG_DATABASE_UTF8_CONVERSION_UTF8MB4="The Joomla! Core database tables have not been converted yet to UTF-8 Multibyte (utf8mb4)." COM_INSTALLER_MSG_DESCFTP="For installing or uninstalling Extensions, Joomla will most likely need your FTP account details. Please enter them in the form fields below." COM_INSTALLER_MSG_DESCFTPTITLE="FTP Login Details" diff --git a/libraries/src/Schema/ChangeSet.php b/libraries/src/Schema/ChangeSet.php index fb966de221411..977c3f869d16e 100644 --- a/libraries/src/Schema/ChangeSet.php +++ b/libraries/src/Schema/ChangeSet.php @@ -111,21 +111,12 @@ public function __construct($db, $folder = null) $tmpSchemaChangeItem->checkStatus = 0; // Set the check query - if ($this->db instanceof UTF8MB4SupportInterface && $this->db->hasUTF8mb4Support()) - { - $converted = 2; - $tmpSchemaChangeItem->queryType = 'UTF8_CONVERSION_UTF8MB4'; - } - else - { - $converted = 1; - $tmpSchemaChangeItem->queryType = 'UTF8_CONVERSION_UTF8'; - } + $tmpSchemaChangeItem->queryType = 'UTF8_CONVERSION_UTF8MB4'; $tmpSchemaChangeItem->checkQuery = 'SELECT ' . $this->db->quoteName('converted') . ' FROM ' . $this->db->quoteName('#__utf8_conversion') - . ' WHERE ' . $this->db->quoteName('converted') . ' = ' . $converted; + . ' WHERE ' . $this->db->quoteName('converted') . ' = 2'; // Set expected records from check query $tmpSchemaChangeItem->checkQueryExpected = 1; From e64f4d0b2dbca1fa47e4ff24d01376f8c0bcb989 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Fri, 3 Apr 2020 12:34:13 +0200 Subject: [PATCH 03/20] Remove `#__core_log_searches` and finder tables --- .../others/mysql/utf8mb4-conversion-01.sql | 1 - .../others/mysql/utf8mb4-conversion-02.sql | 57 +------------------ 2 files changed, 1 insertion(+), 57 deletions(-) diff --git a/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-01.sql b/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-01.sql index 843ab1256a981..8a46289ac9a2f 100644 --- a/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-01.sql +++ b/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-01.sql @@ -21,7 +21,6 @@ ALTER TABLE `#__content_types` DROP KEY `idx_alias`; ALTER TABLE `#__fields` DROP KEY `idx_context`; ALTER TABLE `#__fields_groups` DROP KEY `idx_context`; ALTER TABLE `#__fields_values` DROP KEY `idx_item_id`; -ALTER TABLE `#__finder_links` DROP KEY `idx_title`; ALTER TABLE `#__menu` DROP KEY `idx_alias`; ALTER TABLE `#__menu` DROP KEY `idx_client_id_parent_id_alias_language`; ALTER TABLE `#__menu` DROP KEY `idx_path`; diff --git a/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-02.sql b/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-02.sql index 3edcbd3e7978a..54a26a2e09bdf 100644 --- a/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-02.sql +++ b/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-02.sql @@ -33,7 +33,6 @@ ALTER TABLE `#__banners` MODIFY `metakey_prefix` varchar(400) NOT NULL DEFAULT ' ALTER TABLE `#__categories` MODIFY `path` varchar(400) NOT NULL DEFAULT ''; ALTER TABLE `#__categories` MODIFY `alias` varchar(400) NOT NULL DEFAULT ''; ALTER TABLE `#__content_types` MODIFY `type_alias` varchar(400) NOT NULL DEFAULT ''; -ALTER TABLE `#__finder_links` MODIFY `title` varchar(400) DEFAULT NULL; ALTER TABLE `#__contact_details` MODIFY `alias` varchar(400) NOT NULL DEFAULT ''; ALTER TABLE `#__content` MODIFY `alias` varchar(400) NOT NULL DEFAULT ''; ALTER TABLE `#__menu` MODIFY `alias` varchar(400) NOT NULL COMMENT 'The SEF alias of the menu item.'; @@ -47,8 +46,7 @@ ALTER TABLE `#__users` MODIFY `name` varchar(400) NOT NULL DEFAULT ''; -- -- Step 2.2: Convert all tables to utf8mb4 chracter set with utf8mb4_unicode_ci collation --- except #__finder_xxx tables, those will have utf8mb4_general_ci collation. --- Note: The database driver for mysql will change utf8mb4 to utf8 if utf8mb4 is not supported +-- except of #__finder_xxx tables, those are handled with 4.0.0-2018-07-29.sql at update. -- ALTER TABLE `#__assets` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; @@ -63,37 +61,11 @@ ALTER TABLE `#__content_frontpage` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8 ALTER TABLE `#__content_rating` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__content_types` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__contentitem_tag_map` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -ALTER TABLE `#__core_log_searches` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__extensions` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__fields` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__fields_categories` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__fields_groups` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__fields_values` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -ALTER TABLE `#__finder_filters` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_terms0` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_terms1` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_terms2` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_terms3` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_terms4` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_terms5` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_terms6` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_terms7` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_terms8` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_terms9` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_termsa` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_termsb` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_termsc` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_termsd` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_termse` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_termsf` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_taxonomy` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_taxonomy_map` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_terms` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_terms_common` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_tokens` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_tokens_aggregate` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_types` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; ALTER TABLE `#__languages` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__menu` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__menu_types` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; @@ -156,37 +128,11 @@ ALTER TABLE `#__content_frontpage` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4 ALTER TABLE `#__content_rating` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__content_types` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__contentitem_tag_map` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -ALTER TABLE `#__core_log_searches` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__extensions` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__fields` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__fields_categories` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__fields_groups` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__fields_values` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -ALTER TABLE `#__finder_filters` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_terms0` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_terms1` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_terms2` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_terms3` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_terms4` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_terms5` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_terms6` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_terms7` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_terms8` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_terms9` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_termsa` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_termsb` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_termsc` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_termsd` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_termse` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_links_termsf` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_taxonomy` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_taxonomy_map` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_terms` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_terms_common` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_tokens` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_tokens_aggregate` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -ALTER TABLE `#__finder_types` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; ALTER TABLE `#__languages` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__menu` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__menu_types` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; @@ -231,7 +177,6 @@ ALTER TABLE `#__content_types` ADD KEY `idx_alias` (`type_alias`(100)); ALTER TABLE `#__fields` ADD KEY `idx_context` (`context`(191)); ALTER TABLE `#__fields_groups` ADD KEY `idx_context` (`context`(191)); ALTER TABLE `#__fields_values` ADD KEY `idx_item_id` (`item_id`(191)); -ALTER TABLE `#__finder_links` ADD KEY `idx_title` (`title`(100)); ALTER TABLE `#__menu` ADD KEY `idx_alias` (`alias`(100)); ALTER TABLE `#__menu` ADD UNIQUE `idx_client_id_parent_id_alias_language` (`client_id`,`parent_id`,`alias`(100),`language`); ALTER TABLE `#__menu` ADD KEY `idx_path` (`path`(100)); From 1c3cf6dfdeab634878d3229859c551cbd429032f Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sat, 4 Apr 2020 15:09:27 +0200 Subject: [PATCH 04/20] Solve merge conflict --- installation/sql/mysql/base.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation/sql/mysql/base.sql b/installation/sql/mysql/base.sql index 1389fa6f6a839..e0940bc5c4087 100644 --- a/installation/sql/mysql/base.sql +++ b/installation/sql/mysql/base.sql @@ -1017,7 +1017,7 @@ CREATE TABLE IF NOT EXISTS `#__utf8_conversion` ( -- Dumping data for table `#__utf8_conversion` -- -INSERT INTO `#__utf8_conversion` (`converted`) VALUES (0); +INSERT INTO `#__utf8_conversion` (`converted`) VALUES (2); -- -------------------------------------------------------- From ef6900a7b85b749a41f282cc95f0250128ef7dd0 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sun, 5 Apr 2020 16:14:27 +0200 Subject: [PATCH 05/20] No `#__utf8_conversion` table for new installations --- administrator/components/com_admin/script.php | 27 +++++++ installation/sql/mysql/base.sql | 16 ----- .../src/Schema/ChangeItem/MysqlChangeItem.php | 13 ---- libraries/src/Schema/ChangeSet.php | 72 +++++++++---------- 4 files changed, 62 insertions(+), 66 deletions(-) diff --git a/administrator/components/com_admin/script.php b/administrator/components/com_admin/script.php index 2367cb41286f5..4b8094d4ab10b 100644 --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -6251,6 +6251,33 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false) return; } + // Check if the #__utf8_conversion table exists + $db->setQuery('SHOW TABLES LIKE ' . $this->db->quote($this->db->getPrefix() . 'utf8_conversion')); + + try + { + $tableExists = $db->loadResult(); + } + catch (Exception $e) + { + // Render the error message from the Exception object + Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); + + if ($doDbFixMsg) + { + // Show an error message telling to check database problems + Factory::getApplication()->enqueueMessage(Text::_('JLIB_DATABASE_ERROR_DATABASE_UPGRADE_FAILED'), 'error'); + } + + return; + } + + // Nothing to do if the table doesn't exist because the CMS has never been updated from a pre-4.0 version + if ($tableExists == 0) + { + return; + } + // Set required conversion status $converted = 2; diff --git a/installation/sql/mysql/base.sql b/installation/sql/mysql/base.sql index e0940bc5c4087..1610e00a8086a 100644 --- a/installation/sql/mysql/base.sql +++ b/installation/sql/mysql/base.sql @@ -1005,22 +1005,6 @@ CREATE TABLE IF NOT EXISTS `#__user_usergroup_map` ( -- -------------------------------------------------------- --- --- Table structure for table `#__utf8_conversion` --- - -CREATE TABLE IF NOT EXISTS `#__utf8_conversion` ( - `converted` tinyint(4) NOT NULL DEFAULT 0 -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; - --- --- Dumping data for table `#__utf8_conversion` --- - -INSERT INTO `#__utf8_conversion` (`converted`) VALUES (2); - --- -------------------------------------------------------- - -- -- Table structure for table `#__viewlevels` -- diff --git a/libraries/src/Schema/ChangeItem/MysqlChangeItem.php b/libraries/src/Schema/ChangeItem/MysqlChangeItem.php index 46c1f7e47db4c..2588aba4199dd 100644 --- a/libraries/src/Schema/ChangeItem/MysqlChangeItem.php +++ b/libraries/src/Schema/ChangeItem/MysqlChangeItem.php @@ -65,19 +65,6 @@ protected function buildCheckQuery() // We can only make check queries for alter table and create table queries $command = strtoupper($wordArray[0] . ' ' . $wordArray[1]); - // Check for special update statement to reset utf8mb4 conversion status - if (($command === 'UPDATE `#__UTF8_CONVERSION`' - || $command === 'UPDATE #__UTF8_CONVERSION') - && strtoupper($wordArray[2]) === 'SET' - && strtolower(substr(str_replace('`', '', $wordArray[3]), 0, 9)) === 'converted') - { - // Statement is special statement to reset conversion status - $this->queryType = 'UTF8CNV'; - - // Done with method - return; - } - if ($command === 'ALTER TABLE') { $alterCommand = strtoupper($wordArray[3] . ' ' . $wordArray[4]); diff --git a/libraries/src/Schema/ChangeSet.php b/libraries/src/Schema/ChangeSet.php index 977c3f869d16e..1b42a4326cdb8 100644 --- a/libraries/src/Schema/ChangeSet.php +++ b/libraries/src/Schema/ChangeSet.php @@ -75,55 +75,53 @@ public function __construct($db, $folder = null) foreach ($updateQueries as $obj) { - $changeItem = ChangeItem::getInstance($db, $obj->file, $obj->updateQuery); + $this->changeItems[] = ChangeItem::getInstance($db, $obj->file, $obj->updateQuery); + } + + // If on mysql, add a query at the end to check for utf8mb4 conversion status + if ($this->db->getServerType() === 'mysql') + { + // Check if the #__utf8_conversion table exists + $this->db->setQuery('SHOW TABLES LIKE ' . $this->db->quote($this->db->getPrefix() . 'utf8_conversion')); - if ($changeItem->queryType === 'UTF8CNV') + try { - // Execute the special update query for utf8mb4 conversion status reset - try - { - $this->db->setQuery($changeItem->updateQuery)->execute(); - } - catch (\RuntimeException $e) - { - Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); - } + $tableExists = $this->db->loadResult(); } - else + catch (\RuntimeException $e) { - // Normal change item - $this->changeItems[] = $changeItem; + $tableExists = 0; } - } - // If on mysql, add a query at the end to check for utf8mb4 conversion status - if ($this->db->getServerType() === 'mysql') - { - // Let the update query be something harmless which should always succeed - $tmpSchemaChangeItem = ChangeItem::getInstance( - $db, - 'database.php', - 'UPDATE ' . $this->db->quoteName('#__utf8_conversion') - . ' SET ' . $this->db->quoteName('converted') . ' = 0;' - ); + // If the table exists add a change item for utf8mb4 conversion to the end + if ($tableExists > 0) + { + // Let the update query be something harmless which should always succeed + $tmpSchemaChangeItem = ChangeItem::getInstance( + $db, + 'database.php', + 'UPDATE ' . $this->db->quoteName('#__utf8_conversion') + . ' SET ' . $this->db->quoteName('converted') . ' = 0;' + ); - // Set to not skipped - $tmpSchemaChangeItem->checkStatus = 0; + // Set to not skipped + $tmpSchemaChangeItem->checkStatus = 0; - // Set the check query - $tmpSchemaChangeItem->queryType = 'UTF8_CONVERSION_UTF8MB4'; + // Set the check query + $tmpSchemaChangeItem->queryType = 'UTF8_CONVERSION_UTF8MB4'; - $tmpSchemaChangeItem->checkQuery = 'SELECT ' - . $this->db->quoteName('converted') - . ' FROM ' . $this->db->quoteName('#__utf8_conversion') - . ' WHERE ' . $this->db->quoteName('converted') . ' = 2'; + $tmpSchemaChangeItem->checkQuery = 'SELECT ' + . $this->db->quoteName('converted') + . ' FROM ' . $this->db->quoteName('#__utf8_conversion') + . ' WHERE ' . $this->db->quoteName('converted') . ' = 2'; - // Set expected records from check query - $tmpSchemaChangeItem->checkQueryExpected = 1; + // Set expected records from check query + $tmpSchemaChangeItem->checkQueryExpected = 1; - $tmpSchemaChangeItem->msgElements = array(); + $tmpSchemaChangeItem->msgElements = array(); - $this->changeItems[] = $tmpSchemaChangeItem; + $this->changeItems[] = $tmpSchemaChangeItem; + } } } From 9ad340c691d5e0dcefaf7ec4e0d26d254b906bd2 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sun, 5 Apr 2020 16:32:35 +0200 Subject: [PATCH 06/20] Fix check if conversion table exists --- administrator/components/com_admin/script.php | 4 ++-- libraries/src/Schema/ChangeSet.php | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/administrator/components/com_admin/script.php b/administrator/components/com_admin/script.php index 4b8094d4ab10b..27b4c602b7b9f 100644 --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -6256,7 +6256,7 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false) try { - $tableExists = $db->loadResult(); + $rows = $db->loadRowList(0); } catch (Exception $e) { @@ -6273,7 +6273,7 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false) } // Nothing to do if the table doesn't exist because the CMS has never been updated from a pre-4.0 version - if ($tableExists == 0) + if (\count($rows) === 0) { return; } diff --git a/libraries/src/Schema/ChangeSet.php b/libraries/src/Schema/ChangeSet.php index 1b42a4326cdb8..02ab53e6dae56 100644 --- a/libraries/src/Schema/ChangeSet.php +++ b/libraries/src/Schema/ChangeSet.php @@ -86,7 +86,9 @@ public function __construct($db, $folder = null) try { - $tableExists = $this->db->loadResult(); + $rows = $this->db->loadRowList(0); + + $tableExists = \count($rows); } catch (\RuntimeException $e) { From b3ddcccd5e02bf47469d5ac962fc4c10d25015ed Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sun, 5 Apr 2020 16:57:59 +0200 Subject: [PATCH 07/20] Drop `#__utf8_conversion` table if conversion done --- administrator/components/com_admin/script.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/administrator/components/com_admin/script.php b/administrator/components/com_admin/script.php index 27b4c602b7b9f..60a6e369cec64 100644 --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -6367,7 +6367,24 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false) Factory::getApplication()->enqueueMessage(Text::_('JLIB_DATABASE_ERROR_DATABASE_UPGRADE_FAILED'), 'error'); } - // Set flag in database if the update is done. + // If the conversion was successful try to drop the #__utf8_conversion table + if ($converted == 2) + { + try + { + $db->setQuery('DROP TABLE ' . $db->quoteName('#__utf8_conversion') . ';' + )->execute(); + + // All done + return; + } + catch (Exception $e) + { + // Nothing to be done, conversion status is updated in database later + } + } + + // Update conversion status in database $db->setQuery('UPDATE ' . $db->quoteName('#__utf8_conversion') . ' SET ' . $db->quoteName('converted') . ' = ' . $converted . ';' )->execute(); From 4a4af08e8056c0ac5240697c23452de2b69e90a4 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sun, 5 Apr 2020 17:29:17 +0200 Subject: [PATCH 08/20] No SQL query downgrade utf8mb4 to utf8 --- administrator/components/com_admin/script.php | 2 +- installation/src/Model/DatabaseModel.php | 21 ------------------ libraries/src/Installer/Installer.php | 22 ------------------- libraries/src/Schema/ChangeItem.php | 6 ----- 4 files changed, 1 insertion(+), 50 deletions(-) diff --git a/administrator/components/com_admin/script.php b/administrator/components/com_admin/script.php index 60a6e369cec64..47cdf0a8e9f46 100644 --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -6348,7 +6348,7 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false) { try { - $db->setQuery($db->convertUtf8mb4QueryToUtf8($query2))->execute(); + $db->setQuery($query2)->execute(); } catch (Exception $e) { diff --git a/installation/src/Model/DatabaseModel.php b/installation/src/Model/DatabaseModel.php index e3ceef19e9767..98f32eb60f5b6 100644 --- a/installation/src/Model/DatabaseModel.php +++ b/installation/src/Model/DatabaseModel.php @@ -23,7 +23,6 @@ use Joomla\CMS\Version; use Joomla\Database\DatabaseDriver; use Joomla\Database\DatabaseInterface; -use Joomla\Database\UTF8MB4SupportInterface; use Joomla\Utilities\ArrayHelper; /** @@ -660,26 +659,6 @@ public function populateDatabase($db, $schema) // If the query isn't empty and is not a MySQL or PostgreSQL comment, execute it. if (!empty($query) && ($query[0] != '#') && ($query[0] != '-')) { - /** - * If we don't have UTF-8 Multibyte support we'll have to convert queries to plain UTF-8 - * - * Note: the JDatabaseDriver::convertUtf8mb4QueryToUtf8 performs the conversion ONLY when - * necessary, so there's no need to check the conditions in JInstaller. - */ - if ($db instanceof UTF8MB4SupportInterface) - { - $query = $db->convertUtf8mb4QueryToUtf8($query); - - /** - * This is a query which was supposed to convert tables to utf8mb4 charset but the server doesn't - * support utf8mb4. Therefore we don't have to run it, it has no effect and it's a mere waste of time. - */ - if (!$db->hasUTF8mb4Support() && stristr($query, 'CONVERT TO CHARACTER SET utf8 ')) - { - continue; - } - } - // Execute the query. $db->setQuery($query); diff --git a/libraries/src/Installer/Installer.php b/libraries/src/Installer/Installer.php index fb6fe0c5d7ff8..5abb11c1ac8d3 100644 --- a/libraries/src/Installer/Installer.php +++ b/libraries/src/Installer/Installer.php @@ -23,7 +23,6 @@ use Joomla\Database\DatabaseDriver; use Joomla\Database\Exception\ExecutionFailureException; use Joomla\Database\ParameterType; -use Joomla\Database\UTF8MB4SupportInterface; \JLoader::import('joomla.base.adapter'); @@ -902,18 +901,11 @@ public function parseQueries(\SimpleXMLElement $element) $update_count = 0; - $isUtf8mb4Db = $db instanceof UTF8MB4SupportInterface; - // Process each query in the $queries array (children of $tagName). foreach ($queries as $query) { try { - if ($isUtf8mb4Db) - { - $query = $db->convertUtf8mb4QueryToUtf8($query); - } - $db->setQuery($query)->execute(); } catch (ExecutionFailureException $e) @@ -998,18 +990,11 @@ public function parseSQLFiles($element) continue; } - $isUtf8mb4Db = $db instanceof UTF8MB4SupportInterface; - // Process each query in the $queries array (split out of sql file). foreach ($queries as $query) { try { - if ($isUtf8mb4Db) - { - $query = $db->convertUtf8mb4QueryToUtf8($query); - } - $db->setQuery($query)->execute(); } catch (ExecutionFailureException $e) @@ -1202,18 +1187,11 @@ public function parseSchemaUpdates(\SimpleXMLElement $schema, $eid) continue; } - $isUtf8mb4Db = $db instanceof UTF8MB4SupportInterface; - // Process each query in the $queries array (split out of sql file). foreach ($queries as $query) { try { - if ($isUtf8mb4Db) - { - $query = $db->convertUtf8mb4QueryToUtf8($query); - } - $db->setQuery($query)->execute(); } catch (ExecutionFailureException $e) diff --git a/libraries/src/Schema/ChangeItem.php b/libraries/src/Schema/ChangeItem.php index 518ee2d1a597c..d0b3c5b55f6a2 100644 --- a/libraries/src/Schema/ChangeItem.php +++ b/libraries/src/Schema/ChangeItem.php @@ -12,7 +12,6 @@ use Joomla\CMS\Factory; use Joomla\Database\Exception\ExecutionFailureException; -use Joomla\Database\UTF8MB4SupportInterface; /** * Each object represents one query, which is one line from a DDL SQL query. @@ -238,11 +237,6 @@ public function fix() // At this point we have a failed query $query = $this->updateQuery; - if ($this->db instanceof UTF8MB4SupportInterface) - { - $query = $this->db->convertUtf8mb4QueryToUtf8($query); - } - $this->db->setQuery($query); try From e8ff38238915421f4b3d4a0c426d858a92c3c8cf Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sun, 5 Apr 2020 18:51:50 +0200 Subject: [PATCH 09/20] Don't let the database checker create the conversion table --- .../com_installer/src/Model/DatabaseModel.php | 63 ------------------- 1 file changed, 63 deletions(-) diff --git a/administrator/components/com_installer/src/Model/DatabaseModel.php b/administrator/components/com_installer/src/Model/DatabaseModel.php index 2087fbb4be358..fe38d1f7123c8 100644 --- a/administrator/components/com_installer/src/Model/DatabaseModel.php +++ b/administrator/components/com_installer/src/Model/DatabaseModel.php @@ -21,7 +21,6 @@ use Joomla\Component\Installer\Administrator\Helper\InstallerHelper; use Joomla\Database\Exception\ExecutionFailureException; use Joomla\Database\ParameterType; -use Joomla\Database\UTF8MB4SupportInterface; use Joomla\Registry\Registry; \JLoader::register('JoomlaInstallerScript', JPATH_ADMINISTRATOR . '/components/com_admin/script.php'); @@ -231,9 +230,6 @@ protected function populateState($ordering = 'name', $direction = 'asc') $this->setState('filter.type', $this->getUserStateFromRequest($this->context . '.filter.type', 'filter_type', '', 'string')); $this->setState('filter.folder', $this->getUserStateFromRequest($this->context . '.filter.folder', 'filter_folder', '', 'string')); - // Prepare the utf8mb4 conversion check table - $this->prepareUtf8mb4StatusTable(); - parent::populateState($ordering, $direction); } @@ -651,63 +647,4 @@ private function fixDefaultTextFilters() } } } - - /** - * Prepare the table to save the status of utf8mb4 conversion - * Make sure it contains 1 initialized record if there is not - * already exactly 1 record. - * - * @return void - * - * @since 3.5 - */ - private function prepareUtf8mb4StatusTable() - { - $db = Factory::getDbo(); - - if (!$db instanceof UTF8MB4SupportInterface) - { - return; - } - - $creaTabSql = 'CREATE TABLE IF NOT EXISTS ' . $db->quoteName('#__utf8_conversion') - . ' (' . $db->quoteName('converted') . ' tinyint(4) NOT NULL DEFAULT 0' - . ') ENGINE=InnoDB'; - - if ($db->hasUTF8mb4Support()) - { - $creaTabSql = $creaTabSql - . ' DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;'; - } - else - { - $creaTabSql = $creaTabSql - . ' DEFAULT CHARSET=utf8 DEFAULT COLLATE=utf8_unicode_ci;'; - } - - $db->setQuery($creaTabSql)->execute(); - - $db->setQuery('SELECT COUNT(*) FROM ' . $db->quoteName('#__utf8_conversion') . ';'); - - $count = $db->loadResult(); - - if ($count > 1) - { - // Table messed up somehow, clear it - $db->setQuery('DELETE FROM ' . $db->quoteName('#__utf8_conversion') . ';') - ->execute(); - $db->setQuery('INSERT INTO ' . $db->quoteName('#__utf8_conversion') - . ' (' . $db->quoteName('converted') . ') VALUES (0);' - ) - ->execute(); - } - elseif ($count == 0) - { - // Record missing somehow, fix this - $db->setQuery('INSERT INTO ' . $db->quoteName('#__utf8_conversion') - . ' (' . $db->quoteName('converted') . ') VALUES (0);' - ) - ->execute(); - } - } } From 31e793dbc1fc1d02432a6cce2812f28ccc5d23ec Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sun, 5 Apr 2020 18:53:05 +0200 Subject: [PATCH 10/20] Always utf8mb4 support in the database checker --- .../src/Schema/ChangeItem/MysqlChangeItem.php | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/libraries/src/Schema/ChangeItem/MysqlChangeItem.php b/libraries/src/Schema/ChangeItem/MysqlChangeItem.php index 2588aba4199dd..2516fecc496bb 100644 --- a/libraries/src/Schema/ChangeItem/MysqlChangeItem.php +++ b/libraries/src/Schema/ChangeItem/MysqlChangeItem.php @@ -11,7 +11,6 @@ \defined('JPATH_PLATFORM') or die; use Joomla\CMS\Schema\ChangeItem; -use Joomla\Database\UTF8MB4SupportInterface; /** * Checks the database schema against one MySQL DDL query to see if it has been run. @@ -283,24 +282,17 @@ private function fixUtf8mb4TypeChecks($type) { $uType = strtoupper(str_replace(';', '', $type)); - if ($this->db instanceof UTF8MB4SupportInterface && $this->db->hasUTF8mb4Support()) + if ($uType === 'TINYTEXT') { - if ($uType === 'TINYTEXT') - { - $typeCheck = 'UPPER(type) IN (' . $this->db->quote('TINYTEXT') . ',' . $this->db->quote('TEXT') . ')'; - } - elseif ($uType === 'TEXT') - { - $typeCheck = 'UPPER(type) IN (' . $this->db->quote('TEXT') . ',' . $this->db->quote('MEDIUMTEXT') . ')'; - } - elseif ($uType === 'MEDIUMTEXT') - { - $typeCheck = 'UPPER(type) IN (' . $this->db->quote('MEDIUMTEXT') . ',' . $this->db->quote('LONGTEXT') . ')'; - } - else - { - $typeCheck = 'UPPER(type) = ' . $this->db->quote($uType); - } + $typeCheck = 'UPPER(type) IN (' . $this->db->quote('TINYTEXT') . ',' . $this->db->quote('TEXT') . ')'; + } + elseif ($uType === 'TEXT') + { + $typeCheck = 'UPPER(type) IN (' . $this->db->quote('TEXT') . ',' . $this->db->quote('MEDIUMTEXT') . ')'; + } + elseif ($uType === 'MEDIUMTEXT') + { + $typeCheck = 'UPPER(type) IN (' . $this->db->quote('MEDIUMTEXT') . ',' . $this->db->quote('LONGTEXT') . ')'; } else { From 2cfc8d1bf2876e2c8d91019f0a30b0cb61588d23 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Fri, 1 May 2020 15:42:00 +0200 Subject: [PATCH 11/20] Use one conversion sql script only, fix drop table --- administrator/components/com_admin/script.php | 102 ++++++++---------- .../others/mysql/utf8mb4-conversion-01.sql | 33 ------ ...nversion-02.sql => utf8mb4-conversion.sql} | 88 +++------------ libraries/src/Schema/ChangeSet.php | 6 +- 4 files changed, 65 insertions(+), 164 deletions(-) delete mode 100644 administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-01.sql rename administrator/components/com_admin/sql/others/mysql/{utf8mb4-conversion-02.sql => utf8mb4-conversion.sql} (70%) diff --git a/administrator/components/com_admin/script.php b/administrator/components/com_admin/script.php index 6fae2055b6d92..2cd0e9cf8b553 100644 --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -19,7 +19,6 @@ use Joomla\CMS\Table\Table; use Joomla\Database\ParameterType; use Joomla\Component\Fields\Administrator\Model\FieldModel; -use Joomla\Database\UTF8MB4SupportInterface; /** * Script file of Joomla CMS @@ -6246,7 +6245,7 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false) { $db = Factory::getDbo(); - if (!($db instanceof UTF8MB4SupportInterface)) + if ($db->getServerType() !== 'mysql') { return; } @@ -6304,55 +6303,33 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false) return; } - // Nothing to do, saved conversion status from DB is equal to required - if ($convertedDB == $converted) + // If conversion status from DB is equal to required final status, try to drop the #__utf8_conversion table + if ($convertedDB === $converted) { - return; - } - - // Step 1: Drop indexes later to be added again with column lengths limitations at step 2 - $fileName1 = JPATH_ROOT . '/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-01.sql'; + $this->dropUtf8ConversionTable(); - if (is_file($fileName1)) - { - $fileContents1 = @file_get_contents($fileName1); - $queries1 = $db->splitSql($fileContents1); - - if (!empty($queries1)) - { - foreach ($queries1 as $query1) - { - try - { - $db->setQuery($query1)->execute(); - } - catch (Exception $e) - { - // If the query fails we will go on. It just means the index to be dropped does not exist. - } - } - } + return; } - // Step 2: Perform the index modifications and conversions - $fileName2 = JPATH_ROOT . '/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-02.sql'; + // Perform the conversions + $fileName = JPATH_ROOT . '/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion.sql'; - if (is_file($fileName2)) + if (is_file($fileName)) { - $fileContents2 = @file_get_contents($fileName2); - $queries2 = $db->splitSql($fileContents2); + $fileContents = @file_get_contents($fileName); + $queries = $db->splitSql($fileContents); - if (!empty($queries2)) + if (!empty($queries)) { - foreach ($queries2 as $query2) + foreach ($queries as $query) { try { - $db->setQuery($query2)->execute(); + $db->setQuery($query)->execute(); } catch (Exception $e) { - $converted = 0; + $converted = $convertedDB; // Still render the error message from the Exception object Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); @@ -6361,33 +6338,26 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false) } } - if ($doDbFixMsg && $converted == 0) + if ($doDbFixMsg && $converted !== 2) { // Show an error message telling to check database problems Factory::getApplication()->enqueueMessage(Text::_('JLIB_DATABASE_ERROR_DATABASE_UPGRADE_FAILED'), 'error'); } // If the conversion was successful try to drop the #__utf8_conversion table - if ($converted == 2) + if ($converted === 2 && $this->dropUtf8ConversionTable()) { - try - { - $db->setQuery('DROP TABLE ' . $db->quoteName('#__utf8_conversion') . ';' - )->execute(); - - // All done - return; - } - catch (Exception $e) - { - // Nothing to be done, conversion status is updated in database later - } + // Table successfully dropped + return; } - // Update conversion status in database - $db->setQuery('UPDATE ' . $db->quoteName('#__utf8_conversion') - . ' SET ' . $db->quoteName('converted') . ' = ' . $converted . ';' - )->execute(); + // Set flag in database if the conversion status has changed. + if ($converted !== $convertedDB) + { + $db->setQuery('UPDATE ' . $db->quoteName('#__utf8_conversion') + . ' SET ' . $db->quoteName('converted') . ' = ' . $converted . ';' + )->execute(); + } } /** @@ -6409,6 +6379,28 @@ private function cleanJoomlaCache() $model->clean(); } + /** + * This method drops the #__utf8_conversion table + * + * @return boolean True on success + * + * @since 4.0.0 + */ + private function dropUtf8ConversionTable() + { + try + { + $db->setQuery('DROP TABLE ' . $db->quoteName('#__utf8_conversion') . ';' + )->execute(); + } + catch (Exception $e) + { + return false; + } + + return true; + } + /** * Called after any type of action * diff --git a/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-01.sql b/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-01.sql deleted file mode 100644 index 8a46289ac9a2f..0000000000000 --- a/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-01.sql +++ /dev/null @@ -1,33 +0,0 @@ --- --- Step 1 of the UTF-8 Multibyte (utf8mb4) conversion for MySQL --- --- Drop indexes which will be added again in step 2, utf8mb4-conversion-02.sql. --- --- Do not rename this file or any other of the utf8mb4-conversion-*.sql --- files unless you want to change PHP code, too. --- --- This file here will be processed ignoring any exceptions caused by indexes --- to be dropped do not exist. --- --- The file for step 2 will the be processed with reporting exceptions. --- - -ALTER TABLE `#__banners` DROP KEY `idx_metakey_prefix`; -ALTER TABLE `#__banner_clients` DROP KEY `idx_metakey_prefix`; -ALTER TABLE `#__categories` DROP KEY `idx_path`; -ALTER TABLE `#__categories` DROP KEY `idx_alias`; -ALTER TABLE `#__content` DROP KEY `idx_alias`; -ALTER TABLE `#__content_types` DROP KEY `idx_alias`; -ALTER TABLE `#__fields` DROP KEY `idx_context`; -ALTER TABLE `#__fields_groups` DROP KEY `idx_context`; -ALTER TABLE `#__fields_values` DROP KEY `idx_item_id`; -ALTER TABLE `#__menu` DROP KEY `idx_alias`; -ALTER TABLE `#__menu` DROP KEY `idx_client_id_parent_id_alias_language`; -ALTER TABLE `#__menu` DROP KEY `idx_path`; -ALTER TABLE `#__redirect_links` DROP KEY `idx_old_url`; -ALTER TABLE `#__tags` DROP KEY `idx_path`; -ALTER TABLE `#__tags` DROP KEY `idx_alias`; -ALTER TABLE `#__ucm_content` DROP KEY `idx_alias`; -ALTER TABLE `#__ucm_content` DROP KEY `idx_title`; -ALTER TABLE `#__ucm_content` DROP KEY `idx_content_type`; -ALTER TABLE `#__users` DROP KEY `idx_name`; diff --git a/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-02.sql b/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion.sql similarity index 70% rename from administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-02.sql rename to administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion.sql index 54a26a2e09bdf..7f3873a547815 100644 --- a/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-02.sql +++ b/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion.sql @@ -1,54 +1,12 @@ -- --- Step 2 of the UTF-8 Multibyte (utf8mb4) conversion for MySQL --- --- Enlarge some database columns to avoid data losses, then convert all tables --- to utf8mb4 or utf8, then set default character sets and collations for all --- tables, then add back indexes previosly dropped with step 1, --- utf8mb4-conversion-01.sql, but add them back with limited lenghts of --- columns. --- --- Do not rename this file or any other of the utf8mb4-conversion-*.sql --- files unless you want to change PHP code, too. --- --- IMPORTANT: When adding an index modification to this file for limiting the --- length by which one or more columns go into that index, --- --- 1. remember to add the statement to drop the index to the file for step 1, --- utf8mb4-conversion-01.sql, and --- --- 2. check if the index is created created or modified in some old schema --- update sql in an "ALTER TABLE" statement and limit the column length --- there, too ("CREATE TABLE" is ok, no need to modify those). --- --- This file here will the be processed with reporting exceptions, in opposite --- to the file for step 1. --- - --- --- Step 2.1: Enlarge columns to avoid data loss on later conversion to utf8mb4 --- - -ALTER TABLE `#__banners` MODIFY `alias` varchar(400) NOT NULL DEFAULT ''; -ALTER TABLE `#__banners` MODIFY `metakey_prefix` varchar(400) NOT NULL DEFAULT ''; -ALTER TABLE `#__categories` MODIFY `path` varchar(400) NOT NULL DEFAULT ''; -ALTER TABLE `#__categories` MODIFY `alias` varchar(400) NOT NULL DEFAULT ''; -ALTER TABLE `#__content_types` MODIFY `type_alias` varchar(400) NOT NULL DEFAULT ''; -ALTER TABLE `#__contact_details` MODIFY `alias` varchar(400) NOT NULL DEFAULT ''; -ALTER TABLE `#__content` MODIFY `alias` varchar(400) NOT NULL DEFAULT ''; -ALTER TABLE `#__menu` MODIFY `alias` varchar(400) NOT NULL COMMENT 'The SEF alias of the menu item.'; -ALTER TABLE `#__newsfeeds` MODIFY `alias` varchar(400) NOT NULL DEFAULT ''; -ALTER TABLE `#__tags` MODIFY `path` varchar(400) NOT NULL DEFAULT ''; -ALTER TABLE `#__tags` MODIFY `alias` varchar(400) NOT NULL DEFAULT ''; -ALTER TABLE `#__ucm_content` MODIFY `core_type_alias` varchar(400) NOT NULL DEFAULT '' COMMENT 'FK to the content types table'; -ALTER TABLE `#__ucm_content` MODIFY `core_title` varchar(400) NOT NULL; -ALTER TABLE `#__ucm_content` MODIFY `core_alias` varchar(400) NOT NULL DEFAULT ''; -ALTER TABLE `#__users` MODIFY `name` varchar(400) NOT NULL DEFAULT ''; - --- --- Step 2.2: Convert all tables to utf8mb4 chracter set with utf8mb4_unicode_ci collation +-- Step 1: Convert all tables to utf8mb4 chracter set with utf8mb4_unicode_ci collation -- except of #__finder_xxx tables, those are handled with 4.0.0-2018-07-29.sql at update. -- +ALTER TABLE `#__action_logs` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +ALTER TABLE `#__action_logs_extensions` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +ALTER TABLE `#__action_logs_users` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +ALTER TABLE `#__action_log_config` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__assets` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__associations` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__banners` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; @@ -76,6 +34,8 @@ ALTER TABLE `#__modules_menu` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_u ALTER TABLE `#__newsfeeds` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__overrider` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__postinstall_messages` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +ALTER TABLE `#__privacy_consents` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +ALTER TABLE `#__privacy_requests` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__redirect_links` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__schemas` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__session` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; @@ -98,7 +58,7 @@ ALTER TABLE `#__utf8_conversion` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb ALTER TABLE `#__viewlevels` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- --- Step 2.3: Set collation to utf8mb4_bin for formerly utf8_bin collated columns +-- Step 2: Set collation to utf8mb4_bin for formerly utf8_bin collated columns -- and for the lang_code column of the languages table -- @@ -113,9 +73,13 @@ ALTER TABLE `#__tags` MODIFY `alias` varchar(400) CHARACTER SET utf8mb4 COLLATE ALTER TABLE `#__ucm_content` MODIFY `core_alias` varchar(400) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT ''; -- --- Step 2.4: Set default character set and collation for all tables +-- Step 3: Set default character set and collation for all tables -- +ALTER TABLE `#__action_logs` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +ALTER TABLE `#__action_logs_extensions` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +ALTER TABLE `#__action_logs_users` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +ALTER TABLE `#__action_log_config` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__assets` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__associations` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__banners` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; @@ -143,6 +107,8 @@ ALTER TABLE `#__modules_menu` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unic ALTER TABLE `#__newsfeeds` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__overrider` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__postinstall_messages` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +ALTER TABLE `#__privacy_consents` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +ALTER TABLE `#__privacy_requests` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__redirect_links` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__schemas` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__session` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; @@ -163,27 +129,3 @@ ALTER TABLE `#__user_profiles` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_uni ALTER TABLE `#__user_usergroup_map` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__utf8_conversion` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE `#__viewlevels` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - --- --- Step 2.5: Limit indexes to first 100 so their max allowed lengths would not get exceeded with utf8mb4 --- - -ALTER TABLE `#__banners` ADD KEY `idx_metakey_prefix` (`metakey_prefix`(100)); -ALTER TABLE `#__banner_clients` ADD KEY `idx_metakey_prefix` (`metakey_prefix`(100)); -ALTER TABLE `#__categories` ADD KEY `idx_path` (`path`(100)); -ALTER TABLE `#__categories` ADD KEY `idx_alias` (`alias`(100)); -ALTER TABLE `#__content` ADD KEY `idx_alias` (`alias`(191)); -ALTER TABLE `#__content_types` ADD KEY `idx_alias` (`type_alias`(100)); -ALTER TABLE `#__fields` ADD KEY `idx_context` (`context`(191)); -ALTER TABLE `#__fields_groups` ADD KEY `idx_context` (`context`(191)); -ALTER TABLE `#__fields_values` ADD KEY `idx_item_id` (`item_id`(191)); -ALTER TABLE `#__menu` ADD KEY `idx_alias` (`alias`(100)); -ALTER TABLE `#__menu` ADD UNIQUE `idx_client_id_parent_id_alias_language` (`client_id`,`parent_id`,`alias`(100),`language`); -ALTER TABLE `#__menu` ADD KEY `idx_path` (`path`(100)); -ALTER TABLE `#__redirect_links` ADD KEY `idx_old_url` (`old_url`(100)); -ALTER TABLE `#__tags` ADD KEY `idx_path` (`path`(100)); -ALTER TABLE `#__tags` ADD KEY `idx_alias` (`alias`(100)); -ALTER TABLE `#__ucm_content` ADD KEY `idx_alias` (`core_alias`(100)); -ALTER TABLE `#__ucm_content` ADD KEY `idx_title` (`core_title`(100)); -ALTER TABLE `#__ucm_content` ADD KEY `idx_content_type` (`core_type_alias`(100)); -ALTER TABLE `#__users` ADD KEY `idx_name` (`name`(100)); diff --git a/libraries/src/Schema/ChangeSet.php b/libraries/src/Schema/ChangeSet.php index 02ab53e6dae56..32fc17b7f5427 100644 --- a/libraries/src/Schema/ChangeSet.php +++ b/libraries/src/Schema/ChangeSet.php @@ -98,13 +98,13 @@ public function __construct($db, $folder = null) // If the table exists add a change item for utf8mb4 conversion to the end if ($tableExists > 0) { - // Let the update query be something harmless which should always succeed + // Let the update query do nothing $tmpSchemaChangeItem = ChangeItem::getInstance( $db, 'database.php', 'UPDATE ' . $this->db->quoteName('#__utf8_conversion') - . ' SET ' . $this->db->quoteName('converted') . ' = 0;' - ); + . ' SET ' . $this->db->quoteName('converted') . ' = ' + . $this->db->quoteName('converted') . ';'); // Set to not skipped $tmpSchemaChangeItem->checkStatus = 0; From 1fd661a6c60ae7e310f8f3739341aaafbc093870 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Fri, 1 May 2020 15:52:39 +0200 Subject: [PATCH 12/20] PHPCS --- libraries/src/Schema/ChangeSet.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/src/Schema/ChangeSet.php b/libraries/src/Schema/ChangeSet.php index 32fc17b7f5427..b26bdbfff49c3 100644 --- a/libraries/src/Schema/ChangeSet.php +++ b/libraries/src/Schema/ChangeSet.php @@ -104,7 +104,8 @@ public function __construct($db, $folder = null) 'database.php', 'UPDATE ' . $this->db->quoteName('#__utf8_conversion') . ' SET ' . $this->db->quoteName('converted') . ' = ' - . $this->db->quoteName('converted') . ';'); + . $this->db->quoteName('converted') . ';' + ); // Set to not skipped $tmpSchemaChangeItem->checkStatus = 0; From e17d2ece910b2b9d6aed5daee219b7de27ac6b94 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Fri, 1 May 2020 15:57:34 +0200 Subject: [PATCH 13/20] Adapt to my latest changes in staging and 3.10-dev --- administrator/components/com_admin/script.php | 6 +++--- libraries/src/Schema/ChangeSet.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/administrator/components/com_admin/script.php b/administrator/components/com_admin/script.php index 2cd0e9cf8b553..379401a4aedc9 100644 --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -6278,7 +6278,7 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false) } // Set required conversion status - $converted = 2; + $converted = 4; // Check conversion status in database $db->setQuery('SELECT ' . $db->quoteName('converted') @@ -6338,14 +6338,14 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false) } } - if ($doDbFixMsg && $converted !== 2) + if ($doDbFixMsg && $converted !== 4) { // Show an error message telling to check database problems Factory::getApplication()->enqueueMessage(Text::_('JLIB_DATABASE_ERROR_DATABASE_UPGRADE_FAILED'), 'error'); } // If the conversion was successful try to drop the #__utf8_conversion table - if ($converted === 2 && $this->dropUtf8ConversionTable()) + if ($converted === 4 && $this->dropUtf8ConversionTable()) { // Table successfully dropped return; diff --git a/libraries/src/Schema/ChangeSet.php b/libraries/src/Schema/ChangeSet.php index b26bdbfff49c3..aa1944e594dd5 100644 --- a/libraries/src/Schema/ChangeSet.php +++ b/libraries/src/Schema/ChangeSet.php @@ -116,7 +116,7 @@ public function __construct($db, $folder = null) $tmpSchemaChangeItem->checkQuery = 'SELECT ' . $this->db->quoteName('converted') . ' FROM ' . $this->db->quoteName('#__utf8_conversion') - . ' WHERE ' . $this->db->quoteName('converted') . ' = 2'; + . ' WHERE ' . $this->db->quoteName('converted') . ' = 4'; // Set expected records from check query $tmpSchemaChangeItem->checkQueryExpected = 1; From 22f5d57dfeb39e5134af65fd1f4ad364edf86af8 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Fri, 1 May 2020 16:44:32 +0200 Subject: [PATCH 14/20] Fix PHP undefined property --- administrator/components/com_admin/script.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_admin/script.php b/administrator/components/com_admin/script.php index 379401a4aedc9..3b37886be9192 100644 --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -6251,7 +6251,7 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false) } // Check if the #__utf8_conversion table exists - $db->setQuery('SHOW TABLES LIKE ' . $this->db->quote($this->db->getPrefix() . 'utf8_conversion')); + $db->setQuery('SHOW TABLES LIKE ' . $db->quote($db->getPrefix() . 'utf8_conversion')); try { From 4b1031c45001dddf727948af3bd9f860d908f566 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Fri, 1 May 2020 17:03:20 +0200 Subject: [PATCH 15/20] Fix undefined variable $db --- administrator/components/com_admin/script.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/administrator/components/com_admin/script.php b/administrator/components/com_admin/script.php index 3b37886be9192..b91af82795dc3 100644 --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -6388,6 +6388,8 @@ private function cleanJoomlaCache() */ private function dropUtf8ConversionTable() { + $db = Factory::getDbo(); + try { $db->setQuery('DROP TABLE ' . $db->quoteName('#__utf8_conversion') . ';' From d9ed339653f0016c6e9f168771ee48a566648469 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sun, 3 May 2020 16:24:02 +0200 Subject: [PATCH 16/20] Add optional conversion for old core extensions --- administrator/components/com_admin/script.php | 73 +++++++++++++++---- .../mysql/utf8mb4-conversion_optional.sql | 23 ++++++ 2 files changed, 82 insertions(+), 14 deletions(-) create mode 100644 administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion_optional.sql diff --git a/administrator/components/com_admin/script.php b/administrator/components/com_admin/script.php index b91af82795dc3..cbc4cb80b2b9e 100644 --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -6311,28 +6311,73 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false) return; } - // Perform the conversions - $fileName = JPATH_ROOT . '/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion.sql'; - - if (is_file($fileName)) + // Perform the required conversions of core tables if not done already in a previous step + if ($convertedDB !== 5) { - $fileContents = @file_get_contents($fileName); - $queries = $db->splitSql($fileContents); + $fileName1 = JPATH_ROOT . '/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion.sql'; - if (!empty($queries)) + if (is_file($fileName1)) { - foreach ($queries as $query) + $fileContents1 = @file_get_contents($fileName1); + $queries1 = $db->splitSql($fileContents1); + + if (!empty($queries1)) { - try + foreach ($queries1 as $query1) { - $db->setQuery($query)->execute(); + try + { + $db->setQuery($query1)->execute(); + } + catch (Exception $e) + { + $converted = $convertedDB; + + // Still render the error message from the Exception object + Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); + } } - catch (Exception $e) + } + } + } + + // Perform the optional conversions of tables which might or might not exist + $fileName2 = JPATH_ROOT . '/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion_optional.sql'; + + if (is_file($fileName2)) + { + $fileContents2 = @file_get_contents($fileName2); + $queries2 = $db->splitSql($fileContents2); + + if (!empty($queries2)) + { + foreach ($queries2 as $query2) + { + // Get table name from query + if (preg_match('/^ALTER\s+TABLE\s+([^\s]+)\s+/i', $query2, $matches) === 1) { - $converted = $convertedDB; + $tableName = str_replace('`', '', $matches[1]); + $tableName = str_replace('#__', $db->getPrefix(), $tableName); + + // Check if the table exists and if yes, run the query + try + { + $db->setQuery('SHOW TABLES LIKE ' . $db->quote($tableName)); + + $rows = $db->loadRowList(0); - // Still render the error message from the Exception object - Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); + if (\count($rows) > 0) + { + $db->setQuery($query2)->execute(); + } + } + catch (Exception $e) + { + $converted = 5; + + // Still render the error message from the Exception object + Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); + } } } } diff --git a/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion_optional.sql b/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion_optional.sql new file mode 100644 index 0000000000000..794d604bae152 --- /dev/null +++ b/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion_optional.sql @@ -0,0 +1,23 @@ +-- +-- This file contains the part of the UTF-8 Multibyte (utf8mb4) conversion for MySQL +-- for optional extensions which might be still installed or not on an updated installation. +-- +-- In opposite to file utf8mb4-conversion.sql, any table handled by this file here doesn't +-- need to exist. +-- + +-- +-- Step 1: Convert all tables to utf8mb4 chracter set with utf8mb4_unicode_ci collation. +-- + +ALTER TABLE `#__core_log_searches` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- +-- Step 2: Set collation to utf8mb4_bin for formerly utf8_bin collated columns. +-- + +-- +-- Step 3: Set default character set and collation for all tables +-- + +ALTER TABLE `#__core_log_searches` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; From ad6556fc51391b2a6c26432be9e4d9ec407b8bfa Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Mon, 4 May 2020 08:26:07 +0200 Subject: [PATCH 17/20] Small fix in error handling --- administrator/components/com_admin/script.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/administrator/components/com_admin/script.php b/administrator/components/com_admin/script.php index cbc4cb80b2b9e..9324ce94923c6 100644 --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -6373,7 +6373,10 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false) } catch (Exception $e) { - $converted = 5; + if ($converted === 4) + { + $converted = 5; + } // Still render the error message from the Exception object Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); From 3a0587c33d6359b4d6dc587767db1f1bf768233d Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Mon, 4 May 2020 08:44:22 +0200 Subject: [PATCH 18/20] Run the optional conversion only if no error before --- administrator/components/com_admin/script.php | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/administrator/components/com_admin/script.php b/administrator/components/com_admin/script.php index 9324ce94923c6..e51f86825c568 100644 --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -6341,45 +6341,45 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false) } } - // Perform the optional conversions of tables which might or might not exist - $fileName2 = JPATH_ROOT . '/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion_optional.sql'; - - if (is_file($fileName2)) + // If no error before, perform the optional conversions of tables which might or might not exist + if ($converted === 4) { - $fileContents2 = @file_get_contents($fileName2); - $queries2 = $db->splitSql($fileContents2); + $fileName2 = JPATH_ROOT . '/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion_optional.sql'; - if (!empty($queries2)) + if (is_file($fileName2)) { - foreach ($queries2 as $query2) + $fileContents2 = @file_get_contents($fileName2); + $queries2 = $db->splitSql($fileContents2); + + if (!empty($queries2)) { - // Get table name from query - if (preg_match('/^ALTER\s+TABLE\s+([^\s]+)\s+/i', $query2, $matches) === 1) + foreach ($queries2 as $query2) { - $tableName = str_replace('`', '', $matches[1]); - $tableName = str_replace('#__', $db->getPrefix(), $tableName); - - // Check if the table exists and if yes, run the query - try + // Get table name from query + if (preg_match('/^ALTER\s+TABLE\s+([^\s]+)\s+/i', $query2, $matches) === 1) { - $db->setQuery('SHOW TABLES LIKE ' . $db->quote($tableName)); + $tableName = str_replace('`', '', $matches[1]); + $tableName = str_replace('#__', $db->getPrefix(), $tableName); - $rows = $db->loadRowList(0); - - if (\count($rows) > 0) + // Check if the table exists and if yes, run the query + try { - $db->setQuery($query2)->execute(); + $db->setQuery('SHOW TABLES LIKE ' . $db->quote($tableName)); + + $rows = $db->loadRowList(0); + + if (\count($rows) > 0) + { + $db->setQuery($query2)->execute(); + } } - } - catch (Exception $e) - { - if ($converted === 4) + catch (Exception $e) { $converted = 5; - } - // Still render the error message from the Exception object - Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); + // Still render the error message from the Exception object + Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); + } } } } From 94d2606071f18e2f8ab4048ff707612c87d004d4 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sat, 9 May 2020 20:41:59 +0200 Subject: [PATCH 19/20] Delete utf8mb4-conversion-03.sql --- .../others/mysql/utf8mb4-conversion-03.sql | 33 ------------------- 1 file changed, 33 deletions(-) delete mode 100644 administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-03.sql diff --git a/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-03.sql b/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-03.sql deleted file mode 100644 index 93fcf9ee3d18d..0000000000000 --- a/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-03.sql +++ /dev/null @@ -1,33 +0,0 @@ --- --- Step 3 of the UTF-8 Multibyte (utf8mb4) conversion for MySQL --- --- Convert the tables for action logs and the privacy suite which have been --- forgotten to be added to the utf8mb4 conversion before. --- --- This file here will be processed with reporting exceptions, in opposite --- to the file for step 1. --- - --- --- Step 3.1: Convert action logs and privacy suite tables to utf8mb4 character set with --- utf8mb4_unicode_ci collation --- Note: The database driver for mysql will change utf8mb4 to utf8 if utf8mb4 is not supported --- - -ALTER TABLE `#__action_logs` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -ALTER TABLE `#__action_logs_extensions` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -ALTER TABLE `#__action_logs_users` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -ALTER TABLE `#__action_log_config` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -ALTER TABLE `#__privacy_consents` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -ALTER TABLE `#__privacy_requests` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - --- --- Step 3.2: Set default character set and collation for previously converted tables --- - -ALTER TABLE `#__action_logs` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -ALTER TABLE `#__action_logs_extensions` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -ALTER TABLE `#__action_logs_users` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -ALTER TABLE `#__action_log_config` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -ALTER TABLE `#__privacy_consents` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -ALTER TABLE `#__privacy_requests` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; From d86c9115c8995b6a4a2bdd9c2a9f3df148780da7 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sun, 17 May 2020 15:30:56 +0200 Subject: [PATCH 20/20] Be more open for future changes in J3 --- administrator/components/com_admin/script.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/administrator/components/com_admin/script.php b/administrator/components/com_admin/script.php index e51f86825c568..e1dc20147133c 100644 --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -6312,7 +6312,7 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false) } // Perform the required conversions of core tables if not done already in a previous step - if ($convertedDB !== 5) + if ($convertedDB !== 99) { $fileName1 = JPATH_ROOT . '/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion.sql'; @@ -6375,7 +6375,7 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false) } catch (Exception $e) { - $converted = 5; + $converted = 99; // Still render the error message from the Exception object Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');