feat: auto-remove deprecated system plugin on install/upgrade #66

Merged
jmiller merged 1 commits from dev into main 2026-06-04 18:13:43 +00:00
+38 -7
View File
@@ -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
}
}
}