<?php

/******************************************************************************************
 * Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
 * Unauthorized copying of this file, via any medium is strictly prohibited
 * Proprietary and confidential
 * You can contact Smackcoders at email address info@smackcoders.com.
 *******************************************************************************************/
namespace Smackcoders\WCSV;

if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly

/**
 * Class SmackUCIUnInstall
 * @package Smackcoders\WCSV
 */

class SmackUCIUnInstall {
	/**
	 * UnInstall UCI Pro.
	 */
	protected static $instance = null;
	public $plugin;	
	public function __construct() {
		$this->plugin = Plugin::getInstance();
	}

	public static function getInstance() {
		if ( null == self::$instance ) {
			self::$instance = new self;
		}
		return self::$instance;
	}

	/**
	 * unInstall
	 *
	 * @return void
	 */
	public static function unInstall() {
		global $wpdb;
		$wpdb->hide_errors();
		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
		$ucisettings = get_option('sm_uci_pro_settings');		
		$prefix = $wpdb->prefix;
		$droptable = isset($ucisettings['drop_table']) ? $ucisettings['drop_table'] : '';		
		if(!empty($droptable) && $droptable == 'true'){
			$tables[] = "drop table {$prefix}ultimate_csv_importer_external_file_schedules";
			$tables[] = "drop table {$prefix}ultimate_csv_importer_ftp_schedules";
			$tables[] = "drop table {$prefix}ultimate_csv_importer_mappingtemplate";
			$tables[] = "drop table {$prefix}ultimate_csv_importer_scheduled_import";
			$tables[] = "drop table {$prefix}ultimate_csv_importer_scheduled_export";
			$tables[] = "drop table {$prefix}ultimate_csv_importer_export_template";
			$tables[] = "drop table {$prefix}import_detail_log";
			$tables[] = "drop table {$prefix}smackcsv_file_events";
			$tables[] = "drop table {$prefix}ultimate_csv_importer_media_report";
			$tables[] = "drop table {$prefix}ultimate_csv_importer_shortcode_manager";	
			$tables[] = "drop table {$prefix}smackuci_events";
			$tables[] = "drop table {$prefix}smack_field_types";
			$tables[] = "drop table {$prefix}ultimate_csv_importer_acf_fields";
			$tables[] = "drop table {$prefix}post_entries_table";
			$tables[] = "drop table {$prefix}clitemplate";
			
			foreach($tables as $table) {
				$wpdb->query($table, array());
			}
		}
	}
}
