Location: PHPKode > projects > Esvon Personals > esvon-personals/upgrades/v4_to_v4_09/upgrade401-402.php
<?php

// File to upgrade Esvon Classifieds from 4.0.1 to 4.0.2
// After use this, you can delete it

//*********************************************

define('DB_UPGRADE', 1);

if(!defined('SITE_PATH')){
  if(!file_exists('./inc/application.php')) die("File Not Found: application.php");
  require_once './inc/application.php';
}

mysql_query("ALTER TABLE ".TBL_PAY_PEND." ADD ref_id varchar(255) NOT NULL");

mysql_query("ALTER TABLE ".TBL_FIELD." ADD attr varchar(255) NOT NULL");

if(hwModGetState('Compare_Items')){
  mysql_query("CREATE TABLE ".hwModTable('Compare_Items','disabled_fields')." (
  fset varchar(30) NOT NULL,
  fid varchar(40) NOT NULL,
  PRIMARY KEY (fset, fid))");
}

if(hwModGetState('Auction')){
  mysql_query("CREATE TABLE ".hwModTable('Auction','banned_bidder')." (
   bidder_id mediumint(8) unsigned NOT NULL,
   seller_id mediumint(8) unsigned NOT NULL,
   PRIMARY KEY (bidder_id, seller_id))");
}


$A_KEY_APR = array(
  'approved' => 1,
  'user_approved' => 1,
  'exp_date' => 1,
);

$res = $db->query('SHOW KEYS FROM '.TBL_AD);
while($v = mysql_fetch_assoc($res)){
  if($v['Key_name']=='approved' && isset($A_KEY_APR[$v['Column_name']])) unset($A_KEY_APR[$v['Column_name']]);
}

if(!empty($A_KEY_APR)){
  mysql_query("ALTER TABLE ".TBL_AD." DROP KEY approved");
  mysql_query("ALTER TABLE ".TBL_AD." ADD KEY approved (approved, user_approved, exp_date)");
}

mysql_query("ALTER TABLE ".TBL_PAY_PLAN." ADD weight smallint(5) unsigned DEFAULT '0' NOT NULL");


// Due to changed VARBINARY behaviour since MySQL 5.x

if($db->version() > 50000) {

  $a_vb = array(
    TBL_SETTINGS => 'login',
    TBL_REG_CONFIRM => 'code',
    TBL_USER => 'pwd',
  );

  if(hwModGetState('Affiliates')){
    $a_vb[ hwModTable('Affiliates','register') ] = 'code';
    $a_vb[ hwModTable('Affiliates','user') ] = 'pwd';
  }

  if(hwModGetState('Editors')){
    $a_vb[ hwModTable('Editors','user') ] = 'pwd';
  }

  foreach($a_vb as $tbl => $db_f){
    $val = $db->one_data('SELECT '.$db_f.' FROM '.$tbl.' WHERE '.$db_f.'<>"" LIMIT 1');
    if($val != rtrim($val)){
      $db->query('ALTER TABLE '.$tbl.' MODIFY '.$db_f.' varchar(20) NOT NULL');
      $db->query('UPDATE '.$tbl.' SET '.$db_f.'=TRIM(TRAILING "\0" FROM '.$db_f.')');
    }
  }

}

mysql_query("ALTER TABLE ".TBL_USER." MODIFY lastlogin_ip varchar(255) NOT NULL"); 

echo 'Esvon Classifieds Tables Updated, Ok.. ('.basename(__FILE__).')';


?>
Return current item: Esvon Personals