Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.1] Prevent deleting a parent template if children exist #36191

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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