public function addColumnIfNotExist($db, $table, $field, $attr)
{
$exists = false;
$columns = $db->fetchAll("SHOW columns FROM `".$table."`");
foreach ($columns AS $column)
{
if ($column['Field'] == $field)
{
$exists = true;
break;
}
}
if (!$exists)
{
$db->query("ALTER TABLE `".$table."` ADD `".$field."` ".$attr);
}
return true;
}
public static function install($existingAddOn, $addOnData)
{
$start_at = 0;
$finish_at = $addOnData['version_id'];
if ($existingAddOn)
{
// if the addon already exists, it has a version id, retrieve it and increase it by one for our new starting point
$start_at = $existingAddOn['version_id'];
$start_at++;
}
for ($x = $start_at; $x <= $finish_at; $x++)
{
switch ($x)
{
case 0:
// initial DB query here (or function call) as this is the first install
break;
case 4:
// version updates 2 and 3 needed no DB changes, but version 4 does
break;
default:
break;
}
}
// rebuild caches and all done
XenForo_Model::create('XenForo_Model_ContentType')->rebuildContentTypeCache();
}