diff --git a/src/script.php b/src/script.php index cbe4db17..327e2208 100644 --- a/src/script.php +++ b/src/script.php @@ -210,10 +210,11 @@ class plgSystemMokoWaaSInstallerScript implements InstallerScriptInterface } /** - * Ensure mokocassiopeia template is installed and locked. + * Ensure the active Moko template is installed and locked. * - * If the template exists in #__extensions, lock and protect it. - * If not found, attempt to install from the update server. + * Prefers MokoOnyx (successor). Falls back to MokoCassiopeia. + * If MokoOnyx is found, lock it and unlock MokoCassiopeia. + * If only MokoCassiopeia is found, lock it as before. * * @return void * @@ -221,17 +222,50 @@ class plgSystemMokoWaaSInstallerScript implements InstallerScriptInterface */ private function ensureMokoCassiopeia() { - $db = Factory::getDbo(); + $db = Factory::getDbo(); + + // Check for MokoOnyx first (successor template) $query = $db->getQuery(true) ->select([$db->quoteName('extension_id'), $db->quoteName('enabled')]) ->from($db->quoteName('#__extensions')) - ->where($db->quoteName('element') . ' = ' - . $db->quote('mokocassiopeia')) - ->where($db->quoteName('type') . ' = ' - . $db->quote('template')); + ->where($db->quoteName('element') . ' = ' . $db->quote('mokoonyx')) + ->where($db->quoteName('type') . ' = ' . $db->quote('template')); + $onyx = $db->setQuery($query)->loadObject(); - $db->setQuery($query); - $template = $db->loadObject(); + if ($onyx) + { + // Lock and protect MokoOnyx + $db->setQuery( + $db->getQuery(true) + ->update($db->quoteName('#__extensions')) + ->set($db->quoteName('enabled') . ' = 1') + ->set($db->quoteName('locked') . ' = 1') + ->set($db->quoteName('protected') . ' = 1') + ->where($db->quoteName('extension_id') . ' = ' . (int) $onyx->extension_id) + )->execute(); + + $this->setDefaultTemplate('mokoonyx', 0); + + // Unlock MokoCassiopeia if present (allow uninstall) + $db->setQuery( + $db->getQuery(true) + ->update($db->quoteName('#__extensions')) + ->set($db->quoteName('locked') . ' = 0') + ->set($db->quoteName('protected') . ' = 0') + ->where($db->quoteName('element') . ' = ' . $db->quote('mokocassiopeia')) + ->where($db->quoteName('type') . ' = ' . $db->quote('template')) + )->execute(); + + return; + } + + // Fallback: MokoCassiopeia + $query = $db->getQuery(true) + ->select([$db->quoteName('extension_id'), $db->quoteName('enabled')]) + ->from($db->quoteName('#__extensions')) + ->where($db->quoteName('element') . ' = ' . $db->quote('mokocassiopeia')) + ->where($db->quoteName('type') . ' = ' . $db->quote('template')); + $template = $db->setQuery($query)->loadObject(); if ($template) { @@ -247,7 +281,6 @@ class plgSystemMokoWaaSInstallerScript implements InstallerScriptInterface ); $db->execute(); - // Set as default site template $this->setDefaultTemplate('mokocassiopeia', 0); return;