Skip to content

Commit

Permalink
UTF-8 Multibyte (utf8mb4) support
Browse files Browse the repository at this point in the history
Make the Database Fix feature really convert an existing database to utf8mb4. The kicker? It's not required in any installation or upgrade scenario. It's only required to let people test the pull request of this feature. [sigh]
  • Loading branch information
Nicholas K. Dionysopoulos committed Jun 13, 2015
1 parent f2d6335 commit 477d8a4
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions administrator/components/com_installer/models/database.php
Expand Up @@ -63,6 +63,9 @@ public function fix()
$installer = new JoomlaInstallerScript;
$installer->deleteUnexistingFiles();
$this->fixDefaultTextFilters();

// Finally, make sure the database is converted to utf8mb4 if supported by the server
$this->convertTablesToUtf8mb4();
}

/**
Expand Down Expand Up @@ -255,4 +258,45 @@ public function fixDefaultTextFilters()
}
}
}

public function convertTablesToUtf8mb4()
{
$db = JFactory::getDbo();

// If the database does not have UTF-8 Multibyte (utf8mb4) support we can't do much about it.
if (!$db->hasUTF8mb4Support())
{
return;
}

// Get the SQL file to convert the core tables. Yes, this is hardcoded because we have all sorts of index
// conversions and funky things we can't automate in core tables without an actual SQL file.
$serverType = $db->getServerType();
$fileName = JPATH_ADMINISTRATOR . "/components/com_admin/sql/updates/$serverType/3.5.0-2015-01-01.sql";

if (!is_file($fileName))
{
return;
}

$fileContents = @file_get_contents($fileName);
$queries = $db->splitSql($fileContents);

if (empty($queries))
{
return;
}

foreach ($queries as $query)
{
try
{
$db->setQuery($query)->execute();
}
catch (Exception $e)
{
// If the query fails we will go on. It probably means we've already done this conversion.
}
}
}
}

0 comments on commit 477d8a4

Please sign in to comment.