Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4ed383b
Initial utf8mb4 support in J4
richard67 Mar 30, 2020
f39e1c8
Remove more obsolete utf8mb4 checks
richard67 Apr 3, 2020
e64f4d0
Remove `#__core_log_searches` and finder tables
richard67 Apr 3, 2020
1d69a9e
Merge remote-tracking branch 'upstream/4.0-dev' into 4.0-dev-clean-up…
richard67 Apr 4, 2020
1c3cf6d
Solve merge conflict
richard67 Apr 4, 2020
b826157
Merge remote-tracking branch 'upstream/4.0-dev' into 4.0-dev-clean-up…
richard67 Apr 5, 2020
ef6900a
No `#__utf8_conversion` table for new installations
richard67 Apr 5, 2020
9ad340c
Fix check if conversion table exists
richard67 Apr 5, 2020
b3ddccc
Drop `#__utf8_conversion` table if conversion done
richard67 Apr 5, 2020
4a4af08
No SQL query downgrade utf8mb4 to utf8
richard67 Apr 5, 2020
e8ff382
Don't let the database checker create the conversion table
richard67 Apr 5, 2020
31e793d
Always utf8mb4 support in the database checker
richard67 Apr 5, 2020
a0eac29
Merge remote-tracking branch 'upstream/4.0-dev' into 4.0-dev-clean-up…
richard67 Apr 10, 2020
3529be0
Merge remote-tracking branch 'upstream/4.0-dev' into 4.0-dev-clean-up…
richard67 Apr 30, 2020
938041b
Merge remote-tracking branch 'upstream/4.0-dev' into 4.0-dev-clean-up…
richard67 May 1, 2020
2cfc8d1
Use one conversion sql script only, fix drop table
richard67 May 1, 2020
1fd661a
PHPCS
richard67 May 1, 2020
e17d2ec
Adapt to my latest changes in staging and 3.10-dev
richard67 May 1, 2020
22f5d57
Fix PHP undefined property
richard67 May 1, 2020
4b1031c
Fix undefined variable $db
richard67 May 1, 2020
d441c45
Merge remote-tracking branch 'upstream/4.0-dev' into 4.0-dev-clean-up…
richard67 May 2, 2020
1ac8038
Merge remote-tracking branch 'upstream/4.0-dev' into 4.0-dev-clean-up…
richard67 May 2, 2020
64c8402
Merge remote-tracking branch 'upstream/4.0-dev' into 4.0-dev-clean-up…
richard67 May 2, 2020
d9ed339
Add optional conversion for old core extensions
richard67 May 3, 2020
dfe90ca
Merge remote-tracking branch 'upstream/4.0-dev' into 4.0-dev-clean-up…
richard67 May 3, 2020
ad6556f
Small fix in error handling
richard67 May 4, 2020
3a0587c
Run the optional conversion only if no error before
richard67 May 4, 2020
e2a09e1
Merge remote-tracking branch 'upstream/4.0-dev' into 4.0-dev-clean-up…
richard67 May 9, 2020
94d2606
Delete utf8mb4-conversion-03.sql
richard67 May 9, 2020
018c8ef
Merge remote-tracking branch 'upstream/4.0-dev' into 4.0-dev-clean-up…
richard67 May 17, 2020
d86c911
Be more open for future changes in J3
richard67 May 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 95 additions & 68 deletions administrator/components/com_admin/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -6246,23 +6245,41 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false)
{
$db = Factory::getDbo();

if (!($db instanceof UTF8MB4SupportInterface))
if ($db->getServerType() !== 'mysql')
{
return;
}

// Set required conversion status
if ($db->hasUTF8mb4Support())
// Check if the #__utf8_conversion table exists
$db->setQuery('SHOW TABLES LIKE ' . $db->quote($db->getPrefix() . 'utf8_conversion'));

try
{
$convertedStep1 = 2;
$convertedStep2 = 4;
$rows = $db->loadRowList(0);
}
else
catch (Exception $e)
{
$convertedStep1 = 1;
$convertedStep2 = 3;
// 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 (\count($rows) === 0)
{
return;
}

// Set required conversion status
$converted = 4;

// Check conversion status in database
$db->setQuery('SELECT ' . $db->quoteName('converted')
. ' FROM ' . $db->quoteName('#__utf8_conversion')
Expand All @@ -6286,20 +6303,18 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false)
return;
}

// Nothing to do, saved conversion status from DB is equal to required final status
if ($convertedDB == $convertedStep2)
// If conversion status from DB is equal to required final status, try to drop the #__utf8_conversion table
if ($convertedDB === $converted)
{
$this->dropUtf8ConversionTable();

return;
}

$converted = $convertedDB;
$hasErrors = false;

// Steps 1 and 2: Convert core tables if necessary and not to be done at later steps
if ($convertedDB < $convertedStep1)
// Perform the required conversions of core tables if not done already in a previous step
if ($convertedDB !== 99)
{
// 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';
$fileName1 = JPATH_ROOT . '/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion.sql';

if (is_file($fileName1))
{
Expand All @@ -6316,14 +6331,20 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false)
}
catch (Exception $e)
{
// If the query fails we will go on. It just means the index to be dropped does not exist.
$converted = $convertedDB;

// Still render the error message from the Exception object
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
}
}
}
}
}

