コード例 #1
0
 /**
  * Init DB
  */
 public function __construct()
 {
     parent::__construct();
 }
コード例 #2
0
ファイル: EbayOrdersModel.php プロジェクト: booklein/wpbookle
 function getDateOfLastOrder($account_id)
 {
     global $wpdb;
     $lastdate = $wpdb->get_var($wpdb->prepare("\n\t\t\tSELECT LastTimeModified\n\t\t\tFROM {$this->tablename}\n\t\t\tWHERE account_id = %s\n\t\t\tORDER BY LastTimeModified DESC LIMIT 1\n\t\t", $account_id));
     // if there are no orders yet, check the date of the last transaction
     if (!$lastdate) {
         $tm = new TransactionsModel();
         $lastdate = $tm->getDateOfLastCreatedTransaction($account_id);
         if ($lastdate) {
             // add two minutes to prevent importing the same transaction again
             $lastdate = mysql2date('U', $lastdate) + 120;
             $lastdate = date('Y-m-d H:i:s', $lastdate);
         }
     }
     return $lastdate;
 }
コード例 #3
0
 /**
  * Remove all records associated with a transaction
  * @return bool
  */
 private function deleteTransactionRecords()
 {
     $transMdl = new TransactionsModel();
     if ($transMdl->remove($this->data->id) === false) {
         return false;
     }
     $itemMdl = new SaleItemsModel();
     if ($itemMdl->removeBySale($this->data->id) === false) {
         return false;
     }
     $payMdl = new SalePaymentsModel();
     if ($payMdl->removeBySale($this->data->id) === false) {
         return false;
     }
     $voidMdl = new SaleVoidsModel();
     if ($voidMdl->removeBySale($this->data->id) === false) {
         return false;
     }
     $histMdl = new TransHistModel();
     if ($histMdl->removeBySale($this->data->id) === false) {
         return false;
     }
     return true;
 }
コード例 #4
0
 public function showTransactionDetails($id)
 {
     // init model
     $transactionsModel = new TransactionsModel();
     // get transaction record
     $transaction = $transactionsModel->getItem($id);
     // get auction item record
     $auction_item = ListingsModel::getItemByEbayID($transaction['item_id']);
     $aData = array('transaction' => $transaction, 'auction_item' => $auction_item);
     $this->display('transaction_details', $aData);
 }
コード例 #5
0
ファイル: WposAdminStats.php プロジェクト: razmir/wallacepos
 /**
  * Get grouped sales stats for the current range, grouped by user, device or location
  * @param $result
  * @param string $type
  * @return mixed
  */
 public function getDeviceBreakdownStats($result, $type = 'device')
 {
     $stats = [];
     $salesMdl = new TransactionsModel();
     $voidMdl = new SaleVoidsModel();
     // check if params set, if not set defaults
     $stime = isset($this->data->stime) ? $this->data->stime : strtotime('-1 week') * 1000;
     $etime = isset($this->data->etime) ? $this->data->etime : time() * 1000;
     // setup default object
     $defaults = new stdClass();
     $defaults->refs = '';
     $defaults->refundrefs = '';
     $defaults->voidtotal = 0;
     $defaults->voidnum = 0;
     $defaults->saletotal = 0;
     $defaults->salenum = 0;
     $defaults->refundtotal = 0;
     $defaults->refundnum = 0;
     // get non voided sales
     if (($sales = $salesMdl->getGroupedTotals($stime, $etime, 3, false, $type)) !== false) {
         foreach ($sales as $sale) {
             if ($sale['groupid'] == null) {
                 $sale['name'] = "Admin Dash";
             }
             if (!isset($stats[$sale['groupid']])) {
                 $stats[$sale['groupid']] = clone $defaults;
                 $stats[$sale['groupid']]->name = $sale['name'];
             }
             $stats[$sale['groupid']]->refs = $sale['refs'];
             $stats[$sale['groupid']]->salerefs = $sale['refs'];
             $stats[$sale['groupid']]->saletotal = $sale['stotal'];
             $stats[$sale['groupid']]->salenum = $sale['snum'];
         }
     } else {
         $result['error'] = "Error getting sales: " . $salesMdl->errorInfo;
     }
     // get voided sales
     if (($voids = $salesMdl->getGroupedTotals($stime, $etime, 3, true, $type)) !== false) {
         foreach ($voids as $void) {
             if ($void['groupid'] == null) {
                 $sale['name'] = "Admin Dash";
             }
             if (!isset($stats[$void['groupid']])) {
                 $stats[$void['groupid']] = clone $defaults;
                 $stats[$void['groupid']]->name = $void['name'];
             }
             $stats[$void['groupid']]->refs .= ($stats[$void['groupid']]->refs == '' ? '' : ',') . $void['refs'];
             $stats[$void['groupid']]->voidrefs = $void['refs'];
             $stats[$void['groupid']]->voidtotal = $void['stotal'];
             $stats[$void['groupid']]->voidnum = $void['snum'];
         }
     } else {
         $result['error'] = "Error getting voided sales: " . $salesMdl->errorInfo;
     }
     // get refunds
     if (($refunds = $voidMdl->getGroupedTotals($stime, $etime, false, $type)) !== false) {
         foreach ($refunds as $refund) {
             if ($refund['groupid'] == null) {
                 $sale['name'] = "Admin Dash";
             }
             if (!isset($stats[$refund['groupid']])) {
                 $stats[$refund['groupid']] = clone $defaults;
                 $stats[$refund['groupid']]->name = $refund['name'];
             }
             $stats[$refund['groupid']]->refs .= ($stats[$refund['groupid']]->refs == '' ? '' : ',') . $refund['refs'];
             $stats[$refund['groupid']]->refundrefs = $refund['refs'];
             $stats[$refund['groupid']]->refundtotal = $refund['stotal'];
             $stats[$refund['groupid']]->refundnum = $refund['snum'];
         }
     } else {
         $result['error'] = "Error getting refunds: " . $voidMdl->errorInfo;
     }
     // calc total takings for each device/location
     foreach ($stats as $key => $stat) {
         $stats[$key]->balance = number_format($stat->saletotal - $stat->refundtotal, 2, '.', '');
     }
     // include totals if requested
     if ($this->data->totals == true) {
         $result = $this->getOverviewStats($result);
         $stats["Totals"] = $result['data'];
     }
     $result['data'] = $stats;
     return $result;
 }
