Skip to content

Commit

Permalink
Move adding columns into the script. Fixes #40
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonge authored and javigomez committed May 19, 2015
1 parent 9a3c345 commit c23179f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/com_weblinks/admin/sql/updates/mysql/3.4.0.sql
Original file line number Diff line number Diff line change
@@ -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;
30 changes: 30 additions & 0 deletions src/com_weblinks/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public function postflight($type, $parent)

if (strpos($dbName, 'mysql') !== false)
{
// Add Missing Table Colums if needed
$this->addColumnsIfNeeded();

// Drop the Table Colums if needed
$this->dropColumnsIfNeeded();
}
Expand Down Expand Up @@ -202,4 +205,31 @@ private function dropColumnsIfNeeded()
$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();
}
}
}

0 comments on commit c23179f

Please sign in to comment.