// Step 2: Perform the index modifications and conversions
$fileName2 = JPATH_ROOT . '/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-02.sql';
// If no error before, perform the optional conversions of tables which might or might not exist
if ($converted === 4)
{
$fileName2 = JPATH_ROOT . '/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion_optional.sql';

if (is_file($fileName2))
{
Expand All @@ -6334,70 +6355,52 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false)
{
foreach ($queries2 as $query2)
{
try
// Get table name from query
if (preg_match('/^ALTER\s+TABLE\s+([^\s]+)\s+/i', $query2, $matches) === 1)
{
$db->setQuery($db->convertUtf8mb4QueryToUtf8($query2))->execute();
}
catch (Exception $e)
{
$hasErrors = true;
$tableName = str_replace('`', '', $matches[1]);
$tableName = str_replace('#__', $db->getPrefix(), $tableName);

// Still render the error message from the Exception object
JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error');
}
}
}
}

if (!$hasErrors)
{
$converted = $convertedStep1;
}
}
// Check if the table exists and if yes, run the query
try
{
$db->setQuery('SHOW TABLES LIKE ' . $db->quote($tableName));

// Step 3: Convert action logs and privacy suite tables if necessary and conversion hasn't failed before
if (!$hasErrors && $convertedDB < $convertedStep2)
{
$fileName3 = JPATH_ROOT . '/administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-03.sql';
$rows = $db->loadRowList(0);

if (is_file($fileName3))
{
$fileContents3 = @file_get_contents($fileName3);
$queries3 = $db->splitSql($fileContents3);

if (!empty($queries3))
{
foreach ($queries3 as $query3)
{
try
{
$db->setQuery($db->convertUtf8mb4QueryToUtf8($query3))->execute();
}
catch (Exception $e)
{
$hasErrors = true;
if (\count($rows) > 0)
{
$db->setQuery($query2)->execute();
}
}
catch (Exception $e)
{
$converted = 99;

// Still render the error message from the Exception object
JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error');
// Still render the error message from the Exception object
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
}
}
}
}
}

if (!$hasErrors)
{
$converted = $convertedStep2;
}
}

if ($doDbFixMsg && $hasErrors)
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 === 4 && $this->dropUtf8ConversionTable())
{
// Table successfully dropped
return;
}

// Set flag in database if the conversion status has changed.
if ($converted != $convertedDB)
if ($converted !== $convertedDB)
{
$db->setQuery('UPDATE ' . $db->quoteName('#__utf8_conversion')
. ' SET ' . $db->quoteName('converted') . ' = ' . $converted . ';'
Expand All @@ -6424,6 +6427,30 @@ private function cleanJoomlaCache()
$model->clean();
}

/**
* This method drops the #__utf8_conversion table
*
* @return boolean True on success
*
* @since 4.0.0
*/
private function dropUtf8ConversionTable()
{
$db = Factory::getDbo();

try
{
$db->setQuery('DROP TABLE ' . $db->quoteName('#__utf8_conversion') . ';'
)->execute();
}
catch (Exception $e)
{
return false;
}

return true;
}

/**
* Called after any type of action
*
Expand Down

This file was deleted.

This file was deleted.

Loading