コード例 #6
0
 /** ************************************************************************
  * REQUIRED! This is where you prepare your data for display. This method will
  * usually be used to query the database, sort and filter the data, and generally
  * get it ready to be displayed. At a minimum, we should set $this->items and
  * $this->set_pagination_args(), although the following properties and methods
  * are frequently interacted with here...
  * 
  * @uses $this->_column_headers
  * @uses $this->items
  * @uses $this->get_columns()
  * @uses $this->get_sortable_columns()
  * @uses $this->get_pagenum()
  * @uses $this->set_pagination_args()
  **************************************************************************/
 function prepare_items()
 {
     // process bulk actions
     $this->process_bulk_action();
     // get pagination state
     $current_page = $this->get_pagenum();
     $per_page = $this->get_items_per_page('transactions_per_page', 20);
     // define columns
     $this->_column_headers = $this->get_column_info();
     // fetch profiles from model
     $transactionsModel = new TransactionsModel();
     $this->items = $transactionsModel->getPageItems($current_page, $per_page);
     $total_items = $transactionsModel->total_items;
     // register our pagination options & calculations.
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
 }
コード例 #7
0
 /**
  * Get all transactions for the current customer
  * @param $result
  * @return mixed
  */
 public function getCustomerTransactions($result)
 {
     // Safety check
     if (!isset($_SESSION['cust_id'])) {
         $result['error'] = "Customer ID not found in current session";
         return $result;
     }
     // Get customer transactions
     $transMdl = new TransactionsModel();
     $trans = $transMdl->getByCustomer($_SESSION['cust_id']);
     if ($trans === false) {
         $result['error'] = "Could not fetch your transactions: " . $transMdl->errorInfo;
     } else {
         $result['data'] = [];
         // decode JSON and add extras
         foreach ($trans as $tran) {
             $record = json_decode($tran['data']);
             $record->type = $tran['type'];
             $result['data'][$tran['ref']] = $record;
         }
     }
     return $result;
 }
コード例 #8
0
ファイル: ToolsPage.php プロジェクト: booklein/wpbookle
 public function checkTransactions($show_message = false)
 {
     $om = new EbayOrdersModel();
     $tm = new TransactionsModel();
     $orders = $om->getAll();
     // echo "<pre>";print_r($orders);echo"</pre>";#die();
     $created_transactions = 0;
     $pending_orders = 0;
     // loop orders
     foreach ($orders as $order) {
         $order_details = $om->decodeObject($order['details'], false, true);
         // echo "<pre>";print_r($order_details);echo"</pre>";#die();
         // skip if this order has been processed already
         if ($tm->getTransactionByEbayOrderID($order['order_id'])) {
             continue;
         }
         // limit processing to 500 orders at a time
         if ($created_transactions >= 500) {
             $pending_orders++;
             continue;
         }
         // loop transactions
         $transactions = $order_details->TransactionArray;
         foreach ($transactions as $Transaction) {
             // echo "<pre>";print_r($Transaction->TransactionID);echo"</pre>";#die();
             // $transaction_id = $Transaction->TransactionID;
             // create transaction
             $txn_id = $tm->createTransactionFromEbayOrder($order, $Transaction);
             // echo "<pre>created transaction ";print_r($Transaction->TransactionID);echo"</pre>";#die();
             $created_transactions++;
         }
     }
     $msg = $created_transactions . ' transactions were created.<br><br>';
     if ($pending_orders) {
         $msg .= 'There are ' . $pending_orders . ' more orders to process. Please run this check again until all orders have been processed.';
     } else {
         $msg .= 'Please visit the <a href="admin.php?page=wplister-transactions">Transactions</a> page to check for duplicates.';
     }
     if ($show_message) {
         $this->showMessage($msg);
     }
     // return number of orders which still need to be processed
     return $pending_orders;
 }
