feat: auto-remove deprecated system plugin on install/upgrade #66
+38
-7
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user