diff --git a/src/com_weblinks/admin/sql/updates/mysql/3.4.0.sql b/src/com_weblinks/admin/sql/updates/mysql/3.4.0.sql index e52fac8..894e477 100644 --- a/src/com_weblinks/admin/sql/updates/mysql/3.4.0.sql +++ b/src/com_weblinks/admin/sql/updates/mysql/3.4.0.sql @@ -1,5 +1,3 @@ # This is a rollup of all database schema changes applied from 3.0.0 to 3.3.x -ALTER TABLE `#__weblinks` ENGINE=InnoDB; -ALTER TABLE `#__weblinks` ADD COLUMN `version` int(10) unsigned NOT NULL DEFAULT '1'; -ALTER TABLE `#__weblinks` ADD COLUMN `images` text NOT NULL; +ALTER TABLE `#__weblinks` ENGINE=InnoDB; \ No newline at end of file diff --git a/src/com_weblinks/script.php b/src/com_weblinks/script.php index 219343f..91ad631 100644 --- a/src/com_weblinks/script.php +++ b/src/com_weblinks/script.php @@ -84,6 +84,9 @@ class Com_WeblinksInstallerScript if (strpos($dbName, 'mysql') !== false) { + // Add Missing Table Colums if needed + $this->addColumnsIfNeeded(); + // Drop the Table Colums if needed $this->dropColumnsIfNeeded(); } @@ -202,4 +205,31 @@ class Com_WeblinksInstallerScript $db->execute(); } } + + /** + * Method to add colums from #__weblinks if they are missing. + * + * @return void + * + * @since 3.4.1 + */ + private function addColumnsIfNeeded() + { + $db = JFactory::getDbo(); + $table = $db->getTableColumns('#__weblinks'); + + if (!array_key_exists('version', $table)) + { + $sql = 'ALTER TABLE ' . $db->quoteName('#__weblinks') . ' ADD COLUMN ' . $db->quoteName('version') . " int(10) unsigned NOT NULL DEFAULT '1'"; + $db->setQuery($sql); + $db->execute(); + } + + if (!array_key_exists('images', $table)) + { + $sql = 'ALTER TABLE ' . $db->quoteName('#__weblinks') . ' ADD COLUMN ' . $db->quoteName('images') . ' text NOT NULL'; + $db->setQuery($sql); + $db->execute(); + } + } }