* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved. * @license GNU General Public License version 3 or later; see LICENSE * SPDX-License-Identifier: GPL-3.0-or-later */ defined('_JEXEC') or die; use Joomla\CMS\Factory; use Joomla\CMS\Installer\InstallerAdapter; class Pkg_MokoJoomHeroInstallerScript { /** * Called after install/update — only enables the system plugin on fresh install. * * @param string $type Action type * @param InstallerAdapter $parent Installer adapter * * @return void */ public function postflight(string $type, InstallerAdapter $parent): void { if ($type === 'install') { try { $db = Factory::getDbo(); // Enable the system plugin automatically on fresh install $query = $db->getQuery(true) ->update($db->quoteName('#__extensions')) ->set($db->quoteName('enabled') . ' = 1') ->where($db->quoteName('type') . ' = ' . $db->quote('plugin')) ->where($db->quoteName('folder') . ' = ' . $db->quote('system')) ->where($db->quoteName('element') . ' = ' . $db->quote('mokojoomhero')); $db->setQuery($query); $db->execute(); if ($db->getAffectedRows() === 0) { Factory::getApplication()->enqueueMessage( 'MokoJoomHero: The system plugin could not be auto-enabled. ' . 'Please enable it manually in Extensions → Plugins.', 'warning' ); } } catch (\Exception $e) { Factory::getApplication()->enqueueMessage( 'MokoJoomHero: Failed to auto-enable system plugin: ' . $e->getMessage() . ' — Please enable it manually in Extensions → Plugins.', 'warning' ); } } } }