From f05c30b662092f921dce7ac4b35b7e080f3576ad Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Thu, 4 Jun 2026 13:09:27 -0500 Subject: [PATCH] feat: auto-remove deprecated system plugin on install/upgrade MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The install script now uninstalls plg_system_mokojoomhero if present, cleaning up the old package extension remnant. Uses Joomla Installer for proper DB and file cleanup. Non-critical — silently skips if the plugin is already gone. Authored-by: Moko Consulting Co-Authored-By: Claude Opus 4.6 (1M context) --- src/script.php | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/src/script.php b/src/script.php index 2acf45f..8d9dce9 100644 --- a/src/script.php +++ b/src/script.php @@ -11,17 +11,48 @@ defined('_JEXEC') or die; +use Joomla\CMS\Factory; use Joomla\CMS\Filesystem\Folder; use Joomla\CMS\Installer\InstallerAdapter; class Mod_MokojoomheroInstallerScript { - public function postflight(string $type, InstallerAdapter $adapter): void - { - $heroesPath = JPATH_ROOT . '/images/heroes'; + public function postflight(string $type, InstallerAdapter $adapter): void + { + // Create default image folder on fresh install + $heroesPath = JPATH_ROOT . '/images/heroes'; - if (!is_dir($heroesPath)) { - Folder::create($heroesPath); - } - } + if (!is_dir($heroesPath)) { + Folder::create($heroesPath); + } + + // Remove deprecated system plugin (was part of the old package extension) + $this->removeDeprecatedPlugin(); + } + + /** + * Uninstall plg_system_mokojoomhero if it exists — no longer needed. + */ + private function removeDeprecatedPlugin(): void + { + try { + $db = Factory::getDbo(); + + $query = $db->getQuery(true) + ->select($db->quoteName('extension_id')) + ->from($db->quoteName('#__extensions')) + ->where($db->quoteName('type') . ' = ' . $db->quote('plugin')) + ->where($db->quoteName('folder') . ' = ' . $db->quote('system')) + ->where($db->quoteName('element') . ' = ' . $db->quote('mokojoomhero')); + $db->setQuery($query); + $extensionId = (int) $db->loadResult(); + + if ($extensionId) { + $installer = new \Joomla\CMS\Installer\Installer(); + $installer->uninstall('plugin', $extensionId); + } + } catch (\Exception $e) { + // Non-critical — plugin may already be gone + } + } } -- 2.52.0