diff --git a/src/Extension/MokoWaaS.php b/src/Extension/MokoWaaS.php index 8930e7f..7506d27 100644 --- a/src/Extension/MokoWaaS.php +++ b/src/Extension/MokoWaaS.php @@ -84,6 +84,7 @@ class MokoWaaS extends CMSPlugin if ($this->app->isClient('administrator')) { $this->enforceMasterUser(); + $this->enforceLoginSupportUrls(); $this->enforceAdminSessionTimeout(); $this->enforceUploadRestrictions(); } @@ -841,6 +842,70 @@ class MokoWaaS extends CMSPlugin } } + /** + * Enforce login support module URLs on admin requests. + * + * Checks the mod_loginsupport module params and corrects them if + * they have been changed away from the expected values. + * + * @return void + * + * @since 02.00.00 + */ + protected function enforceLoginSupportUrls() + { + $expected = [ + 'forum_url' => 'https://mokoconsulting.tech/support', + 'documentation_url' => 'https://mokoconsulting.tech/kb', + 'news_url' => 'https://mokoconsulting.tech/news', + ]; + + $db = Factory::getDbo(); + $query = $db->getQuery(true) + ->select([$db->quoteName('id'), $db->quoteName('params')]) + ->from($db->quoteName('#__modules')) + ->where($db->quoteName('module') . ' = ' + . $db->quote('mod_loginsupport')); + + $db->setQuery($query); + $modules = $db->loadObjectList(); + + if (empty($modules)) + { + return; + } + + foreach ($modules as $module) + { + $params = new \Joomla\Registry\Registry( + $module->params ?: '{}' + ); + $needsFix = false; + + foreach ($expected as $key => $url) + { + if ($params->get($key) !== $url) + { + $params->set($key, $url); + $needsFix = true; + } + } + + if ($needsFix) + { + $update = $db->getQuery(true) + ->update($db->quoteName('#__modules')) + ->set($db->quoteName('params') . ' = ' + . $db->quote($params->toString())) + ->where($db->quoteName('id') . ' = ' + . (int) $module->id); + + $db->setQuery($update); + $db->execute(); + } + } + } + // ------------------------------------------------------------------ // Tenant Restrictions (called from onAfterRoute) // ------------------------------------------------------------------ diff --git a/src/script.php b/src/script.php index 6b36dd2..de8cb56 100644 --- a/src/script.php +++ b/src/script.php @@ -123,6 +123,7 @@ class plgSystemMokoWaaSInstallerScript implements InstallerScriptInterface if ($type === 'install' || $type === 'update') { $this->installLanguageOverrides(); + $this->updateLoginSupportUrls(); } return true; @@ -311,6 +312,64 @@ class plgSystemMokoWaaSInstallerScript implements InstallerScriptInterface } } + /** + * Update the mod_loginsupport module params to point to + * Moko Consulting URLs at install time. + * + * @return void + * + * @since 02.00.00 + */ + private function updateLoginSupportUrls() + { + $db = Factory::getDbo(); + $query = $db->getQuery(true) + ->select([$db->quoteName('id'), $db->quoteName('params')]) + ->from($db->quoteName('#__modules')) + ->where($db->quoteName('module') . ' = ' + . $db->quote('mod_loginsupport')); + + $db->setQuery($query); + $modules = $db->loadObjectList(); + + if (empty($modules)) + { + return; + } + + $supportUrls = [ + 'forum_url' => 'https://mokoconsulting.tech/support', + 'documentation_url' => 'https://mokoconsulting.tech/kb', + 'news_url' => 'https://mokoconsulting.tech/news', + ]; + + foreach ($modules as $module) + { + $params = new \Joomla\Registry\Registry( + $module->params ?: '{}' + ); + + foreach ($supportUrls as $key => $url) + { + $params->set($key, $url); + } + + $update = $db->getQuery(true) + ->update($db->quoteName('#__modules')) + ->set($db->quoteName('params') . ' = ' + . $db->quote($params->toString())) + ->where($db->quoteName('id') . ' = ' + . (int) $module->id); + + $db->setQuery($update); + $db->execute(); + } + + Factory::getApplication()->enqueueMessage( + 'Updated login support URLs.', 'message' + ); + } + /** * Remove only MokoWaaS overrides from Joomla's global override files. *