Move adding columns into the script. Fixes #40

This commit is contained in:
wilsonge 2015-05-19 13:55:01 +02:00 committed by javier gomez
parent 9a3c345e05
commit c23179f1c7
2 changed files with 31 additions and 3 deletions

View File

@ -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;

View File

@ -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();
}
}
}