Skip to content

Commit

Permalink
Fix migration to work with all upgrade/downgrade paths
Browse files Browse the repository at this point in the history
  • Loading branch information
m-ober committed Nov 6, 2023
1 parent c6fc666 commit 2dcf88f
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions migrations/v308/add_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,36 @@

namespace mober\discordnotifications\migrations\v308;

class add_modules extends \phpbb\db\migration\container_aware_migration
class add_modules extends \phpbb\db\migration\migration
{
static public function depends_on()
{
return ['\mober\discordnotifications\migrations\extension_installation'];
}

public function effectively_installed()
{
/** @var \phpbb\db\migration\tool\module $module_manager */
$module_manager = $this->container->get('migrator.tool.module');
return $module_manager->exists('acp', 'ACP_DISCORD_NOTIFICATIONS', 'ACP_DISCORD_NOTIFICATIONS_SETTINGS');
}

public function update_data()
{
return [
['module.remove', [
'acp',
'ACP_DISCORD_NOTIFICATIONS',
[
'module_langname' => 'ACP_DISCORD_NOTIFICATIONS_TITLE',
],
]],
['module.add', [
'acp',
'ACP_DISCORD_NOTIFICATIONS',
[
'module_basename' => '\mober\discordnotifications\acp\discord_notifications_module',
'modes' => [
'settings',
'webhooks',
'mapping',
],
],
]],
['custom', [[$this, 'rename_settings_module']]],
];
}

public function rename_settings_module()
{
$sql = 'UPDATE ' . MODULES_TABLE . "
SET module_langname = 'ACP_DISCORD_NOTIFICATIONS_SETTINGS'
WHERE module_langname = 'ACP_DISCORD_NOTIFICATIONS_TITLE'";
$this->sql_query($sql);
}
}

0 comments on commit 2dcf88f

Please sign in to comment.