/**
* Constructor: builds array of $changeItems by processing the .sql files in a folder.
* The folder for the Joomla core updates is `administrator/components/com_admin/sql/updates/<database>`.
*
* @param DatabaseDriver $db The current database object
* @param string $folder The full path to the folder containing the update queries
*
* @since 2.5
*/
public function __construct($db, $folder = null)
{
$this->db = $db;
$this->folder = $folder;
$updateFiles = $this->getUpdateFiles();
// If no files were found nothing more we can do - continue
if ($updateFiles === false) {
return;
}
$updateQueries = $this->getUpdateQueries($updateFiles);
foreach ($updateQueries as $obj) {
$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'));
try {
$rows = $this->db->loadRowList(0);
$tableExists = \count($rows);
} catch (\RuntimeException $e) {
$tableExists = 0;
}
// If the table exists add a change item for utf8mb4 conversion to the end
if ($tableExists > 0) {
// Let the update query do nothing
$tmpSchemaChangeItem = ChangeItem::getInstance($db, 'database.php', 'UPDATE ' . $this->db->quoteName('#__utf8_conversion') . ' SET ' . $this->db->quoteName('converted') . ' = ' . $this->db->quoteName('converted') . ';');
// Set to not skipped
$tmpSchemaChangeItem->checkStatus = 0;
// 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') . ' = 5';
// Set expected records from check query
$tmpSchemaChangeItem->checkQueryExpected = 1;
$tmpSchemaChangeItem->msgElements = array();
$this->changeItems[] = $tmpSchemaChangeItem;
}
}
}