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 #88

Closed
joomlapl-bot opened this issue Dec 7, 2021 · 0 comments
Closed

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

joomlapl-bot opened this issue Dec 7, 2021 · 0 comments

Comments

@joomlapl-bot
Copy link
Collaborator

PR w związku ze zmianą oryginału joomla/joomla-cms#36191 Poniżej zmiany w oryginale:

Click to expand the diff!
diff --git a/administrator/language/en-GB/lib_joomla.ini b/administrator/language/en-GB/lib_joomla.ini
index 5f718b1de0c1..4cebf64ed4ef 100644
--- a/administrator/language/en-GB/lib_joomla.ini
+++ b/administrator/language/en-GB/lib_joomla.ini
@@ -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."
diff --git a/language/en-GB/lib_joomla.ini b/language/en-GB/lib_joomla.ini
index ef9676294b32..8cee7dc26824 100644
--- a/language/en-GB/lib_joomla.ini
+++ b/language/en-GB/lib_joomla.ini
@@ -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."
diff --git a/libraries/src/Installer/Adapter/TemplateAdapter.php b/libraries/src/Installer/Adapter/TemplateAdapter.php
index ddda178f9228..5ca13ddf5419 100644
--- a/libraries/src/Installer/Adapter/TemplateAdapter.php
+++ b/libraries/src/Installer/Adapter/TemplateAdapter.php
@@ -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;
 
@@ -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'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants