Skip to content

Commit

Permalink
Prevent disaster (#36191)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrammatiko authored Dec 7, 2021
1 parent 3e54177 commit f7c66d0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions administrator/language/en-GB/lib_joomla.ini
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ JLIB_INSTALLER_ERROR_TPL_REFRESH_MANIFEST_CACHE="Template Refresh manifest cache
JLIB_INSTALLER_ERROR_TPL_UNINSTALL_ERRORUNKOWNEXTENSION="Template Uninstall: Unknown Extension."
JLIB_INSTALLER_ERROR_TPL_UNINSTALL_INVALID_CLIENT="Template Uninstall: Invalid client."
JLIB_INSTALLER_ERROR_TPL_UNINSTALL_INVALID_NOTFOUND_MANIFEST="Template Uninstall: Manifest file invalid or not found."
JLIB_INSTALLER_ERROR_TPL_UNINSTALL_PARENT_TEMPLATE="Template Uninstall: Can't remove parent template. Please remove all children templates first."
JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_DEFAULT="Template Uninstall: Can't remove default template."
JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_DIRECTORY="Template Uninstall: Folder does not exist, can't remove files."
JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_ID_EMPTY="Template Uninstall: Template ID is empty, can't uninstall files."
Expand Down
1 change: 1 addition & 0 deletions language/en-GB/lib_joomla.ini
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ JLIB_INSTALLER_ERROR_TPL_REFRESH_MANIFEST_CACHE="Template Refresh manifest cache
JLIB_INSTALLER_ERROR_TPL_UNINSTALL_ERRORUNKOWNEXTENSION="Template Uninstall: Unknown Extension."
JLIB_INSTALLER_ERROR_TPL_UNINSTALL_INVALID_CLIENT="Template Uninstall: Invalid client."
JLIB_INSTALLER_ERROR_TPL_UNINSTALL_INVALID_NOTFOUND_MANIFEST="Template Uninstall: Manifest file invalid or not found."
JLIB_INSTALLER_ERROR_TPL_UNINSTALL_PARENT_TEMPLATE="Template Uninstall: Can't remove parent template. Please remove all children templates first."
JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_DEFAULT="Template Uninstall: Can't remove default template."
JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_DIRECTORY="Template Uninstall: Folder does not exist, can't remove files."
JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_ID_EMPTY="Template Uninstall: Template ID is empty, can't uninstall files."
Expand Down
21 changes: 20 additions & 1 deletion libraries/src/Installer/Adapter/TemplateAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ protected function setupUninstall()
{
$this->parent->extension = $this->extension;

$db = $this->parent->getDbo();
$name = $this->extension->element;
$clientId = $this->extension->client_id;

Expand All @@ -473,8 +474,26 @@ protected function setupUninstall()
throw new \RuntimeException(Text::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_ID_EMPTY'));
}

// Deny removing a parent template if there are children
$query = $db->getQuery(true)
->select('COUNT(*)')
->from($db->quoteName('#__template_styles'))
->where(
[
$db->quoteName('parent') . ' = :template',
$db->quoteName('client_id') . ' = :client_id',
]
)
->bind(':template', $name)
->bind(':client_id', $clientId);
$db->setQuery($query);

if ($db->loadResult() != 0)
{
throw new \RuntimeException(Text::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_PARENT_TEMPLATE'));
}

// Deny remove default template
$db = $this->parent->getDbo();
$query = $db->getQuery(true)
->select('COUNT(*)')
->from($db->quoteName('#__template_styles'))
Expand Down

0 comments on commit f7c66d0

Please sign in to comment.