From 2476bae0ba7e67e2f458fbdd7da12c057330b2df Mon Sep 17 00:00:00 2001 From: vishal adheli Date: Tue, 15 Apr 2025 16:34:24 +0530 Subject: [PATCH 1/4] Issue#238805 Fix: add missing columns in db tables --- .../install.tjnotifications.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/com_tjnotifications/install.tjnotifications.php b/src/com_tjnotifications/install.tjnotifications.php index 15eef954..2c0466db 100644 --- a/src/com_tjnotifications/install.tjnotifications.php +++ b/src/com_tjnotifications/install.tjnotifications.php @@ -128,8 +128,38 @@ public function update($parent) $this->installSqlFiles($parent); $this->fix_db_on_update(); $this->fixMenuLinks(); + $this->addMissingColumns(); } + + private function addMissingColumns() + { + $db = Factory::getDbo(); + $columns = $this->getTableColumns('#__tj_notification_template_configs'); + if (!array_key_exists('webhook_url', $columns)) { + $db->setQuery("ALTER TABLE `#__tj_notification_template_configs` ADD COLUMN `webhook_url` text DEFAULT NULL AFTER `body`;"); + $db->execute(); + } + if (!array_key_exists('use_global_webhook_url', $columns)) { + $db->setQuery("ALTER TABLE `#__tj_notification_template_configs` ADD COLUMN `use_global_webhook_url` TINYINT(1) NOT NULL DEFAULT '1' COMMENT 'Use Global Config Webhook URLs' AFTER `webhook_url`;"); + $db->execute(); + } + $columns = $this->getTableColumns('#__tj_notification_logs'); + if (!array_key_exists('webhook_url', $columns)) { + $db->setQuery("ALTER TABLE `#__tj_notification_logs` ADD COLUMN `webhook_url` TEXT NULL DEFAULT NULL AFTER `body`;"); + $db->execute(); + } + } + + private function getTableColumns($table) + { + $db = Factory::getDbo(); + $db->setQuery("SHOW COLUMNS FROM `$table`"); + $columns = $db->loadColumn(0); + + return array_flip($columns); + } + /** * method to run before an install/update/uninstall method * From c61849f6c8e8711c890912e4c1c66e769d360b8c Mon Sep 17 00:00:00 2001 From: vishal adheli Date: Tue, 15 Apr 2025 16:35:45 +0530 Subject: [PATCH 2/4] code indentation --- .../install.tjnotifications.php | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/com_tjnotifications/install.tjnotifications.php b/src/com_tjnotifications/install.tjnotifications.php index 2c0466db..48bb9fd9 100644 --- a/src/com_tjnotifications/install.tjnotifications.php +++ b/src/com_tjnotifications/install.tjnotifications.php @@ -133,32 +133,32 @@ public function update($parent) private function addMissingColumns() - { - $db = Factory::getDbo(); - $columns = $this->getTableColumns('#__tj_notification_template_configs'); - if (!array_key_exists('webhook_url', $columns)) { - $db->setQuery("ALTER TABLE `#__tj_notification_template_configs` ADD COLUMN `webhook_url` text DEFAULT NULL AFTER `body`;"); - $db->execute(); - } - if (!array_key_exists('use_global_webhook_url', $columns)) { - $db->setQuery("ALTER TABLE `#__tj_notification_template_configs` ADD COLUMN `use_global_webhook_url` TINYINT(1) NOT NULL DEFAULT '1' COMMENT 'Use Global Config Webhook URLs' AFTER `webhook_url`;"); - $db->execute(); - } + { + $db = Factory::getDbo(); + $columns = $this->getTableColumns('#__tj_notification_template_configs'); + if (!array_key_exists('webhook_url', $columns)) { + $db->setQuery("ALTER TABLE `#__tj_notification_template_configs` ADD COLUMN `webhook_url` text DEFAULT NULL AFTER `body`;"); + $db->execute(); + } + if (!array_key_exists('use_global_webhook_url', $columns)) { + $db->setQuery("ALTER TABLE `#__tj_notification_template_configs` ADD COLUMN `use_global_webhook_url` TINYINT(1) NOT NULL DEFAULT '1' COMMENT 'Use Global Config Webhook URLs' AFTER `webhook_url`;"); + $db->execute(); + } $columns = $this->getTableColumns('#__tj_notification_logs'); if (!array_key_exists('webhook_url', $columns)) { - $db->setQuery("ALTER TABLE `#__tj_notification_logs` ADD COLUMN `webhook_url` TEXT NULL DEFAULT NULL AFTER `body`;"); - $db->execute(); - } - } + $db->setQuery("ALTER TABLE `#__tj_notification_logs` ADD COLUMN `webhook_url` TEXT NULL DEFAULT NULL AFTER `body`;"); + $db->execute(); + } + } private function getTableColumns($table) - { - $db = Factory::getDbo(); - $db->setQuery("SHOW COLUMNS FROM `$table`"); - $columns = $db->loadColumn(0); + { + $db = Factory::getDbo(); + $db->setQuery("SHOW COLUMNS FROM `$table`"); + $columns = $db->loadColumn(0); - return array_flip($columns); - } + return array_flip($columns); + } /** * method to run before an install/update/uninstall method From db03e90dadcb4467242b3c813566c222ab0caad1 Mon Sep 17 00:00:00 2001 From: vishal adheli Date: Tue, 15 Apr 2025 17:02:30 +0530 Subject: [PATCH 3/4] add comments --- .../install.tjnotifications.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/com_tjnotifications/install.tjnotifications.php b/src/com_tjnotifications/install.tjnotifications.php index 48bb9fd9..38003d41 100644 --- a/src/com_tjnotifications/install.tjnotifications.php +++ b/src/com_tjnotifications/install.tjnotifications.php @@ -131,7 +131,13 @@ public function update($parent) $this->addMissingColumns(); } - + /** + * method to add missing columns + * + * @param none + * + * @return void + */ private function addMissingColumns() { $db = Factory::getDbo(); @@ -151,6 +157,13 @@ private function addMissingColumns() } } + /** + * method to check is column exists + * + * @param none + * + * @return void + */ private function getTableColumns($table) { $db = Factory::getDbo(); From 3208711f41d965e533466ae228a41ddd04d3e26b Mon Sep 17 00:00:00 2001 From: vishal adheli Date: Tue, 15 Apr 2025 17:10:48 +0530 Subject: [PATCH 4/4] optimize query, use joomla function to check if column exists --- .../install.tjnotifications.php | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/com_tjnotifications/install.tjnotifications.php b/src/com_tjnotifications/install.tjnotifications.php index 38003d41..5630c7ab 100644 --- a/src/com_tjnotifications/install.tjnotifications.php +++ b/src/com_tjnotifications/install.tjnotifications.php @@ -141,7 +141,7 @@ public function update($parent) private function addMissingColumns() { $db = Factory::getDbo(); - $columns = $this->getTableColumns('#__tj_notification_template_configs'); + $columns = $db->getTableColumns('#__tj_notification_template_configs'); if (!array_key_exists('webhook_url', $columns)) { $db->setQuery("ALTER TABLE `#__tj_notification_template_configs` ADD COLUMN `webhook_url` text DEFAULT NULL AFTER `body`;"); $db->execute(); @@ -150,29 +150,13 @@ private function addMissingColumns() $db->setQuery("ALTER TABLE `#__tj_notification_template_configs` ADD COLUMN `use_global_webhook_url` TINYINT(1) NOT NULL DEFAULT '1' COMMENT 'Use Global Config Webhook URLs' AFTER `webhook_url`;"); $db->execute(); } - $columns = $this->getTableColumns('#__tj_notification_logs'); + $columns = $db->getTableColumns('#__tj_notification_logs'); if (!array_key_exists('webhook_url', $columns)) { $db->setQuery("ALTER TABLE `#__tj_notification_logs` ADD COLUMN `webhook_url` TEXT NULL DEFAULT NULL AFTER `body`;"); $db->execute(); } } - /** - * method to check is column exists - * - * @param none - * - * @return void - */ - private function getTableColumns($table) - { - $db = Factory::getDbo(); - $db->setQuery("SHOW COLUMNS FROM `$table`"); - $columns = $db->loadColumn(0); - - return array_flip($columns); - } - /** * method to run before an install/update/uninstall method *