-
Notifications
You must be signed in to change notification settings - Fork 2
/
dokan-wcv-migrator.php
257 lines (225 loc) · 8.92 KB
/
dokan-wcv-migrator.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<?php
/**
Plugin Name: Dokan WC Vendors Migrator
Plugin URI: http://wedevs.com/
Description: Migrate WC Vendors Data to Dokan
Version: 1.0.0
Author: weDevs
Author URI: http://wedevs.com/
License: GPL2
*/
/**
* Copyright (c) 2016 weDevs (email: [email protected]). All rights reserved.
*
* Released under the GPL license
* http://www.opensource.org/licenses/gpl-license.php
*
* This is an add-on for WordPress
* http://wordpress.org/
*
* **********************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* **********************************************************************
*/
// don't call the file directly
if ( ! defined( 'ABSPATH' ) ) exit;
/**
* Dokan_WC_Vendors_Migrator class
*/
class Dokan_WCV_Migrator {
/**
* Class constructor.
*/
public function __construct() {
// load the addon
add_action( 'dokan_loaded', array( $this, 'plugin_init' ) );
}
/**
* Initialize the class.
*/
public static function init() {
static $instance = false;
if ( ! $instance ) {
$instance = new self();
}
return $instance;
}
/**
* Init the plugin.
*
* @return void
*/
public function plugin_init() {
include dirname( __FILE__ ) . '/includes/class-wcv-migrator-kit.php';
include dirname( __FILE__ ) . '/includes/class-ajax.php';
// Instantiate classes
$this->init_classes();
// Initialize the action hooks
$this->init_actions();
}
/**
* Init the plugin classes.
*
* @return void
*/
private function init_classes() {
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
new Dokan_WCV_Ajax_Handler();
}
}
/**
* Init the plugin actions.
*
* @return void
*/
private function init_actions() {
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
}
/**
* Register the admin menu.
*
* @return void
*/
public function admin_menu() {
add_submenu_page( 'tools.php', __( 'WC Vendors 2 Dokan Migrator', 'dokan-wcv' ), __( 'WC Vendors 2 Dokan Migrator', 'dokan-wcv' ), 'manage_options', 'dokan-wcv-migrator', array( $this, 'plugin_page' ) );
}
/**
* Display the plugin page.
*
* @return void
*/
public function plugin_page() {
?>
<style type="text/css">
.wcv-migrator-response span {
color: #8a6d3b;
background-color: #fcf8e3;
border-color: #faebcc;
padding: 15px;
margin: 10px 0;
border: 1px solid transparent;
border-radius: 4px;
display: block;
}
.wcv-migrator-loader {
background: url('<?php echo admin_url('images/spinner-2x.gif') ?>') no-repeat;
width: 20px;
height: 20px;
display: inline-block;
background-size: cover;
}
#progressbar {
background-color: #EEE;
border-radius: 13px;
padding: 3px;
margin-bottom : 20px;
}
#wcv-migrator-progress {
background-color: #00A0D2;
width: 0%;
height: 20px;
border-radius: 10px;
text-align: center;
color:#FFF;
}
</style>
<script type="text/javascript">
jQuery( function ($) {
var total_items = 0;
$('form#dokan-wcv-migrator-form').on('submit', function(e) {
e.preventDefault();
var form = $(this),
submit = form.find('input[type=submit]'),
loader = form.find('.wcv-migrator-loader');
responseDiv = $('.wcv-migrator-response');
submit.attr('disabled', 'disabled');
loader.show();
var data = {
'action': 'dokan_wcv_migrate',
'type': form.find( "select[name=type]" ).val(),
'limit': form.find( "input[name=limit]" ).val(),
'total_items': form.find( "input[name=total_items]" ).val(),
'done': form.find( "input[name=done]" ).val(),
'_wpnonce': '<?php echo wp_create_nonce( "dokan-wcv-migrator" ); ?>'
};
$.post( ajaxurl, data, function( resp ) {
if ( resp.success ) {
total_items = resp.data.total_items;
completed = (resp.data.done*100) / total_items;
completed = Math.round(completed);
if (!$.isNumeric(completed)) {
$('#wcv-migrator-progress').width('100%');
$('#wcv-migrator-progress').html('Finished');
} else {
$('#wcv-migrator-progress').width(completed+'%');
$('#wcv-migrator-progress').html(completed+'%');
}
$('#progressbar').show();
responseDiv.html( '<span>' + resp.data.message + '</span>' );
if ( resp.data.done != 'All' ) {
form.find('input[name="total_items"]').val( resp.data.total_items );
form.find('input[name="done"]').val( resp.data.done );
form.submit();
return;
} else {
form.find('input[name="total_items"]').val( 0 );
form.find('input[name="done"]').val( 0 );
submit.removeAttr('disabled');
loader.hide();
}
}
});
});
});
</script>
<div class="wrap">
<h2><?php _e( "WC Vendors 2 Dokan Data Migrator", "dokan-wcv" ); ?></h2>
<p><?php _e( "This tool will migrate your <strong>WC Vendors</strong> data to <strong>Dokan</strong>.", "dokan-wcv" ); ?></p>
<form action="" method="post" id="dokan-wcv-migrator-form">
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row"><?php _e( "Type", "dokan-wcv" ); ?></th>
<td>
<select name="type">
<option value="vendor"><?php _e( "Vendor", "dokan-wcv" ); ?></option>
<option value="order"><?php _e( "Order", "dokan-wcv" ); ?></option>
</select>
<p class="description"><?php _e( "Select a specific type to migrate.", "dokan-wcv" ); ?></p>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e( "Limit", "dokan-wcv" ); ?></th>
<td>
<input type="number" name="limit" value="50">
<p class="description"><?php _e( "Amount of items to migrate per request.", "dokan-wcv" ); ?></p>
</td>
</tr>
</tbody>
</table>
<div class="wcv-migrator-response"></div>
<div id="progressbar" style="display: none;">
<div id="wcv-migrator-progress">0</div>
</div>
<input type="hidden" name="total_items" value="0">
<input type="hidden" name="done" value="0">
<input type="submit" class="button button-primary" value="<?php esc_attr_e( 'Migrate', 'dokan-wcv' ); ?>" >
<span class="wcv-migrator-loader" style="display:none"></span>
</form>
</div>
<?php
}
}
Dokan_WCV_Migrator::init();