Skip to content

Commit 83dc4d8

Browse files
authored
Add database structure check to pre-update checker (#33080)
1 parent 0dc0a3a commit 83dc4d8

File tree

2 files changed

+65
-10
lines changed

2 files changed

+65
-10
lines changed

administrator/components/com_joomlaupdate/models/default.php

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,16 +1171,6 @@ public function getPhpOptions()
11711171
$option->notice = null;
11721172
$options[] = $option;
11731173

1174-
// Check if configured database is compatible with Joomla 4
1175-
if (version_compare($this->getUpdateInformation()['latest'], '4', '>='))
1176-
{
1177-
$option = new stdClass;
1178-
$option->label = JText::sprintf('INSTL_DATABASE_SUPPORTED', $this->getConfiguredDatabaseType());
1179-
$option->state = $this->isDatabaseTypeSupported();
1180-
$option->notice = null;
1181-
$options[] = $option;
1182-
}
1183-
11841174
// Check for mbstring options.
11851175
if (extension_loaded('mbstring'))
11861176
{
@@ -1213,6 +1203,23 @@ public function getPhpOptions()
12131203
$option->notice = null;
12141204
$options[] = $option;
12151205

1206+
// Check if configured database is compatible with Joomla 4
1207+
if (version_compare($this->getUpdateInformation()['latest'], '4', '>='))
1208+
{
1209+
$option = new stdClass;
1210+
$option->label = JText::sprintf('INSTL_DATABASE_SUPPORTED', $this->getConfiguredDatabaseType());
1211+
$option->state = $this->isDatabaseTypeSupported();
1212+
$option->notice = null;
1213+
$options[] = $option;
1214+
}
1215+
1216+
// Check if database structure is up to date
1217+
$option = new stdClass;
1218+
$option->label = JText::_('COM_JOOMLAUPDATE_VIEW_DEFAULT_DATABASE_STRUCTURE_TITLE');
1219+
$option->state = $this->getDatabaseSchemaCheck();
1220+
$option->notice = $option->state ? null : JText::_('COM_JOOMLAUPDATE_VIEW_DEFAULT_DATABASE_STRUCTURE_NOTICE');
1221+
$options[] = $option;
1222+
12161223
return $options;
12171224
}
12181225

@@ -1379,6 +1386,52 @@ public function getIniParserAvailability()
13791386
return $result;
13801387
}
13811388

1389+
1390+
/**
1391+
* Check if database structure is up to date
1392+
*
1393+
* @return boolean True if ok, false if not.
1394+
*
1395+
* @since 3.10.0
1396+
*/
1397+
private function getDatabaseSchemaCheck()
1398+
{
1399+
JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_installer/models', 'InstallerModel');
1400+
1401+
// Get the database model
1402+
$model = JModelLegacy::getInstance('Database', 'InstallerModel');
1403+
1404+
// Check if no default text filters found
1405+
if (!$model->getDefaultTextFilters())
1406+
{
1407+
return false;
1408+
}
1409+
1410+
// Check if database update version does not match CMS version
1411+
if (version_compare($model->getUpdateVersion(), JVERSION) != 0)
1412+
{
1413+
return false;
1414+
}
1415+
1416+
// Get the schema change set
1417+
$changeSet = $model->getItems();
1418+
1419+
// Check if schema errors found
1420+
if (!empty($changeSet->check()))
1421+
{
1422+
return false;
1423+
}
1424+
1425+
// Check if database schema version does not match CMS version
1426+
if ($model->getSchemaVersion() != $changeSet->getSchema())
1427+
{
1428+
return false;
1429+
}
1430+
1431+
// No database problems found
1432+
return true;
1433+
}
1434+
13821435
/**
13831436
* Gets an array containing all installed extensions, that are not core extensions.
13841437
*

administrator/language/en-GB/en-GB.com_joomlaupdate.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ COM_JOOMLAUPDATE_VIEW_COMPLETE_MESSAGE="Your site has been updated. Your Joomla
4848
COM_JOOMLAUPDATE_VIEW_DEFAULT_ACTUAL="Actual"
4949
COM_JOOMLAUPDATE_VIEW_DEFAULT_COMPATIBILITY_CHECK="Joomla! %s Compatibility Check"
5050
COM_JOOMLAUPDATE_VIEW_DEFAULT_COMPATIBLE_UPDATE_WARNING="Extensions marked with <span class='label label-warning'>X.X.X</span> have an extension update available for the current version of Joomla which is not marked as compatible with the updated version of Joomla. You should contact the extension developer for more information."
51+
COM_JOOMLAUPDATE_VIEW_DEFAULT_DATABASE_STRUCTURE_NOTICE="Go to 'Extensions - Manage - Database' and use the 'Fix' button."
52+
COM_JOOMLAUPDATE_VIEW_DEFAULT_DATABASE_STRUCTURE_TITLE="Database Table Structure Up to Date"
5153
COM_JOOMLAUPDATE_VIEW_DEFAULT_DESCRIPTION_BREAK="Extensions marked with <span class='label label-important'>No</span> or <span class='label'>Missing Compatibility Tag</span> might break your website. Please consult with the developer before upgrading."
5254
COM_JOOMLAUPDATE_VIEW_DEFAULT_DESCRIPTION_MISSING_TAG="Extensions marked with <span class='label'>Missing Compatibility Tag</span> indicate the developer has not included <a href='https://docs.joomla.org/Special:MyLanguage/Deploying_an_Update_Server' target='_blank' rel='noopener noreferrer'>compatibility information.</a>"
5355
COM_JOOMLAUPDATE_VIEW_DEFAULT_DESCRIPTION_UPDATE_REQUIRED="Extensions marked with <span class='label label-warning'>Yes (X.X.X)</span> might require an update."

0 commit comments

Comments
 (0)