<?php

if (!defined('UPGRADE_RUN')) { exit; }

/* UPGRADE - INDEXES
------------------------------------------------------*/

mswUpLog('Check all live indexes are set', 'instruction');

foreach(array(
  /* Affiliates
  ------------------------------------------------------------*/
  '01_affiliates' => array('code', 'code'),
  '02_affiliates' => array('email', 'email'),
  '03_affiliates' => array('approved', 'approved'),
  '04_affiliates' => array('en', 'en'),
  '05_affiliates' => array('fname', 'fname'),
  '06_affiliates' => array('lname', 'lname'),
  
  /* Affiliates Commissions
  ------------------------------------------------------------*/
  '01_affiliates_commissions' => array('affid', 'affid'),
  '02_affiliates_commissions' => array('approved', 'approved'),
  '03_affiliates_commissions' => array('en', 'en'),
  '04_affiliates_commissions' => array('product', 'product'),
  
  /* Affiliates Payments
  ------------------------------------------------------------*/
  '01_affiliates_payments' => array('affid', 'affid'),
  
  /* Affiliates Tracking
  ------------------------------------------------------------*/
  '01_affiliates_tracking' => array('affid', 'affid'),
  '02_affiliates_tracking' => array('product', 'product'),
  
  /* Social
  ------------------------------------------------------------*/
  '01_social' => array('desc', 'desc')

) AS $k => $v) {
  $table = substr($k, 3);
  if (!isset($v[2])) {
    $v[2] = 'def';
  }
  if (mswCheckIndex($table, $v[1], $DB) == 'no') {
    $q = $DB->db_query("alter table `" . DB_PREFIX . $table . "` add index `" . $v[1] . "` (`" . $v[0] . "`)", true);
    if ($q === 'err') {
      $ERR = $DB->db_error(true);
      mswUpLog(DB_PREFIX . $table, $ERR[1], $ERR[0], __LINE__, __FILE__, 'Add Index');
    } else {
      mswUpLog('Index added to ' . $table . ': ' . $v[1], 'instruction');
    }
  } else {
    mswUpLog('Index ' . $v[1] . ' exists in ' . $table . ' and will be ignored', 'instruction');
  }
}


?>