コード例 #9
0
 public static function upgradeDB()
 {
     global $wpdb;
     $db_version = get_option('wplister_db_version', 0);
     $hide_message = $db_version == 0 ? true : false;
     $msg = false;
     // initialize db with version 4
     if (4 > $db_version) {
         $new_db_version = 4;
         // create table: ebay_auctions
         $sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ebay_auctions` (\n\t\t\t  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t  `ebay_id` bigint(255) DEFAULT NULL,\n\t\t\t  `auction_title` varchar(255) DEFAULT NULL,\n\t\t\t  `auction_type` varchar(255) DEFAULT NULL,\n\t\t\t  `listing_duration` varchar(255) DEFAULT NULL,\n\t\t\t  `date_created` datetime DEFAULT NULL,\n\t\t\t  `date_published` datetime DEFAULT NULL,\n\t\t\t  `date_finished` datetime DEFAULT NULL,\n\t\t\t  `end_date` datetime DEFAULT NULL,\n\t\t\t  `price` float DEFAULT NULL,\n\t\t\t  `quantity` int(11) DEFAULT NULL,\n\t\t\t  `quantity_sold` int(11) DEFAULT NULL,\n\t\t\t  `status` varchar(50) DEFAULT NULL,\n\t\t\t  `details` text,\n\t\t\t  `ViewItemURL` varchar(255) DEFAULT NULL,\n\t\t\t  `GalleryURL` varchar(255) DEFAULT NULL,\n\t\t\t  `post_content` text,\n\t\t\t  `post_id` int(11) DEFAULT NULL,\n\t\t\t  `profile_id` int(11) DEFAULT NULL,\n\t\t\t  `profile_data` text,\n\t\t\t  `template` varchar(255) DEFAULT '',\n\t\t\t  `fees` float DEFAULT NULL,\n\t\t\t  PRIMARY KEY  (`id`)\n\t\t\t);";
         #dbDelta($sql);
         $wpdb->query($sql);
         echo $wpdb->last_error;
         // create table: ebay_categories
         $sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ebay_categories` (\n\t\t\t  `cat_id` bigint(16) DEFAULT NULL,\n\t\t\t  `parent_cat_id` bigint(11) DEFAULT NULL,\n\t\t\t  `level` int(11) DEFAULT NULL,\n\t\t\t  `leaf` tinyint(4) DEFAULT NULL,\n\t\t\t  `version` int(11) DEFAULT NULL,\n\t\t\t  `cat_name` varchar(255) DEFAULT NULL,\n\t\t\t  `wp_term_id` int(11) DEFAULT NULL,\n\t\t\t  KEY `cat_id` (`cat_id`),\n\t\t\t  KEY `parent_cat_id` (`parent_cat_id`)\t\t\n\t\t\t);";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         // create table: ebay_store_categories
         $sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ebay_store_categories` (\n\t\t\t  `cat_id` bigint(20) DEFAULT NULL,\n\t\t\t  `parent_cat_id` bigint(20) DEFAULT NULL,\n\t\t\t  `level` int(11) DEFAULT NULL,\n\t\t\t  `leaf` tinyint(4) DEFAULT NULL,\n\t\t\t  `version` int(11) DEFAULT NULL,\n\t\t\t  `cat_name` varchar(255) DEFAULT NULL,\n\t\t\t  `order` int(11) DEFAULT NULL,\n\t\t\t  `wp_term_id` int(11) DEFAULT NULL,\n\t\t\t  KEY `cat_id` (`cat_id`),\n\t\t\t  KEY `parent_cat_id` (`parent_cat_id`)\t\t\n\t\t\t);";
         $wpdb->query($sql);
         // create table: ebay_payment
         $sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ebay_payment` (\n\t\t\t  `payment_name` varchar(255) DEFAULT NULL,\n\t\t\t  `payment_description` varchar(255) DEFAULT NULL,\n\t\t\t  `version` int(11) DEFAULT NULL\t\n\t\t\t);";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         // create table: ebay_profiles
         $sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ebay_profiles` (\n\t\t\t  `profile_id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t  `profile_name` varchar(255) DEFAULT NULL,\n\t\t\t  `profile_description` varchar(255) DEFAULT NULL,\n\t\t\t  `listing_duration` varchar(255) DEFAULT NULL,\n\t\t\t  `type` varchar(255) DEFAULT NULL,\n\t\t\t  `details` text,\n\t\t\t  `conditions` text,\n\t\t\t  PRIMARY KEY  (`profile_id`)\t\n\t\t\t);";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         // create table: ebay_shipping
         $sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ebay_shipping` (\n\t\t\t  `service_id` int(11) DEFAULT NULL,\n\t\t\t  `service_name` varchar(255) DEFAULT NULL,\n\t\t\t  `service_description` varchar(255) DEFAULT NULL,\n\t\t\t  `carrier` varchar(255) DEFAULT NULL,\n\t\t\t  `international` tinyint(4) DEFAULT NULL,\n\t\t\t  `version` int(11) DEFAULT NULL\t\n\t\t\t);";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         // create table: ebay_transactions
         $sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ebay_transactions` (\n\t\t\t  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t  `item_id` bigint(255) DEFAULT NULL,\n\t\t\t  `transaction_id` bigint(255) DEFAULT NULL,\n\t\t\t  `date_created` datetime DEFAULT NULL,\n\t\t\t  `item_title` varchar(255) DEFAULT NULL,\n\t\t\t  `price` float DEFAULT NULL,\n\t\t\t  `quantity` int(11) DEFAULT NULL,\n\t\t\t  `status` varchar(50) DEFAULT NULL,\n\t\t\t  `details` text,\n\t\t\t  `post_id` int(11) DEFAULT NULL,\n\t\t\t  `buyer_userid` varchar(255) DEFAULT NULL,\n\t\t\t  `buyer_name` varchar(255) DEFAULT NULL,\n\t\t\t  `buyer_email` varchar(255) DEFAULT NULL,\n\t\t\t  `eBayPaymentStatus` varchar(50) DEFAULT NULL,\n\t\t\t  `CheckoutStatus` varchar(50) DEFAULT NULL,\n\t\t\t  `ShippingService` varchar(50) DEFAULT NULL,\n\t\t\t  `PaymentMethod` varchar(50) DEFAULT NULL,\n\t\t\t  `ShippingAddress_City` varchar(50) DEFAULT NULL,\n\t\t\t  `CompleteStatus` varchar(50) DEFAULT NULL,\n\t\t\t  `LastTimeModified` datetime DEFAULT NULL,\n\t\t\t  PRIMARY KEY (`id`)\n\t  \t\t);";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         // create table: ebay_log
         $sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ebay_log` (\n\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t  `timestamp` datetime DEFAULT NULL,\n\t\t\t  `request_url` text DEFAULT NULL,\n\t\t\t  `request` text DEFAULT NULL,\n\t\t\t  `response` text DEFAULT NULL,\n\t\t\t  `callname` varchar(64) DEFAULT NULL,\n\t\t\t  `success` varchar(16) DEFAULT NULL,\n\t\t\t  `ebay_id` bigint(255) DEFAULT NULL,\n\t\t\t  `user_id` int(11) DEFAULT NULL,\t\n\t\t\t  PRIMARY KEY (`id`)\t\n\t\t\t);";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         // $db_version = $new_db_version;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     /*
     // upgrade to version 2
     if ( 2 > $db_version ) {
     	$new_db_version = 2;
     
     	// create table: ebay_log
     	$sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ebay_log` (
     	  `id` int(11) NOT NULL AUTO_INCREMENT,
     	  `timestamp` datetime DEFAULT NULL,
     	  `request_url` text DEFAULT NULL,
     	  `request` text DEFAULT NULL,
     	  `response` text DEFAULT NULL,
     	  `callname` varchar(64) DEFAULT NULL,
     	  `success` varchar(16) DEFAULT NULL,
     	  `ebay_id` bigint(255) DEFAULT NULL,
     	  `user_id` int(11) DEFAULT NULL,	
     	  PRIMARY KEY (`id`)	
     	);";
     	$wpdb->query($sql);	echo $wpdb->last_error;
     
     	update_option('wplister_db_version', $new_db_version);
     	$msg  = __('Database was upgraded to version', 'wplister') .' '. $new_db_version . '.';
     }
     
     // upgrade to version 3
     if ( 3 > $db_version ) {
     	$new_db_version = 3;
     
     	// rename column in table: ebay_categories
     	$sql = "ALTER TABLE `{$wpdb->prefix}ebay_categories`
     	        CHANGE wpsc_category_id wp_term_id INTEGER ";
     	$wpdb->query($sql);	echo $wpdb->last_error;
     
     	// rename column in table: ebay_store_categories
     	$sql = "ALTER TABLE `{$wpdb->prefix}ebay_store_categories`
     	        CHANGE wpsc_category_id wp_term_id INTEGER ";
     	$wpdb->query($sql);	echo $wpdb->last_error;
     	
     	update_option('wplister_db_version', $new_db_version);
     	$msg  = __('Database was upgraded to version', 'wplister') .' '. $new_db_version . '.';
     }
     
     // upgrade to version 4
     if ( 4 > $db_version ) {
     	$new_db_version = 4;
     
     	// set column type to bigint in table: ebay_store_categories
     	$sql = "ALTER TABLE `{$wpdb->prefix}ebay_store_categories`
     	        CHANGE cat_id cat_id BIGINT ";
     	$wpdb->query($sql);	echo $wpdb->last_error;
     	
     	// set column type to bigint in table: ebay_store_categories
     	$sql = "ALTER TABLE `{$wpdb->prefix}ebay_store_categories`
     	        CHANGE parent_cat_id parent_cat_id BIGINT ";
     	$wpdb->query($sql);	echo $wpdb->last_error;
     	
     	update_option('wplister_db_version', $new_db_version);
     	$msg  = __('Database was upgraded to version', 'wplister') .' '. $new_db_version . '.';
     }
     */
     // TODO: include upgrade 5-9 in WPLister_Install class
     // upgrade to version 5
     if (5 > $db_version) {
         $new_db_version = 5;
         // create table: ebay_log
         $sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ebay_jobs` (\n\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t  `job_key` varchar(64) DEFAULT NULL,\n\t\t\t  `job_name` varchar(64) DEFAULT NULL,\n\t\t\t  `tasklist` text DEFAULT NULL,\n\t\t\t  `results` text DEFAULT NULL,\n\t\t\t  `success` varchar(16) DEFAULT NULL,\n\t\t\t  `date_created` datetime DEFAULT NULL,\n\t\t\t  `date_finished` datetime DEFAULT NULL,\n\t\t\t  `user_id` int(11) DEFAULT NULL,\t\n\t\t\t  PRIMARY KEY (`id`)\t\n\t\t\t);";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 6
     if (6 > $db_version) {
         $new_db_version = 6;
         // add columns to ebay_shipping table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_shipping`\n\t\t\t        ADD COLUMN `ShippingCategory` varchar(64) DEFAULT NULL AFTER `carrier`, \n\t\t\t        ADD COLUMN `WeightRequired` int(10) UNSIGNED NOT NULL DEFAULT 0 AFTER `international`, \n\t\t\t        ADD COLUMN `DimensionsRequired` int(10) UNSIGNED NOT NULL DEFAULT 0 AFTER `international`, \n\t\t\t        ADD COLUMN `isCalculated` int(10) UNSIGNED NOT NULL DEFAULT 0 AFTER `international`, \n\t\t\t        ADD COLUMN `isFlat` int(10) UNSIGNED NOT NULL DEFAULT 0 AFTER `international`;\n\t\t\t";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 7  (0.9.7.9)
     if (7 > $db_version) {
         $new_db_version = 7;
         // set admin_email as default license_email
         update_option('wplister_license_email', get_bloginfo('admin_email'));
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 8
     if (8 > $db_version) {
         $new_db_version = 8;
         // add columns to ebay_shipping table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_profiles`\n\t\t\t        ADD COLUMN `category_specifics` text DEFAULT NULL;\n\t\t\t";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 9  (1.0)
     if (9 > $db_version) {
         $new_db_version = 9;
         // add update channel option
         update_option('wplister_update_channel', 'stable');
         update_option('wple_update_channel', 'stable');
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 10  (1.0.7)
     if (10 > $db_version) {
         $new_db_version = 10;
         // add column to ebay_transactions table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_transactions`\n\t\t\t        ADD COLUMN `wp_order_id` int(10) UNSIGNED NOT NULL DEFAULT 0 AFTER `post_id`\n\t\t\t";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 11  (1.0.8.8)
     if (11 > $db_version) {
         $new_db_version = 11;
         // fetch available dispatch times - disabled in 2.0.3
         // if ( get_option('wplister_ebay_token') != '' ) {
         // 	$this->initEC();
         // 	$result = $this->EC->loadDispatchTimes();
         // 	$this->EC->closeEbay();
         // }
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 12  (1.0.9.8)
     if (12 > $db_version) {
         $new_db_version = 12;
         // fetch all transactions
         $sql = "SELECT id FROM `{$wpdb->prefix}ebay_transactions` ";
         $items = $wpdb->get_results($sql);
         echo $wpdb->last_error;
         // find and assign orders
         $tm = new TransactionsModel();
         foreach ($items as $transaction) {
             // fetch item details
             $item = $tm->getItem($transaction->id);
             $details = $item['details'];
             // build order title (WooCommerce only)
             $post_title = 'Order &ndash; ' . date('F j, Y @ h:i A', strtotime($details->CreatedDate));
             // find created order
             $sql = "\n\t\t\t\t\tSELECT ID FROM `{$wpdb->prefix}posts`\n\t\t\t\t\tWHERE post_title = '{$post_title}'\n\t\t\t\t\t  AND post_status = 'publish'\n\t\t\t\t";
             $post_id = $wpdb->get_var($sql);
             echo $wpdb->last_error;
             // set order_id for transaction
             $tm->updateWpOrderID($transaction->id, $post_id);
             // Update post data
             update_post_meta($post_id, '_transaction_id', $transaction->id);
             update_post_meta($post_id, '_ebay_item_id', $item['item_id']);
             update_post_meta($post_id, '_ebay_transaction_id', $item['transaction_id']);
         }
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 13  (1.1.0.2)
     if (13 > $db_version) {
         $new_db_version = 13;
         // add column to ebay_transactions table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_transactions`\n\t\t\t        ADD COLUMN `OrderLineItemID` varchar(64) DEFAULT NULL AFTER `transaction_id`\n\t\t\t";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 14  (1.1.0.4)
     if (14 > $db_version) {
         $new_db_version = 14;
         // remove invalid transactions - update on next cron schedule
         $sql = "DELETE FROM `{$wpdb->prefix}ebay_transactions`\n\t\t\t        WHERE transaction_id = 0\n\t\t\t";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 15  (1.1.5.4)
     if (15 > $db_version) {
         $new_db_version = 15;
         // add column to ebay_categories table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_categories`\n\t\t\t        ADD COLUMN `site_id` int(10) UNSIGNED DEFAULT NULL AFTER `wp_term_id`\n\t\t\t";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 16  (1.1.6.3)
     if (16 > $db_version) {
         $new_db_version = 16;
         // add column to ebay_auctions table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_auctions`\n\t\t\t        ADD COLUMN `history` TEXT AFTER `fees`\n\t\t\t";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 17  (1.2.0.12)
     if (17 > $db_version) {
         $new_db_version = 17;
         // fetch available shipping packages - disabled in 2.0.3
         // if ( get_option('wplister_ebay_token') != '' ) {
         // 	$this->initEC();
         // 	$result = $this->EC->loadShippingPackages();
         // 	$this->EC->closeEbay();
         // }
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 18 (1.2.0.18)
     if (18 > $db_version) {
         $new_db_version = 18;
         // set column type to bigint in table: ebay_auctions
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_auctions`\n\t\t\t        CHANGE post_id post_id BIGINT ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         // set column type to bigint in table: ebay_transactions
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_transactions`\n\t\t\t        CHANGE post_id post_id BIGINT ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         // set column type to bigint in table: ebay_transactions
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_transactions`\n\t\t\t        CHANGE wp_order_id wp_order_id BIGINT ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 19  (1.2.1.5)
     if (19 > $db_version) {
         $new_db_version = 19;
         // add column to ebay_auctions table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_auctions`\n\t\t\t        ADD COLUMN `eps` TEXT AFTER `history`\n\t\t\t";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 20  (1.2.2.16)
     if (20 > $db_version) {
         $new_db_version = 20;
         // add column to ebay_transactions table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_transactions`\n\t\t\t        ADD COLUMN `history` TEXT AFTER `details`\n\t\t\t";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 21  (1.2.2.16)
     if (21 > $db_version) {
         $new_db_version = 21;
         // create table: ebay_orders
         $sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ebay_orders` (\n\t\t\t  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t  `order_id` varchar(128) DEFAULT NULL,\n\t\t\t  `date_created` datetime DEFAULT NULL,\n\t\t\t  `total` float DEFAULT NULL,\n\t\t\t  `status` varchar(50) DEFAULT NULL,\n\t\t\t  `post_id` int(11) DEFAULT NULL,\n\t\t\t  `items` text,\n\t\t\t  `details` text,\n\t\t\t  `history` text,\n\t\t\t  `buyer_userid` varchar(255) DEFAULT NULL,\n\t\t\t  `buyer_name` varchar(255) DEFAULT NULL,\n\t\t\t  `buyer_email` varchar(255) DEFAULT NULL,\n\t\t\t  `eBayPaymentStatus` varchar(50) DEFAULT NULL,\n\t\t\t  `CheckoutStatus` varchar(50) DEFAULT NULL,\n\t\t\t  `ShippingService` varchar(50) DEFAULT NULL,\n\t\t\t  `PaymentMethod` varchar(50) DEFAULT NULL,\n\t\t\t  `ShippingAddress_City` varchar(50) DEFAULT NULL,\n\t\t\t  `CompleteStatus` varchar(50) DEFAULT NULL,\n\t\t\t  `LastTimeModified` datetime DEFAULT NULL,\n\t\t\t  PRIMARY KEY (`id`)\n\t  \t\t);";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 22  (1.2.4.7)
     if (22 > $db_version) {
         $new_db_version = 22;
         // add column to ebay_profiles table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_profiles`\n\t\t\t        ADD COLUMN `sort_order` int(11) NOT NULL AFTER `type`\n\t\t\t";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 23  (1.2.7.3)
     if (23 > $db_version) {
         $new_db_version = 23;
         // fetch user defined shipping discount profiles - disabled in 2.0.3
         // if ( get_option('wplister_ebay_token') != '' ) {
         // 	$this->initEC();
         // 	$result = $this->EC->loadShippingDiscountProfiles();
         // 	$this->EC->closeEbay();
         // }
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 24  (1.3.0.12)
     if (24 > $db_version) {
         $new_db_version = 24;
         // add column to ebay_profiles table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_auctions`\n\t\t\t        ADD COLUMN `locked` int(11) NOT NULL DEFAULT 0 AFTER `status`\n\t\t\t";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 25  (1.3.0.12)
     if (25 > $db_version) {
         $new_db_version = 25;
         $batch_size = 1000;
         // fetch all imported items
         $sql = "SELECT post_id FROM `{$wpdb->prefix}postmeta` WHERE meta_key = '_ebay_item_source' AND meta_value = 'imported' ";
         $imported_products = $wpdb->get_col($sql);
         echo $wpdb->last_error;
         $total_number_of_products = sizeof($imported_products);
         if ($total_number_of_products > $batch_size) {
             // legacy code removed in 2.0.3
         } else {
             // normal mode - lock all at once
             // lock all imported imported_products
             $where_sql = " 1 = 0 ";
             foreach ($imported_products as $post_id) {
                 $where_sql .= " OR post_id = '{$post_id}' ";
             }
             $sql = "UPDATE `{$wpdb->prefix}ebay_auctions` SET locked = '1' WHERE ( {$where_sql} ) AND status = 'published' ";
             $wpdb->query($sql);
             echo $wpdb->last_error;
             update_option('wplister_db_version', $new_db_version);
             $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
         }
     }
     // upgrade to version 26 (1.3.0.12)
     if (26 > $db_version) {
         $new_db_version = 26;
         // set column type to mediumtext in table: ebay_auctions
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_auctions`\n\t\t\t        CHANGE history history MEDIUMTEXT ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         // set column type to mediumtext in table: ebay_orders
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_orders`\n\t\t\t        CHANGE history history MEDIUMTEXT ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         // set column type to mediumtext in table: ebay_transactions
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_transactions`\n\t\t\t        CHANGE history history MEDIUMTEXT ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 27  (1.3.2.5)
     if (27 > $db_version) {
         $new_db_version = 27;
         // add columns to ebay_categories table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_categories`\n\t\t\t        ADD COLUMN `specifics` text AFTER `cat_name`,\n\t\t\t        ADD COLUMN `conditions` text AFTER `cat_name`\n\t\t\t";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         // add columns to ebay_auctions table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_auctions`\n\t\t\t        ADD COLUMN `parent_id` bigint(20) NOT NULL AFTER `post_id`,\n\t\t\t        ADD COLUMN `variations` text AFTER `details`\n\t\t\t";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 28  (1.3.2.10)
     if (28 > $db_version) {
         $new_db_version = 28;
         // create table: ebay_messages
         $sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ebay_messages` (\n\t\t\t  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t  `message_id` varchar(128) DEFAULT NULL,\n\t\t\t  `received_date` datetime DEFAULT NULL,\n\t\t\t  `subject` varchar(255) DEFAULT NULL,\n\t\t\t  `sender` varchar(255) DEFAULT NULL,\n\t\t\t  `flag_read` varchar(1) DEFAULT NULL,\n\t\t\t  `flag_replied` varchar(1) DEFAULT NULL,\n\t\t\t  `flag_flagged` varchar(1) DEFAULT NULL,\n\t\t\t  `item_title` varchar(255) DEFAULT NULL,\n\t\t\t  `item_id` bigint(255) DEFAULT NULL,\n\t\t\t  `folder_id` bigint(255) DEFAULT NULL,\n\t\t\t  `msg_text` text,\n\t\t\t  `msg_content` text,\n\t\t\t  `details` text,\n\t\t\t  `expiration_date` datetime DEFAULT NULL,\n\t\t\t  `response_url` varchar(255) DEFAULT NULL,\n\t\t\t  `status` varchar(50) DEFAULT NULL,\n\t\t\t  PRIMARY KEY (`id`)\n\t  \t\t);";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 29  (1.3.2.12)
     if (29 > $db_version) {
         $new_db_version = 29;
         // add columns to ebay_auctions table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_auctions`\n\t\t\t        ADD COLUMN `relist_date` datetime DEFAULT NULL AFTER `end_date`\n\t\t\t";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 30  (1.3.4.5)
     if (30 > $db_version) {
         // automatically switch old sites from transaction to order mode
         update_option('wplister_ebay_update_mode', 'order');
         update_option('wplister_db_version', 30);
     }
     // upgrade to version 31  (1.3.5.4)
     if (31 > $db_version) {
         $new_db_version = 31;
         // add indices to ebay_log table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_log` ADD INDEX `timestamp` (`timestamp`) ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_log` ADD INDEX `callname` (`callname`) ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_log` ADD INDEX `success` (`success`) ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 32  (1.3.5.5)
     if (32 > $db_version) {
         $new_db_version = 32;
         // add column to ebay_transactions table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_transactions`\n\t\t\t        ADD COLUMN `order_id` varchar(64) DEFAULT NULL AFTER `transaction_id`\n\t\t\t";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         // add indices to ebay_transactions table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_transactions` ADD INDEX `item_id` (`item_id`) ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_transactions` ADD INDEX `transaction_id` (`transaction_id`) ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_transactions` ADD INDEX `order_id` (`order_id`) ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         // add index to ebay_orders table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_orders` ADD INDEX `order_id` (`order_id`) ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 33  (1.3.5.6)
     if (33 > $db_version) {
         $new_db_version = 33;
         if (WPL_Setup::isV2()) {
             // disable transaction conversion when updating from an ancient version (1.3.5)
             $more_orders_to_process = false;
         } else {
             $more_orders_to_process = isset(WPLE()->pages['tools']) ? WPLE()->pages['tools']->checkTransactions() : false;
         }
         // check if database upgrade is finished yet
         if ($more_orders_to_process) {
             $msg = __('Database upgrade is in progress', 'wplister') . '...';
             if ($msg && !$hide_message) {
                 wple_show_message($msg, 'info');
             }
             return;
         } else {
             update_option('wplister_db_version', $new_db_version);
             $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
         }
     }
     // upgrade to version 34  (1.3.5.7)
     if (34 > $db_version) {
         $new_db_version = 34;
         // fetch exclude shipping locations - disabled in 2.0.3
         // if ( get_option('wplister_ebay_token') != '' ) {
         // 	$this->initEC();
         //	$sm = new EbayShippingModel();
         //	$result = $sm->downloadExcludeShippingLocations( $this->EC->session );
         // 	$this->EC->closeEbay();
         // }
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 35  (1.5.0)
     if (35 > $db_version) {
         $new_db_version = 35;
         // change price column type to DECIMAL(13,2)
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_auctions`\n\t\t\t        CHANGE price price DECIMAL(13,2) ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_orders`\n\t\t\t        CHANGE total total DECIMAL(13,2) ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 36  (1.5.0)
     if (36 > $db_version) {
         $new_db_version = 36;
         // add indices to ebay_auctions table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_auctions` ADD INDEX `ebay_id` (`ebay_id`) ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_auctions` ADD INDEX `status` (`status`) ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_auctions` ADD INDEX `post_id` (`post_id`) ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_auctions` ADD INDEX `profile_id` (`profile_id`) ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_auctions` ADD INDEX `locked` (`locked`) ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_auctions` ADD INDEX `relist_date` (`relist_date`) ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 37  (1.5.2)
     if (37 > $db_version) {
         $new_db_version = 37;
         // create table: ebay_accounts
         $sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ebay_accounts` (\n\t\t\t  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t  `title` varchar(128) NOT NULL,\n\t\t\t  `site_id` int(11) DEFAULT NULL,\n\t\t\t  `site_code` varchar(16) DEFAULT NULL,\n\t\t\t  `sandbox_mode` varchar(16) DEFAULT NULL,\n\t\t\t  `user_name` varchar(32) DEFAULT NULL,\n\t\t\t  `user_details` text NOT NULL,\n\t\t\t  `active` int(11) DEFAULT NULL,\n\t\t\t  `token` text NOT NULL,\n\t\t\t  `valid_until` datetime DEFAULT NULL,\n\t\t\t  `ebay_motors` int(11) DEFAULT NULL,\n\t\t\t  `seller_profiles` int(11) DEFAULT NULL,\n\t\t\t  `shipping_profiles` text NOT NULL,\n\t\t\t  `payment_profiles` text NOT NULL,\n\t\t\t  `return_profiles` text NOT NULL,\n\t\t\t  `categories_map_ebay` text NOT NULL,\n\t\t\t  `categories_map_store` text NOT NULL,\n\t\t\t  `default_ebay_category_id` bigint(20) DEFAULT NULL,\n\t\t\t  `paypal_email` varchar(64) DEFAULT NULL,\n\t\t\t  `sync_orders` int(11) DEFAULT NULL,\n\t\t\t  `sync_products` int(11) DEFAULT NULL,\n\t\t\t  `last_orders_sync` datetime DEFAULT NULL,\n\t\t\t  PRIMARY KEY  (`id`)\n\t\t\t) DEFAULT CHARSET=utf8 ;";
         $wpdb->query($sql);
         // add column to ebay_auctions table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_auctions`\n\t\t\t        ADD COLUMN `site_id` int(11) DEFAULT NULL AFTER `eps`,\n\t\t\t        ADD COLUMN `account_id` int(11) DEFAULT NULL AFTER `eps`\n\t\t\t";
         $wpdb->query($sql);
         // add column to ebay_log table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_log`\n\t\t\t        ADD COLUMN `site_id` int(11) DEFAULT NULL AFTER `user_id`,\n\t\t\t        ADD COLUMN `account_id` int(11) DEFAULT NULL AFTER `user_id`\n\t\t\t";
         $wpdb->query($sql);
         // add column to ebay_messages table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_messages`\n\t\t\t        ADD COLUMN `site_id` int(11) DEFAULT NULL AFTER `status`,\n\t\t\t        ADD COLUMN `account_id` int(11) DEFAULT NULL AFTER `status`\n\t\t\t";
         $wpdb->query($sql);
         // add column to ebay_orders table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_orders`\n\t\t\t        ADD COLUMN `site_id` int(11) DEFAULT NULL AFTER `LastTimeModified`,\n\t\t\t        ADD COLUMN `account_id` int(11) DEFAULT NULL AFTER `LastTimeModified`\n\t\t\t";
         $wpdb->query($sql);
         // add column to ebay_transactions table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_transactions`\n\t\t\t        ADD COLUMN `site_id` int(11) DEFAULT NULL AFTER `LastTimeModified`,\n\t\t\t        ADD COLUMN `account_id` int(11) DEFAULT NULL AFTER `LastTimeModified`\n\t\t\t";
         $wpdb->query($sql);
         // add column to ebay_payment table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_payment`\n\t\t\t        ADD COLUMN `site_id` int(11) DEFAULT NULL AFTER `version`\n\t\t\t";
         $wpdb->query($sql);
         // add column to ebay_shipping table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_shipping`\n\t\t\t        ADD COLUMN `site_id` int(11) DEFAULT NULL AFTER `version`\n\t\t\t";
         $wpdb->query($sql);
         // add column to ebay_profiles table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_profiles`\n\t\t\t        ADD COLUMN `site_id` int(11) DEFAULT NULL AFTER `category_specifics`,\n\t\t\t        ADD COLUMN `account_id` int(11) DEFAULT NULL AFTER `category_specifics`\n\t\t\t";
         $wpdb->query($sql);
         // add column to ebay_store_categories table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_store_categories`\n\t\t\t        ADD COLUMN `site_id` int(11) DEFAULT NULL AFTER `wp_term_id`,\n\t\t\t        ADD COLUMN `account_id` int(11) DEFAULT NULL AFTER `wp_term_id`\n\t\t\t";
         $wpdb->query($sql);
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 38  (1.5.2)
     if (38 > $db_version) {
         $new_db_version = 38;
         $token = get_option('wplister_ebay_token');
         $site_id = get_option('wplister_ebay_site_id');
         $accounts = WPLE_eBayAccount::getAll(true);
         $sites = EbayController::getEbaySites();
         // if there is a token but no accounts in table...
         if ($token && sizeof($accounts) == 0) {
             // migrate current account to new default account
             $default_account = new WPLE_eBayAccount();
             $default_account->title = 'Default';
             $default_account->active = '1';
             $default_account->site_id = $site_id;
             $default_account->site_code = $sites[$site_id];
             $default_account->token = $token;
             $default_account->user_name = get_option('wplister_ebay_token_userid');
             $default_account->sandbox_mode = get_option('wplister_sandbox_enabled');
             $default_account->valid_until = get_option('wplister_ebay_token_expirationtime');
             $default_account->ebay_motors = get_option('wplister_enable_ebay_motors');
             // deprecated
             $default_account->seller_profiles = get_option('wplister_ebay_seller_profiles_enabled') == 'yes' ? 1 : 0;
             $default_account->default_ebay_category_id = get_option('wplister_default_ebay_category_id');
             $default_account->paypal_email = get_option('wplister_paypal_email');
             $default_account->user_details = serialize(maybe_unserialize(get_option('wplister_ebay_user')));
             $default_account->categories_map_ebay = serialize(maybe_unserialize(get_option('wplister_categories_map_ebay')));
             $default_account->categories_map_store = serialize(maybe_unserialize(get_option('wplister_categories_map_store')));
             $default_account->add();
             // echo "<pre>";print_r($default_account);echo"</pre>";#die();
             // apply new account_id all over the site
             $default_account_id = $default_account->id;
             // update ebay_auctions table
             $sql = "UPDATE `{$wpdb->prefix}ebay_auctions` SET\n\t\t\t\t        `site_id`    = '{$site_id}',\n\t\t\t\t        `account_id` = '{$default_account_id}'  ";
             $wpdb->query($sql);
             // update ebay_log table
             $sql = "UPDATE `{$wpdb->prefix}ebay_log` SET\n\t\t\t\t        `site_id`    = '{$site_id}',\n\t\t\t\t        `account_id` = '{$default_account_id}'  ";
             $wpdb->query($sql);
             // update ebay_messages table
             $sql = "UPDATE `{$wpdb->prefix}ebay_messages` SET\n\t\t\t\t        `site_id`    = '{$site_id}',\n\t\t\t\t        `account_id` = '{$default_account_id}'  ";
             $wpdb->query($sql);
             // update ebay_orders table
             $sql = "UPDATE `{$wpdb->prefix}ebay_orders` SET\n\t\t\t\t        `site_id`    = '{$site_id}',\n\t\t\t\t        `account_id` = '{$default_account_id}'  ";
             $wpdb->query($sql);
             // update ebay_transactions table
             $sql = "UPDATE `{$wpdb->prefix}ebay_transactions` SET\n\t\t\t\t        `site_id`    = '{$site_id}',\n\t\t\t\t        `account_id` = '{$default_account_id}'  ";
             $wpdb->query($sql);
             // update ebay_profiles table
             $sql = "UPDATE `{$wpdb->prefix}ebay_profiles` SET\n\t\t\t\t        `site_id`    = '{$site_id}',\n\t\t\t\t        `account_id` = '{$default_account_id}'  ";
             $wpdb->query($sql);
             // update ebay_store_categories table
             $sql = "UPDATE `{$wpdb->prefix}ebay_store_categories` SET\n\t\t\t\t        `site_id`    = '{$site_id}',\n\t\t\t\t        `account_id` = '{$default_account_id}'  ";
             $wpdb->query($sql);
             // update ebay_payment table
             $sql = "UPDATE `{$wpdb->prefix}ebay_payment` SET\n\t\t\t\t        `site_id`    = '{$site_id}'  ";
             $wpdb->query($sql);
             // update ebay_shipping table
             $sql = "UPDATE `{$wpdb->prefix}ebay_shipping` SET\n\t\t\t\t        `site_id`    = '{$site_id}'  ";
             $wpdb->query($sql);
             update_option('wplister_default_account_id', $default_account_id);
             // make sure to reload accounts - which requires db version 38
             update_option('wplister_db_version', $new_db_version);
             WPLE()->loadAccounts();
         }
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 39  (1.6.0.6)
     if (39 > $db_version) {
         $new_db_version = 39;
         // add column to ebay_auctions table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_auctions`\n\t\t\t        ADD COLUMN `last_errors` TEXT AFTER `history`\n\t\t\t";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 40  (1.6.0.7)
     if (40 > $db_version) {
         $new_db_version = 40;
         // add column to ebay_orders table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_orders`\n\t\t\t        ADD COLUMN `currency` varchar(16) AFTER `total`\n\t\t\t";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 41  (1.6.0.10)
     if (41 > $db_version) {
         $new_db_version = 41;
         // create table: ebay_sites
         $sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ebay_sites` (\n\t\t\t  `id` int(11) DEFAULT NULL,\n\t\t\t  `title` varchar(128) NOT NULL,\n\t\t\t  `code` varchar(16) DEFAULT NULL,\n\t\t\t  `url` varchar(64) DEFAULT NULL,\n\t\t\t  `enabled` int(11) DEFAULT NULL,\n\t\t\t  `sort_order` int(11) DEFAULT NULL,\n\t\t\t  `last_refresh` datetime DEFAULT NULL,\n\t\t\t  `categories_map_ebay` text NOT NULL,\n\t\t\t  `DispatchTimeMaxDetails` text NOT NULL,\n\t\t\t  `MinListingStartPrices` text NOT NULL,\n\t\t\t  `ReturnsWithinOptions` text NOT NULL,\n\t\t\t  `CountryDetails` text NOT NULL,\t\t  \n\t\t\t  `ShippingPackageDetails` text NOT NULL,\n\t\t\t  `ShippingCostPaidByOptions` text NOT NULL,\n\t\t\t  `ShippingLocationDetails` text NOT NULL,\n\t\t\t  `ExcludeShippingLocationDetails` text NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`)\n\t\t\t) DEFAULT CHARSET=utf8 ;";
         $wpdb->query($sql);
         // build sites data
         $ebay_sites = EbayController::getEbaySites();
         $sort_order = 1;
         foreach ($ebay_sites as $site_id => $site_title) {
             $data = array('id' => $site_id, 'title' => $site_title, 'url' => EbayController::getDomainnameBySiteId($site_id), 'sort_order' => $sort_order);
             $wpdb->insert($wpdb->prefix . 'ebay_sites', $data);
             $sort_order++;
         }
         // enable site for each account
         foreach (WPLE()->accounts as $account) {
             $wpdb->update($wpdb->prefix . 'ebay_sites', array('enabled' => 1), array('id' => $account->site_id));
         }
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 42  (1.6.0.12 / 2.0.1)
     if (42 > $db_version) {
         $new_db_version = 42;
         // add columns to ebay_accounts table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_accounts`\n\t\t\t        ADD COLUMN `oosc_mode` int(11) AFTER `ebay_motors`,\n\t\t\t        ADD COLUMN `shipping_discount_profiles` text NOT NULL AFTER `return_profiles`\n\t\t\t";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         // refresh accounts
         WPLE()->loadAccounts();
         // if there is a valid default account, copy site specific data from wp_options to wp_ebay_sites
         $accounts = WPLE()->accounts;
         $default_account_id = get_option('wplister_default_account_id');
         $default_account = isset($accounts[$default_account_id]) ? $accounts[$default_account_id] : false;
         if ($default_account) {
             $data = array('categories_map_ebay' => serialize(maybe_unserialize(get_option('wplister_categories_map_ebay'))), 'DispatchTimeMaxDetails' => serialize(maybe_unserialize(get_option('wplister_DispatchTimeMaxDetails'))), 'MinListingStartPrices' => serialize(maybe_unserialize(get_option('wplister_MinListingStartPrices'))), 'ReturnsWithinOptions' => serialize(maybe_unserialize(get_option('wplister_ReturnsWithinOptions'))), 'CountryDetails' => serialize(maybe_unserialize(get_option('wplister_CountryDetails'))), 'ShippingPackageDetails' => serialize(maybe_unserialize(get_option('wplister_ShippingPackageDetails'))), 'ShippingCostPaidByOptions' => serialize(maybe_unserialize(get_option('wplister_ShippingCostPaidByOptions'))), 'ShippingLocationDetails' => serialize(maybe_unserialize(get_option('wplister_ShippingLocationDetails'))), 'ExcludeShippingLocationDetails' => serialize(maybe_unserialize(get_option('wplister_ExcludeShippingLocationDetails'))));
             $wpdb->update($wpdb->prefix . 'ebay_sites', $data, array('id' => $default_account->site_id));
         }
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 43  (2.0.8)
     if (43 > $db_version) {
         $new_db_version = 43;
         // add indices to ebay_auctions table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_auctions` ADD INDEX `parent_id` (`parent_id`) ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_auctions` ADD INDEX `site_id` (`site_id`) ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_auctions` ADD INDEX `account_id` (`account_id`) ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 44 (2.0.8.7)
     if (44 > $db_version) {
         $new_db_version = 44;
         // set column type to mediumtext in table: ebay_accounts
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_accounts`  CHANGE shipping_profiles shipping_profiles MEDIUMTEXT ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_accounts`  CHANGE payment_profiles  payment_profiles  MEDIUMTEXT ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_accounts`  CHANGE return_profiles   return_profiles   MEDIUMTEXT ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_accounts`  CHANGE shipping_discount_profiles shipping_discount_profiles MEDIUMTEXT ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_accounts`  CHANGE categories_map_ebay  categories_map_ebay  MEDIUMTEXT ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_accounts`  CHANGE categories_map_store categories_map_store MEDIUMTEXT ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 45  (2.0.9.5)
     if (45 > $db_version) {
         $new_db_version = 45;
         // add column to ebay_sites table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_sites`\n\t\t\t        ADD COLUMN `DoesNotApplyText` varchar(128) NOT NULL AFTER `ExcludeShippingLocationDetails`\n\t\t\t";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 46 (2.0.9.8.2)
     if (46 > $db_version) {
         $new_db_version = 46;
         // set column type to mediumtext in table: ebay_auctions
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_auctions`\n\t\t\t        CHANGE details details MEDIUMTEXT ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         // set column type to mediumtext in table: ebay_orders
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_orders`\n\t\t\t        CHANGE details details MEDIUMTEXT ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         // set column type to mediumtext in table: ebay_transactions
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_transactions`\n\t\t\t        CHANGE details details MEDIUMTEXT ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 47 (2.0.9.8.2)
     if (47 > $db_version) {
         $new_db_version = 47;
         // restructure categories table
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_categories`\n\t\t\t        CHANGE conditions features MEDIUMTEXT ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_categories`\n\t\t\t        CHANGE specifics specifics MEDIUMTEXT ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         $sql = "ALTER TABLE `{$wpdb->prefix}ebay_categories`\n\t\t\t        CHANGE wp_term_id last_updated datetime ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // upgrade to version 48 (2.0.9.8.2)
     if (48 > $db_version) {
         $new_db_version = 48;
         // remove legacy data
         $sql = "DELETE FROM `{$wpdb->prefix}postmeta` WHERE meta_key    =    '_ebay_category_specifics' ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         $sql = "DELETE FROM `{$wpdb->prefix}options`  WHERE option_name LIKE '_transient_wplister_ebay_item_conditions_%' ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         $sql = "DELETE FROM `{$wpdb->prefix}options`  WHERE option_name LIKE '_transient_timeout_wplister_ebay_item_conditions_%' ";
         $wpdb->query($sql);
         echo $wpdb->last_error;
         update_option('wplister_db_version', $new_db_version);
         $msg = __('Database was upgraded to version', 'wplister') . ' ' . $new_db_version . '.';
     }
     // show update message
     if ($msg && !$hide_message) {
         wple_show_message($msg, 'info');
     }
     #debug: update_option('wplister_db_version', 0);
 }
コード例 #10
0
ファイル: EbayController.php プロジェクト: booklein/wpbookle
 public function updateTransactionsFromEbay($id)
 {
     $sm = new TransactionsModel();
     if (is_array($id)) {
         foreach ($id as $single_id) {
             $sm->updateSingleTransaction($this->session, $single_id);
         }
     } else {
         $sm->updateSingleTransaction($this->session, $id);
     }
 }