diff --git a/administrator/components/com_admin/sql/updates/mysql/3.5.0-2016-02-26.sql b/administrator/components/com_admin/sql/updates/mysql/3.5.0-2016-02-26.sql index b331cc015f90b..aa2081a9f36c1 100644 --- a/administrator/components/com_admin/sql/updates/mysql/3.5.0-2016-02-26.sql +++ b/administrator/components/com_admin/sql/updates/mysql/3.5.0-2016-02-26.sql @@ -3,12 +3,15 @@ -- order to check if the conversion has been performed and if not show a -- message about database problem in the database schema view. -- --- Note: This table is created with charset utf8 and collation utf8_unicode_ci --- so it will not cause an exception on upgrading a pre-3.5.0 with a database --- not supporting utf8mb4, but all create table statements in future have to --- use charset utf8mb4 and collation utf8mb4_unicode_ci. +-- The value of `converted` can be 0 (not converted yet after update), +-- 1 (converted to utf8), 2 (converted to utf8mb4) or 3 (value set on new +-- installation, will be later set to 1 or 2 by the database schema +-- manager according to utf8 support of the database before checking the +-- database) -- CREATE TABLE IF NOT EXISTS `#__utf8_conversion` ( `converted` tinyint(4) NOT NULL DEFAULT 0 -) ENGINE=InnoDB DEFAULT CHARSET=utf8 DEFAULT COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; + +INSERT INTO `#__utf8_conversion` (`converted`) VALUES (0); diff --git a/administrator/components/com_installer/models/database.php b/administrator/components/com_installer/models/database.php index 8d62df89e5a7d..7aa0dc3d383fb 100644 --- a/administrator/components/com_installer/models/database.php +++ b/administrator/components/com_installer/models/database.php @@ -362,9 +362,24 @@ private function prepareUtf8mb4StatusTable() return; } - $db->setQuery('CREATE TABLE IF NOT EXISTS ' . $db->quoteName('#__utf8_conversion') + $creaTabSql = 'CREATE TABLE IF NOT EXISTS ' . $db->quoteName('#__utf8_conversion') . ' (' . $db->quoteName('converted') . ' tinyint(4) NOT NULL DEFAULT 0' - . ') ENGINE=InnoDB DEFAULT CHARSET=utf8 DEFAULT COLLATE=utf8_unicode_ci;')->execute(); + . ') ENGINE=InnoDB'; + + if ($db->hasUTF8mb4Support()) + { + $converted = 2; + $creaTabSql = $creaTabSql + . ' DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;'; + } + else + { + $converted = 1; + $creaTabSql = $creaTabSql + . ' DEFAULT CHARSET=utf8 DEFAULT COLLATE=utf8_unicode_ci;'; + } + + $db->setQuery($creaTabSql)->execute(); $db->setQuery('SELECT COUNT(*) FROM ' . $db->quoteName('#__utf8_conversion') . ';'); @@ -372,15 +387,25 @@ private function prepareUtf8mb4StatusTable() 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(); + . ' (' . $db->quoteName('converted') . ') VALUES (0);')->execute(); + } + elseif ($count == 1) + { + // Set status after new installation to converted + $db->setQuery('UPDATE ' . $db->quoteName('#__utf8_conversion') + . ' SET ' . $db->quoteName('converted') + . ' = ' . $converted + . ' WHERE ' . $db->quoteName('converted') . ' = 3;')->execute(); } elseif ($count == 0) { + // Record missing somehow, fix this $db->setQuery('INSERT INTO ' . $db->quoteName('#__utf8_conversion') - . ' (' . $db->quoteName('converted') . ') ' . ' VALUES (0);')->execute(); + . ' (' . $db->quoteName('converted') . ') VALUES (0);')->execute(); } } diff --git a/installation/sql/mysql/joomla.sql b/installation/sql/mysql/joomla.sql index f9fb25f556e23..9967ef6a201b9 100644 --- a/installation/sql/mysql/joomla.sql +++ b/installation/sql/mysql/joomla.sql @@ -1949,7 +1949,20 @@ CREATE TABLE IF NOT EXISTS `#__user_usergroup_map` ( PRIMARY KEY (`user_id`,`group_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; --- -------------------------------------------------------- +-- +-- 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` +-- - the `converted`=3 means table just created with a new installation +-- + +INSERT INTO `#__utf8_conversion` (`converted`) VALUES (3); -- -- Table structure for table `#__viewlevels` diff --git a/libraries/cms/schema/changeset.php b/libraries/cms/schema/changeset.php index b069abb999d19..5b8af6d4ba27f 100644 --- a/libraries/cms/schema/changeset.php +++ b/libraries/cms/schema/changeset.php @@ -95,7 +95,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') . ' = ' . $converted . ';'; + . ' WHERE ' . $this->db->quoteName('converted') . ' IN (' . $converted . ', 3);'; // Set expected records from check query $tmpSchemaChangeItem->checkQueryExpected = 1;