Skip to content

Commit

Permalink
fix: run/rollback migrations on install/uninstall instead of enable/d…
Browse files Browse the repository at this point in the history
…isable
  • Loading branch information
tadhgboyle committed Oct 22, 2024
1 parent c66afb2 commit f646f2a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions modules/Core/pages/panel/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
'actualVersion' => Text::bold(NAMELESS_VERSION)
]) : false,
'disable_link' => (($module->getName() != 'Core' && $item->enabled) ? URL::build('/panel/core/modules/', 'action=disable&m=' . urlencode($item->id)) : null),
'uninstall_link' => ($module->getName() != 'Core' && !$module instanceof ComposerModuleWrapper ? URL::build('/panel/core/modules/', 'action=uninstall&m=' . urlencode($item->id)) : null),
'uninstall_link' => ($module->getName() != 'Core' ? URL::build('/panel/core/modules/', 'action=uninstall&m=' . urlencode($item->id)) : null),
'confirm_uninstall' => $language->get('admin', 'uninstall_confirm', ['item' => Output::getClean($module->getName())]),
'enable_link' => (($module->getName() != 'Core' && !$item->enabled) ? URL::build('/panel/core/modules/', 'action=enable&m=' . urlencode($item->id)) : null),
'enabled' => $item->enabled
Expand Down Expand Up @@ -183,7 +183,6 @@

// We need to boot it so that the Lifecycle Extenders are loaded
ComposerModuleDiscovery::bootModule($container, $composerModule);
$composerModule->runMigrations();
$composerModule->onEnable();

DB::getInstance()->update('modules', $_GET['m'], [
Expand Down Expand Up @@ -307,7 +306,6 @@
// Check if composer module
foreach (ComposerModuleDiscovery::discoverModules() as $composerModule) {
if ($composerModule->getName() === $name) { // compare by ID?
$composerModule->rollbackMigrations();
$composerModule->onDisable();
}
}
Expand Down Expand Up @@ -373,6 +371,7 @@
DB::getInstance()->insert('modules', [
'name' => $composerModule->getName(),
]);
$composerModule->runMigrations();
$composerModule->onInstall();
}
}
Expand Down Expand Up @@ -433,10 +432,17 @@
/** @var Module $module */
require_once(ROOT_PATH . '/modules/' . $name . '/init.php');
$module->onUninstall();
}

if (!Util::recursiveRemoveDirectory(ROOT_PATH . '/modules/' . $name)) {
Session::flash('admin_modules_error', $language->get('admin', 'unable_to_delete_module_files'));
if (!Util::recursiveRemoveDirectory(ROOT_PATH . '/modules/' . $name)) {
Session::flash('admin_modules_error', $language->get('admin', 'unable_to_delete_module_files'));
}
} else {
// Check if composer module
foreach (ComposerModuleDiscovery::discoverModules() as $composerModule) {
if ($composerModule->getName() === $name) { // compare by ID?
$composerModule->rollbackMigrations();
}
}
}

Session::flash('admin_modules', $language->get('admin', 'module_uninstalled'));
Expand Down

0 comments on commit f646f2a

Please sign in to comment.