From d64d7773c737958ca0470c041894f42599b6ed73 Mon Sep 17 00:00:00 2001 From: Alex Winkler Date: Tue, 7 May 2024 14:37:40 +0200 Subject: [PATCH] add DB migration to drop style column --- extension.json | 6 ++++- resources/scripts/ext.networknotice.Notice.js | 2 +- sql/3_3_0.sql | 1 + networknotice.sql => sql/networknotice.sql | 11 -------- src/Hooks/SchemaHookHandler.php | 25 +++++++++++++++++++ 5 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 sql/3_3_0.sql rename networknotice.sql => sql/networknotice.sql (66%) create mode 100644 src/Hooks/SchemaHookHandler.php diff --git a/extension.json b/extension.json index 39f5805..c722dd3 100644 --- a/extension.json +++ b/extension.json @@ -1,6 +1,6 @@ { "name": "NetworkNotice", - "version": "3.2.1", + "version": "3.3.0", "author": [ "Tephus", "[https://fo-nttax.de Alex Winkler]" @@ -26,10 +26,14 @@ "HookHandlers": { "Main": { "class": "\\Liquipedia\\Extension\\NetworkNotice\\Hooks\\MainHookHandler" + }, + "Schema": { + "class": "\\Liquipedia\\Extension\\NetworkNotice\\Hooks\\SchemaHookHandler" } }, "Hooks": { "BeforePageDisplay": "Main", + "LoadExtensionSchemaUpdates": "Schema", "LPExtensionMenu": [ "Liquipedia\\Extension\\NetworkNotice\\Hooks\\LegacyHooks::onLPExtensionMenu" ], diff --git a/resources/scripts/ext.networknotice.Notice.js b/resources/scripts/ext.networknotice.Notice.js index 6459b36..d1c2be5 100644 --- a/resources/scripts/ext.networknotice.Notice.js +++ b/resources/scripts/ext.networknotice.Notice.js @@ -26,7 +26,7 @@ const items = localStorage.getItem( LOCAL_STORAGE_KEY ); try { return items ? JSON.parse( items ) : []; - } catch( e ) { + } catch ( e ) { return [ ]; } } diff --git a/sql/3_3_0.sql b/sql/3_3_0.sql new file mode 100644 index 0000000..1b2ea69 --- /dev/null +++ b/sql/3_3_0.sql @@ -0,0 +1 @@ +ALTER TABLE `networknotice` DROP `style`; diff --git a/networknotice.sql b/sql/networknotice.sql similarity index 66% rename from networknotice.sql rename to sql/networknotice.sql index 3cb3c33..8e08a08 100644 --- a/networknotice.sql +++ b/sql/networknotice.sql @@ -1,23 +1,12 @@ -SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; -SET time_zone = "+00:00"; - - --- -------------------------------------------------------- --- Table structure for table `networknotice` --- - CREATE TABLE IF NOT EXISTS `networknotice` ( `notice_id` int(11) NOT NULL AUTO_INCREMENT, `label` tinyblob NOT NULL, `wiki` blob NOT NULL, `namespace` tinyblob NOT NULL, `notice_text` blob NOT NULL, - `style` tinyblob NOT NULL, `category` blob NOT NULL, `prefix` blob NOT NULL, `action` blob NOT NULL, `disabled` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`notice_id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=binary; - - diff --git a/src/Hooks/SchemaHookHandler.php b/src/Hooks/SchemaHookHandler.php new file mode 100644 index 0000000..71198c8 --- /dev/null +++ b/src/Hooks/SchemaHookHandler.php @@ -0,0 +1,25 @@ +getMainConfig(); + $db = $updater->getDB(); + if ( !$db->tableExists( $config->get( 'DBname' ) . '.networknotice', __METHOD__ ) ) { + $updater->addExtensionTable( 'networknotice', __DIR__ . '/../../sql/networknotice.sql' ); + } + if ( $db->fieldExists( $config->get( 'DBname' ) . '.networknotice', 'style' ) ) { + $updater->dropExtensionField( 'networknotice', 'style', __DIR__ . '/../../sql/3_3_0.sql' ); + } + } + +}