-
Notifications
You must be signed in to change notification settings - Fork 3
/
uninstall.php
124 lines (96 loc) · 4.62 KB
/
uninstall.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* Uninstall helper.
*
* @package megaventory
* @since 1.0.0
*
* Author URI: https://github.com/Megaventory/WooCommerce
* Developer URI: https://megaventory.com/
* Developer e-mail: [email protected]
* Copyright: © 2009-2019 WooCommerce.
* License: GNU General Public License v3.0
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
*/
/**
* Imports.
*/
if ( ! defined( 'MEGAVENTORY__PLUGIN_DIR' ) ) {
define( 'MEGAVENTORY__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
require_once MEGAVENTORY__PLUGIN_DIR . 'classes/class-product.php';
require_once MEGAVENTORY__PLUGIN_DIR . 'classes/class-client.php';
require_once MEGAVENTORY__PLUGIN_DIR . 'classes/class-mv-constants.php';
require_once MEGAVENTORY__PLUGIN_DIR . 'classes/class-order.php';
\Megaventory\Models\Product::wc_delete_mv_data();
\Megaventory\Models\Client::delete_default_client();
\Megaventory\Models\Client::wc_reset_mv_data();
\Megaventory\Models\Order::delete_mv_data_from_orders();
delete_option( 'correct_currency' );
delete_option( 'correct_connection' );
delete_option( 'correct_megaventory_apikey' );
delete_option( 'do_megaventory_requests' );
delete_option( 'mv_account_expired' );
delete_option( 'mv_account_admin' );
delete_option( 'mv_woo_integration_enabled' );
delete_option( 'new_mv_api_key' );
delete_option( 'last_valid_api_key' );
delete_option( 'mv_session_messages' );
delete_option( \Megaventory\Models\MV_Constants::MV_LOCATION_ID_TO_ABBREVIATION );
delete_option( 'megaventory_api_key' );
delete_option( 'megaventory_api_host' );
delete_option( 'woocommerce_guest' );
delete_option( 'default-megaventory-inventory-location' );
delete_option( 'is_megaventory_initialized' );
delete_option( 'are_megaventory_products_synchronized' );
delete_option( 'are_megaventory_clients_synchronized' );
delete_option( 'are_megaventory_coupons_synchronized' );
delete_option( 'is_megaventory_stock_adjusted' );
delete_option( 'megaventory_alternate_wp_cron' );
delete_option( 'megaventory_initialized_time' );
delete_option( 'megaventory_products_synchronized_time' );
delete_option( 'megaventory_clients_synchronized_time' );
delete_option( 'megaventory_coupons_synchronized_time' );
delete_option( 'megaventory_stock_synchronized_time' );
delete_option( 'megaventory_adjustment_document_status_option' );
delete_option( \Megaventory\Models\MV_Constants::SHIPPING_ZONES_ENABLE_OPT );
delete_option( \Megaventory\Models\MV_Constants::SHIPPING_ZONES_PRIORITY_OPT );
delete_option( \Megaventory\Models\MV_Constants::MV_ORDERS_TO_SYNC_OPT );
delete_option( \Megaventory\Models\MV_Constants::MV_ORDER_DELAY_CHOICE_OPT );
delete_option( \Megaventory\Models\MV_Constants::MV_ORDER_DELAY_SECONDS_CHOICE_OPT );
delete_option( \Megaventory\Models\MV_Constants::MV_EXCLUDED_LOCATION_IDS_OPT );
delete_option( \Megaventory\Models\MV_Constants::MV_AUTO_ASSIGN_BATCH_NUMBERS_OPT );
global $wpdb;
$tax_rates_table = "{$wpdb->prefix}woocommerce_tax_rates";
$tax_rates_mv_column = 'mv_id';
$existing_columns = $wpdb->get_col( 'DESC ' . $wpdb->prefix . 'woocommerce_tax_rates', 0 ); // phpcs:ignore
$column_found = false;
foreach ( $existing_columns as $column_name ) {
if ( 'mv_id' === $column_name ) {
$column_found = true;
break;
}
}
if ( $column_found ) {
$return = $wpdb->query( $wpdb->prepare( 'ALTER TABLE %1s DROP COLUMN %1s;', array( $tax_rates_table, $tax_rates_mv_column ) ) ); // phpcs:ignore
}
$error_table_name = "{$wpdb->prefix}megaventory_errors_log";
$success_table_name = "{$wpdb->prefix}megaventory_success_log";
$apikeys_table_name = "{$wpdb->prefix}megaventory_api_keys";
$notices_table_name = "{$wpdb->prefix}megaventory_notices_log";
$existing_table = $wpdb->get_results( $wpdb->prepare( 'show tables like %s', $error_table_name ), ARRAY_A ); // phpcs:ignore
if ( 0 !== count( $existing_table ) ) {
$wpdb->query( $wpdb->prepare( 'DROP TABLE %1s', $error_table_name ) ); // phpcs:ignore
}
$existing_table = $wpdb->get_results( $wpdb->prepare( 'show tables like %s', $success_table_name ), ARRAY_A ); // phpcs:ignore
if ( 0 !== count( $existing_table ) ) {
$wpdb->query( $wpdb->prepare( 'DROP TABLE %1s', $success_table_name ) ); // phpcs:ignore
}
$existing_table = $wpdb->get_results( $wpdb->prepare( 'show tables like %s', $apikeys_table_name ), ARRAY_A ); // phpcs:ignore
if ( 0 !== count( $existing_table ) ) {
$wpdb->query( $wpdb->prepare( 'DROP TABLE %1s', $apikeys_table_name ) ); // phpcs:ignore
}
$existing_table = $wpdb->get_results( $wpdb->prepare( 'show tables like %s', $notices_table_name ), ARRAY_A ); // phpcs:ignore
if ( 0 !== count( $existing_table ) ) {
$wpdb->query( $wpdb->prepare( 'DROP TABLE %1s', $notices_table_name ) ); // phpcs:ignore
}