diff --git a/administrator/components/com_installer/src/Model/ManageModel.php b/administrator/components/com_installer/src/Model/ManageModel.php index 8ac385f59e02e..9c7cdb96177e7 100644 --- a/administrator/components/com_installer/src/Model/ManageModel.php +++ b/administrator/components/com_installer/src/Model/ManageModel.php @@ -140,14 +140,53 @@ public function publish(&$eid = [], $value = 1) continue; } - // Parent template cannot be disabled if there are children - if ($style->load(['parent' => $table->element, 'client_id' => $table->client_id])) { - Factory::getApplication()->enqueueMessage(Text::_('COM_INSTALLER_ERROR_DISABLE_PARENT_TEMPLATE_NOT_PERMITTED'), 'notice'); + $db = $this->getDatabase(); + + if ($value === 0) { + // Parent template cannot be disabled if there are enabled children. + $templateColumn = 's.parent'; + $extensionColumn = 's.template'; + $enabled = 1; + $error = 'COM_INSTALLER_ERROR_DISABLE_PARENT_TEMPLATE_NOT_PERMITTED'; + } else { + // Child template cannot be enabled if its parent template is disabled. + $templateColumn = 's.template'; + $extensionColumn = 's.parent'; + $enabled = 0; + $error = 'COM_INSTALLER_ERROR_ENABLE_CHILD_TEMPLATE_NOT_PERMITTED'; + } + + $query = $db->createQuery() + ->select('1') + ->from($db->quoteName('#__template_styles', 's')) + ->join( + 'INNER', + $db->quoteName('#__extensions', 'e'), + $db->quoteName('e.element') . ' = ' . $db->quoteName($extensionColumn) + . ' AND ' . $db->quoteName('e.type') . ' = ' . $db->quote('template') + . ' AND ' . $db->quoteName('e.client_id') . ' = ' . $db->quoteName('s.client_id') + ) + ->where($db->quoteName($templateColumn) . ' = :template') + ->where($db->quoteName('s.client_id') . ' = :clientid') + ->where($db->quoteName('e.enabled') . ' = :enabled') + ->bind(':template', $table->element) + ->bind(':clientid', $table->client_id, ParameterType::INTEGER) + ->bind(':enabled', $enabled, ParameterType::INTEGER); + + if ($value === 1) { + $query->where($db->quoteName('s.parent') . ' != ' . $db->quote('')); + } + + $db->setQuery($query); + + if ($db->loadResult()) { + Factory::getApplication()->enqueueMessage(Text::_($error), 'notice'); unset($eid[$i]); continue; } } + if ($table->protected == 1) { $result = false; Factory::getApplication()->enqueueMessage(Text::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'), 'error'); diff --git a/administrator/language/en-GB/com_installer.ini b/administrator/language/en-GB/com_installer.ini index b01a65f8bec95..5aa2f5126fc54 100644 --- a/administrator/language/en-GB/com_installer.ini +++ b/administrator/language/en-GB/com_installer.ini @@ -31,7 +31,8 @@ COM_INSTALLER_EMPTYSTATE_CONTENT="You currently have no pending updates to apply COM_INSTALLER_EMPTYSTATE_DISCOVER_BUTTON_ADD="Discover extensions to install" COM_INSTALLER_EMPTYSTATE_DISCOVER_TITLE="You have no discovered extensions to install." COM_INSTALLER_ERROR_DISABLE_DEFAULT_TEMPLATE_NOT_PERMITTED="Disabling the default template is not permitted." -COM_INSTALLER_ERROR_DISABLE_PARENT_TEMPLATE_NOT_PERMITTED="Disabling the parent template is not permitted." +COM_INSTALLER_ERROR_DISABLE_PARENT_TEMPLATE_NOT_PERMITTED="Disabling the parent template of an enabled child template is not permitted." +COM_INSTALLER_ERROR_ENABLE_CHILD_TEMPLATE_NOT_PERMITTED="Enabling a child template when its parent is disabled is not permitted." COM_INSTALLER_ERROR_METHOD="Method Not Implemented" COM_INSTALLER_ERROR_NO_EXTENSIONS_DISCOVERED="No extensions discovered." COM_INSTALLER_ERROR_NO_EXTENSIONS_SELECTED="No extensions selected."