diff --git a/src/script.php b/src/script.php index c6a598c1..5afdddef 100644 --- a/src/script.php +++ b/src/script.php @@ -54,6 +54,9 @@ class Pkg_MokowaasInstallerScript // Set up cpanel module on the admin dashboard $this->setupCpanelModule(); + // Create Support portal menu item on frontend + $this->setupSupportMenuItem(); + // Mark MokoWaaS extensions as protected (prevents disable/uninstall at framework level) $this->protectExtensions(); @@ -699,6 +702,82 @@ class Pkg_MokowaasInstallerScript } } + /** + * Create a "Support" menu item on the frontend main menu. + */ + private function setupSupportMenuItem(): void + { + try + { + $db = Factory::getDbo(); + + $db->setQuery( + $db->getQuery(true) + ->select('COUNT(*)') + ->from($db->quoteName('#__menu')) + ->where($db->quoteName('link') . ' LIKE ' . $db->quote('%com_mokowaas&view=tickets%')) + ->where($db->quoteName('client_id') . ' = 0') + ); + + if ((int) $db->loadResult() > 0) + { + return; + } + + $db->setQuery( + $db->getQuery(true) + ->select($db->quoteName('extension_id')) + ->from($db->quoteName('#__extensions')) + ->where($db->quoteName('element') . ' = ' . $db->quote('com_mokowaas')) + ->where($db->quoteName('type') . ' = ' . $db->quote('component')) + ); + $componentId = (int) $db->loadResult(); + + if (!$componentId) + { + return; + } + + $db->setQuery("SELECT id FROM #__menu WHERE menutype = '' AND level = 0 AND client_id = 0 LIMIT 1"); + $rootId = (int) $db->loadResult() ?: 1; + + $db->setQuery('SELECT MAX(rgt) FROM #__menu WHERE client_id = 0'); + $maxRgt = (int) $db->loadResult(); + + $item = (object) [ + 'menutype' => 'mainmenu', + 'title' => 'Support', + 'alias' => 'support', + 'note' => '', + 'path' => 'support', + 'link' => 'index.php?option=com_mokowaas&view=tickets', + 'type' => 'component', + 'published' => 1, + 'parent_id' => $rootId, + 'level' => 1, + 'component_id' => $componentId, + 'checked_out' => null, + 'checked_out_time' => null, + 'browserNav' => 0, + 'access' => 2, + 'img' => '', + 'template_style_id' => 0, + 'params' => '{}', + 'lft' => $maxRgt + 1, + 'rgt' => $maxRgt + 2, + 'home' => 0, + 'language' => '*', + 'client_id' => 0, + ]; + + $db->insertObject('#__menu', $item, 'id'); + } + catch (\Throwable $e) + { + Log::add('Support menu setup error: ' . $e->getMessage(), Log::WARNING, 'mokowaas'); + } + } + /** * One-time migration of params from the monolithic core plugin to * the new feature plugins. Copies security, tenant, and dev params.