-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.php
More file actions
520 lines (477 loc) · 23 KB
/
Copy pathinstall.php
File metadata and controls
520 lines (477 loc) · 23 KB
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
<?php
// obsolete tables
define('EM_OLD_EVENTS_TABLE','dbem_events') ;
define('EM_OLD_RECURRENCE_TABLE','dbem_recurrence'); //TABLE NAME
define('EM_OLD_LOCATIONS_TABLE','dbem_locations'); //TABLE NAME
define('EM_OLD_BOOKINGS_TABLE','dbem_bookings'); //TABLE NAME
define('EM_OLD_PEOPLE_TABLE','dbem_people'); //TABLE NAME
define('EM_OLD_BOOKING_PEOPLE_TABLE','dbem_bookings_people'); //TABLE NAME
define('EM_OLD_CATEGORIES_TABLE', 'dbem_categories'); //TABLE NAME
function em_install() {
$old_version = get_option('dbem_version');
if( EM_VERSION > $old_version || $old_version == '' ){
// Creates the events table if necessary
em_create_events_table();
em_create_locations_table();
em_create_bookings_table();
em_create_people_table();
em_create_categories_table();
em_add_options();
//Migrate?
if( $old_version < 2.3 && $old_version != '' ){
em_migrate_to_new_tables();
em_import_verify();
}
//Upate Version
update_option('dbem_version', EM_VERSION);
// wp-content must be chmodded 777. Maybe just wp-content.
if(!file_exists("../".EM_IMAGE_UPLOAD_DIR))
mkdir("../".EM_IMAGE_UPLOAD_DIR, 0777); //do we need to 777 it? it'll be owner apache anyway, like normal uploads
em_create_events_page();
}
}
function em_create_events_table() {
global $wpdb, $user_level, $user_ID;
get_currentuserinfo();
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
$table_name = $wpdb->prefix.EM_EVENTS_TABLE;
$sql = "CREATE TABLE ".$table_name." (
event_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
event_author bigint(20) unsigned DEFAULT NULL,
event_name tinytext NOT NULL,
event_start_time time NOT NULL,
event_end_time time NOT NULL,
event_start_date date NOT NULL,
event_end_date date NULL,
event_notes text NULL DEFAULT NULL,
event_rsvp bool NOT NULL DEFAULT 1,
event_seats int(5),
event_cost float DEFAULT NULL,
event_rsvp_closing_date int(5) DEFAULT 5,
event_contactperson_id bigint(20) unsigned NULL,
location_id bigint(20) unsigned NOT NULL,
recurrence_id bigint(20) unsigned NULL,
event_category_id bigint(20) unsigned NULL DEFAULT NULL,
event_attributes text NULL,
recurrence bool NOT NULL DEFAULT 0,
recurrence_interval int(4) NULL DEFAULT NULL,
recurrence_freq tinytext NULL DEFAULT NULL,
recurrence_byday tinytext NULL DEFAULT NULL,
recurrence_byweekno int(4) NULL DEFAULT NULL,
UNIQUE KEY (event_id)
) DEFAULT CHARSET=utf8 ;";
$old_table_name = $wpdb->prefix.EM_OLD_EVENTS_TABLE;
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name && $wpdb->get_var("SHOW TABLES LIKE '$old_table_name'") != $old_table_name) {
dbDelta($sql);
//Add default events
$in_one_week = date('Y-m-d', time() + 60*60*24*7);
$in_four_weeks = date('Y-m-d', time() + 60*60*24*7*4);
$in_one_year = date('Y-m-d', time() + 60*60*24*7*365);
$wpdb->query("INSERT INTO ".$table_name." (event_name, event_start_date, event_start_time, event_end_time, location_id) VALUES ('Orality in James Joyce Conference', '$in_one_week', '16:00:00', '18:00:00', 1)");
$wpdb->query("INSERT INTO ".$table_name." (event_name, event_start_date, event_start_time, event_end_time, location_id) VALUES ('Traditional music session', '$in_four_weeks', '20:00:00', '22:00:00', 2)");
$wpdb->query("INSERT INTO ".$table_name." (event_name, event_start_date, event_start_time, event_end_time, location_id) VALUES ('6 Nations, Italy VS Ireland', '$in_one_year','22:00:00', '24:00:00', 3)");
}else{
dbDelta($sql);
}
}
function em_create_locations_table() {
global $wpdb, $user_level;
$table_name = $wpdb->prefix.EM_LOCATIONS_TABLE;
// Creating the events table
$sql = "CREATE TABLE ".$table_name." (
location_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
location_name tinytext NOT NULL,
location_address tinytext NOT NULL,
location_town tinytext NOT NULL,
location_province tinytext,
location_latitude float DEFAULT NULL,
location_longitude float DEFAULT NULL,
location_description text DEFAULT NULL,
UNIQUE KEY (location_id)
) DEFAULT CHARSET=utf8 ;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
$old_table_name = $wpdb->prefix.EM_OLD_LOCATIONS_TABLE;
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name && $wpdb->get_var("SHOW TABLES LIKE '$old_table_name'") != $old_table_name) {
dbDelta($sql);
//Add default values
$wpdb->query("INSERT INTO ".$table_name." (location_name, location_address, location_town, location_latitude, location_longitude) VALUES ('Arts Millenium Building', 'Newcastle Road','Galway', 53.275, -9.06532)");
$wpdb->query("INSERT INTO ".$table_name." (location_name, location_address, location_town, location_latitude, location_longitude) VALUES ('The Crane Bar', '2, Sea Road','Galway', 53.2692, -9.06151)");
$wpdb->query("INSERT INTO ".$table_name." (location_name, location_address, location_town, location_latitude, location_longitude) VALUES ('Taaffes Bar', '19 Shop Street','Galway', 53.2725, -9.05321)");
}else{
dbDelta($sql);
}
}
function em_create_bookings_table() {
global $wpdb, $user_level;
$table_name = $wpdb->prefix.EM_BOOKINGS_TABLE;
$sql = "CREATE TABLE ".$table_name." (
booking_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
event_id bigint(20) unsigned NOT NULL,
person_id bigint(20) unsigned NOT NULL,
booking_seats int(5) NOT NULL DEFAULT 1,
booking_payment_status int(5) NOT NULL DEFAULT 0,
booking_comment text DEFAULT NULL,
booking_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE KEY (booking_id)
) DEFAULT CHARSET=utf8 ;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
}
function em_create_people_table() {
global $wpdb, $user_level;
$table_name = $wpdb->prefix.EM_PEOPLE_TABLE;
$sql = "CREATE TABLE ".$table_name." (
person_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
person_name tinytext NOT NULL,
person_email tinytext NOT NULL,
person_zip tinytext NOT NULL,
person_address text NOT NULL,
person_num tinytext NOT NULL,
person_compl tinytext NOT NULL,
person_district tinytext NOT NULL,
person_city tinytext NOT NULL,
person_uf tinytext NOT NULL,
person_country tinytext NOT NULL,
person_ddd tinytext NOT NULL,
person_phone tinytext NOT NULL,
auth_token text NULL DEFAULT NULL,
UNIQUE KEY (person_id)
) DEFAULT CHARSET=utf8 ;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
}
//Add the categories table
function em_create_categories_table() {
global $wpdb, $user_level;
$table_name = $wpdb->prefix.EM_CATEGORIES_TABLE;
// Creating the events table
$sql = "CREATE TABLE ".$table_name." (
category_id bigint(20) unsigned NOT NULL auto_increment,
category_name tinytext NOT NULL,
PRIMARY KEY (category_id)
) DEFAULT CHARSET=utf8 ;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
$old_table_name = $wpdb->prefix.EM_OLD_CATEGORIES_TABLE;
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name && $wpdb->get_var("SHOW TABLES LIKE '$old_table_name'") != $old_table_name) {
dbDelta($sql);
$wpdb->insert( $table_name, array('category_name'=>__('Uncategorized', 'dbem')), array('%s') );
}else{
dbDelta($sql);
}
}
function em_add_options() {
$contact_person_email_body_localizable = __("#_RESPNAME (#_RESPEMAIL) will attend #_NAME on #m #d, #Y. He wants to reserve #_SPACES spaces.<br/> Now there are #_RESERVEDSPACES spaces reserved, #_AVAILABLESPACES are still available.<br/>Yours faithfully,<br/>Events Manager",'dbem') ;
$respondent_email_body_localizable = __("Dear #_RESPNAME, <br/>you have successfully reserved #_SPACES space/spaces for #_NAME.<br/>Yours faithfully,<br/> #_CONTACTPERSON",'dbem');
$payment_reminder_email_body_localizable = __("Dear #_RESPNAME, <br/> We noticed that you still haven't paid your reservation for the event #_EVENT . <br/> We'd like to remind you that if you do not make this payment until at least 10 days before the event's beggining date, you will not be able to participate. <br/> If you still wish to participate, please make your payment now using the following link: #_BOOKINGPAYMENTLINK .</br> If you no longer wish to participate, please tell us so in by replying to this message. <br/> Thank you, <br/> #_CONTACTPERSON", 'dbem') ;
$dbem_options = array(
'dbem_event_list_item_format' => '<li>#j #M #Y - #H:#i<br/> #_LINKEDNAME<br/>#_TOWN </li>',
'dbem_display_calendar_in_events_page' => 0,
'dbem_single_event_format' => '<h3>#_NAME</h3><p>#j #M #Y - #H:#i</p><p>#_TOWN</p>',
'dbem_event_page_title_format' => '#_NAME',
'dbem_list_events_page' => 1,
'dbem_events_page_title' => __('Events','dbem'),
'dbem_no_events_message' => __('No events','dbem'),
'dbem_location_page_title_format' => '#_NAME',
'dbem_location_baloon_format' => "<strong>#_NAME</strong><br/>#_ADDRESS - #_TOWN<br/><a href='#_LOCATIONPAGEURL'>Details</a>",
'dbem_location_event_list_item_format' => "<li>#_NAME - #j #M #Y - #H:#i</li>",
'dbem_location_list_item_format' => '#_LOCATIONLINK<ul><li>#_ADDRESS</li><li>#_TOWN</li></ul>',
'dbem_location_no_events_message' => __('<li>No events in this location</li>', 'dbem'),
'dbem_single_location_format' => '<p>#_ADDRESS</p><p>#_TOWN</p>',
'dbem_map_text_format' => '<strong>#_LOCATION</strong><p>#_ADDRESS</p><p>#_TOWN</p>',
'dbem_rss_main_title' => get_bloginfo('title')." - ".__('Events'),
'dbem_rss_main_description' => get_bloginfo('description')." - ".__('Events'),
'dbem_rss_description_format' => "#j #M #y - #H:#i <br/>#_LOCATION <br/>#_ADDRESS <br/>#_TOWN",
'dbem_rss_title_format' => "#_NAME",
'dbem_gmap_is_active'=> 1,
'dbem_default_contact_person' => 1,
'dbem_rsvp_mail_notify_is_active' => 1 ,
'dbem_payment_reminder_email_body' => __(str_replace("<br/>", "\n\r", $payment_reminder_email_body_localizable)),
'dbem_contactperson_email_body' => __(str_replace("<br/>", "\n\r", $contact_person_email_body_localizable)),
'dbem_respondent_email_body' => __(str_replace("<br/>", "\n\r", $respondent_email_body_localizable)),
'dbem_rsvp_mail_port' => 465,
'dbem_smtp_host' => 'localhost',
'dbem_mail_sender_name' => get_option('blogname'),
'dbem_mail_sender_address' => get_option('admin_email'),
'dbem_rsvp_mail_send_method' => 'mail',
'dbem_rsvp_mail_SMTPAuth' => 1,
'dbem_image_max_width' => 700,
'dbem_image_max_height' => 700,
'dbem_image_max_size' => 204800,
'dbem_list_date_title' => __('Events', 'dbem').' - #j #M #y',
'dbem_full_calendar_event_format' => '<li>#_LINKEDNAME</li>',
'dbem_small_calendar_event_title_format' => "#_NAME",
'dbem_small_calendar_event_title_separator' => ", ",
'dbem_hello_to_user' => 1,
'dbem_use_select_for_locations' => false,
'dbem_attributes_enabled' => true,
'dbem_recurrence_enabled'=> true,
'dbem_rsvp_enabled'=> true,
'dbem_categories_enabled'=> true,
'dbem_disable_title_rewrites'=> false,
'dbem_title_html' => '<h2>#_PAGETITLE</h2>',
'dbem_events_default_orderby' => 'start_date,start_time,name',
'dbem_events_default_order' => 'ASC',
'dbem_events_default_limit' => 10,
'dbem_payments_token' => "",
'dbem_payments_email' => get_option('admin_email')
);
foreach($dbem_options as $key => $value){
add_option($key, $value);
}
}
function em_create_events_page(){
global $wpdb,$current_user;
if( get_option('dbem_events_page') == '' && get_option('dbem_dismiss_events_page') != 1 && !is_object( get_page( get_option('dbem_events_page') )) ){
$post_data = array(
'post_status' => 'publish',
'post_type' => 'page',
'ping_status' => get_option('default_ping_status'),
'post_content' => 'CONTENTS',
'post_excerpt' => 'CONTENTS',
'post_title' => __('Events','dbem')
);
$post_id = wp_insert_post($post_data, false);
if( $post_id > 0 ){
update_option('dbem_events_page', $post_id);
}
}
}
// migrate old dbem tables to new em ones
function em_migrate_to_new_tables(){
global $wpdb, $current_user;
get_currentuserinfo();
$errors = array();
// migrating events
$events_required = array('event_id', 'event_name','event_start_time','event_end_time','event_start_date','event_rsvp','location_id','recurrence');
$events = $wpdb->get_results('SELECT * FROM '.$wpdb->prefix.EM_OLD_EVENTS_TABLE,ARRAY_A) ;
$event_fields = array('event_id','event_author','event_name','event_start_time','event_end_time','event_start_date','event_end_date','event_notes','event_rsvp','event_seats','event_contactperson_id','location_id','recurrence_id','event_category_id','event_attributes');
if( count($events) > 0 ){
$events_values = array();
foreach($events as $event) {
foreach($event as $key => $value){
if( in_array($key, $event_fields) ){
if($value == '' && !in_array($key,$events_required)){ $event[$key] = 'NULL'; }
elseif ( $value == '-1' && !in_array($key,$events_required) ) { $event[$key] = 'NULL'; }
else { $event[$key] = "'".$wpdb->escape($event[$key])."'"; }
}else{
unset($event[$key]);
}
}
$events_values[] = "\n".'('. implode(', ', $event).')';
}
$events_keys = array_keys($event);
if( count($events_values) > 0 ){
$events_sql = "INSERT INTO " . $wpdb->prefix.EM_EVENTS_TABLE .
"(`" . implode('` ,`', $events_keys) . "`) VALUES".
implode(', ', $events_values);
$wpdb->query($events_sql);
if($wpdb->last_error != ''){
$errors[] = $wpdb->last_error;
}
}
}
// inserting recurrences into events
$table_name = $wpdb->prefix.EM_EVENTS_TABLE;
$results = $wpdb->get_results('SELECT * FROM '.$wpdb->prefix.EM_RECURRENCE_TABLE, ARRAY_A);
if( count($results) > 0 ){
foreach($results as $recurrence_raw){
//Save copy of recurrence_id
$recurrence_id = $recurrence_raw['recurrence_id'];
//First insert the event into events table
$recurrence = array( //Save new array with correct indexes
'event_author' => $current_user->ID,
'event_name' => $recurrence_raw['recurrence_name'],
'event_start_date' => $recurrence_raw['recurrence_start_date'],
'event_end_date' => $recurrence_raw['recurrence_end_date'],
'event_start_time' => $recurrence_raw['recurrence_start_time'],
'event_end_time' => $recurrence_raw['recurrence_end_time'],
'event_notes' => $recurrence_raw['recurrence_notes'],
'location_id' => $recurrence_raw['location_id'],
'recurrence' => 1,
'recurrence_interval' => $recurrence_raw['recurrence_interval'],
'recurrence_freq' => $recurrence_raw['recurrence_freq'],
'recurrence_byday' => $recurrence_raw['recurrence_byday'],
'recurrence_byweekno' => $recurrence_raw['recurrence_byweekno']
);
$result = $wpdb->insert($table_name, $recurrence, array('%d','%s','%s','%s','%s','%s','%s','%d','%d','%d','%d','%d','%d'));
//Then change the id of all the events with recurrence_id
if($result == 1){
$wpdb->query("UPDATE {$table_name} SET recurrence_id='{$wpdb->insert_id}' WHERE recurrence_id='{$recurrence_id}'");
}else{
//FIXME Better fallback in case of bad install
_e('We could not mirgrate old recurrence data over. DONT WORRY! You can just delete the current plugin, and re-install the previous 2.2.2 version and you wont lose any of your data. Either way, please contact the developers to let them know of this bug.', 'dbem');
}
}
}
// migrating locations
$locations_required = array('location_id', 'location_name', 'location_address', 'location_town');
$locations = $wpdb->get_results('SELECT * FROM '.$wpdb->prefix.EM_OLD_LOCATIONS_TABLE,ARRAY_A) ;
$location_fields = array('location_id','location_name','location_address','location_town','location_province','location_latitude','location_longitude','location_description');
if( count($locations) > 0 ){
$locations_values = array();
foreach($locations as $location) {
foreach($location as $key => $value){
if( in_array($key, $location_fields) ){
if($value == '' && !in_array($key, $locations_required)){ $location[$key] = 'NULL'; }
elseif ( $value == '-1' && !in_array($key, $locations_required) ) { $location[$key] = 'NULL'; }
else { $location[$key] = "'".$wpdb->escape($location[$key])."'"; }
}else{
unset($location[$key]);
}
}
$locations_values[] = "\n".'('. implode(', ', $location).')';
}
$locations_keys = array_keys($location);
if( count($locations_values) > 0 ){
$locations_sql = "INSERT INTO " . $wpdb->prefix.EM_LOCATIONS_TABLE .
"(`" . implode('` ,`', $locations_keys) . "`) VALUES".
implode(', ', $locations_values);
$wpdb->query($locations_sql);
}
}
// migrating people
$people = $wpdb->get_results('SELECT * FROM '.$wpdb->prefix.EM_OLD_PEOPLE_TABLE,ARRAY_A) ;
if( count($people) > 0 ){
$people_values = array();
$people_fields = array('person_id', 'person_name', 'person_email', 'person_phone');
foreach($people as $person) {
foreach($person as $key => $value){
if( in_array($key, $people_fields) ){
$person[$key] = "'".$wpdb->escape($person[$key])."'";
}else{
unset($person[$key]);
}
}
$people_values[] = "\n".'('. implode(', ', $person).')';
}
$people_keys = array_keys($person);
if( count($people_values) > 0 ){
$people_sql = "INSERT INTO " . $wpdb->prefix.EM_PEOPLE_TABLE .
"(`" . implode('` ,`', $people_keys) . "`) VALUES".
implode(', ', $people_values);
$wpdb->query($people_sql);
}
}
// migrating bookings
$bookings = $wpdb->get_results('SELECT * FROM '.$wpdb->prefix.EM_OLD_BOOKINGS_TABLE,ARRAY_A) ;
if( count($bookings) > 0 ){
$bookings_values = array();
$booking_fields = array('booking_id', 'event_id', 'person_id', 'booking_seats', 'booking_comment');
foreach($bookings as $booking) {
foreach($booking as $key => $value){
if( in_array($key, $booking_fields) ){
if($value == '' && $key == 'booking_comment'){ $booking[$key] = 'NULL'; }
elseif ( $value == '-1' ) { $booking[$key] = '0'; }
else { $booking[$key] = "'".$wpdb->escape($booking[$key])."'"; }
}else{
unset($booking[$key]);
}
}
$bookings_values[] = "\n".'('. implode(', ', $booking).')';
}
$bookings_keys = array_keys($booking);
if( count($bookings_values) > 0 ){
$bookings_sql = "INSERT INTO " . $wpdb->prefix.EM_BOOKINGS_TABLE .
"(`" . implode('` ,`', $bookings_keys) . "`) VALUES".
implode(', ', $bookings_values);
$wpdb->query($bookings_sql);
}
// migrating categories
$categories = $wpdb->get_results('SELECT * FROM '.$wpdb->prefix.EM_OLD_CATEGORIES_TABLE,ARRAY_A) ;
$categories_fields = array('category_id', 'category_name');
foreach($categories as $category) {
foreach($category as $key => $val){
if( !in_array($key, $categories_fields) ){
unset($category[$key]);
}
}
$wpdb->insert($wpdb->prefix.EM_CATEGORIES_TABLE, $category);
}
}
if( count($errors) > 0 && is_array($errors) ){
$func = create_function('', '?>
<div id="em_page_error" class="error">
<p>SQL Errors:</p>
<ul>
<li>'. implode('</li><li>', $errors) .'</li>
</ul>
</div>
<?php
');
add_action ( 'admin_notices', $func);
}
}
function em_reimport(){
//Check for reimport request
global $wpdb;
if($_GET['em_reimport'] == 1 ){
check_admin_referer( 'em_reimport' );
$p = $wpdb->prefix;
$table_bookings = $p.EM_BOOKINGS_TABLE;
$table_categories = $p.EM_CATEGORIES_TABLE;
$table_events = $p.EM_EVENTS_TABLE;
$table_locations = $p.EM_LOCATIONS_TABLE;
$table_people = $p.EM_PEOPLE_TABLE;
$wpdb->query('DROP TABLE '.$table_bookings.', '.$table_categories.', '.$table_events.', '.$table_locations.', '.$table_people.';');
update_option('dbem_version','2');
em_install();
}
}
add_action('admin_init', 'em_reimport');
/**
* If importing from 2.x to 3.x, this function will be called to verify the import went well.
* @return string|string
*/
function em_import_verify(){
global $wpdb;
$p = $wpdb->prefix;
//Now go through each table and compare row counts, if all match (events is old recurrences + events, then we're fine
$results[] = ( $wpdb->get_var("SELECT COUNT(*) FROM ".$p.EM_BOOKINGS_TABLE.";") == $wpdb->get_var("SELECT COUNT(*) FROM ".$p.EM_OLD_BOOKINGS_TABLE.";") );
$results[] = ( $wpdb->get_var("SELECT COUNT(*) FROM ".$p.EM_CATEGORIES_TABLE.";") ."==". $wpdb->get_var("SELECT COUNT(*) FROM ".$p.EM_OLD_CATEGORIES_TABLE.";") );
$results[] = ( $wpdb->get_var("SELECT COUNT(*) FROM ".$p.EM_EVENTS_TABLE.";") == $wpdb->get_var("SELECT COUNT(*) FROM ".$p.EM_OLD_EVENTS_TABLE.";") + $wpdb->get_var("SELECT COUNT(*) FROM ".$p.EM_OLD_RECURRENCE_TABLE.";") );
$results[] = ( $wpdb->get_var("SELECT COUNT(*) FROM ".$p.EM_LOCATIONS_TABLE.";") == $wpdb->get_var("SELECT COUNT(*) FROM ".$p.EM_OLD_LOCATIONS_TABLE.";") );
$results[] = ( $wpdb->get_var("SELECT COUNT(*) FROM ".$p.EM_PEOPLE_TABLE.";") == $wpdb->get_var("SELECT COUNT(*) FROM ".$p.EM_OLD_PEOPLE_TABLE.";") );
/* Debugging
echo "BOOKINGS : " . $wpdb->get_var("SELECT COUNT(*) FROM ".$p.EM_BOOKINGS_TABLE.";") ."==". $wpdb->get_var("SELECT COUNT(*) FROM ".$p.EM_OLD_BOOKINGS_TABLE);
echo "<br/>CATEGORIES : ". $wpdb->get_var("SELECT COUNT(*) FROM ".$p.EM_CATEGORIES_TABLE.";") == $wpdb->get_var("SELECT COUNT(*) FROM ".$p.EM_OLD_CATEGORIES_TABLE.";");
echo "<br/>EVENTS : ". $wpdb->get_var("SELECT COUNT(*) FROM ".$p.EM_EVENTS_TABLE.";") .'=='. $wpdb->get_var("SELECT COUNT(*) FROM ".$p.EM_OLD_EVENTS_TABLE.";") .'+'. $wpdb->get_var("SELECT COUNT(*) FROM ".$p.EM_OLD_RECURRENCE_TABLE.";");
echo "<br/>LOCATIONS : ". $wpdb->get_var("SELECT COUNT(*) FROM ".$p.EM_LOCATIONS_TABLE.";") .'=='. $wpdb->get_var("SELECT COUNT(*) FROM ".$p.EM_OLD_LOCATIONS_TABLE.";");
echo "<br/>PEOPLE : ". $wpdb->get_var("SELECT COUNT(*) FROM ".$p.EM_PEOPLE_TABLE.";") .'=='. $wpdb->get_var("SELECT COUNT(*) FROM ".$p.EM_OLD_PEOPLE_TABLE.";");
*/
if( in_array(false, $results) ){
update_option( 'dbem_import_fail', 1 );
return false;
}else{
update_option( 'dbem_import_fail', 0 );
add_action ( 'admin_notices', 'em_import_message_success' );
return true;
}
}
/**
* Gets called if re-import was successful.
*/
function em_import_message_success(){
?>
<div id="em_page_error" class="updated">
<p><?php _e('Events Manager successfully imported your events, please check your records to verify.','dbem')?></p>
</div>
<?php
}
/*
* If import failed, a persistant message will show unless ignored.
*/
function em_import_message_fail(){
if( $_GET['em_dismiss_import'] == '1' ){
update_option('dbem_import_fail', 0);
}
if( get_option('dbem_import_fail') == 1 ){
$dismiss_link_joiner = ( count($_GET) > 0 ) ? '&':'?';
?>
<div id="em_page_error" class="error">
<p><?php printf( __('Something has gone wrong when importing your old event. See the <a href="%s">support page</a> for more information. <a href="%s">Dismiss this message</a>','dbem'), get_bloginfo('wpurl').'/wp-admin/admin.php?page=eventuate-support', $_SERVER['REQUEST_URI'].$dismiss_link_joiner.'em_dismiss_import=1'); ?></p>
</div>
<?php
}
}
add_action ( 'admin_notices', 'em_import_message_fail' );
?>