-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
eme-install.php
1727 lines (1646 loc) · 81.1 KB
/
eme-install.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
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
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
// we define all db-constants here, this also means the uninstall can include this file and use it
// and doesn't need to include the main file
define( 'EME_DB_VERSION', 401 ); // increase this if the db schema changes or the options change
define( 'EME_EVENTS_TBNAME', 'eme_events' );
define( 'EME_EVENTS_CF_TBNAME', 'eme_events_cf' );
define( 'EME_RECURRENCE_TBNAME', 'eme_recurrence' );
define( 'EME_LOCATIONS_TBNAME', 'eme_locations' );
define( 'EME_LOCATIONS_CF_TBNAME', 'eme_locations_cf' );
define( 'EME_BOOKINGS_TBNAME', 'eme_bookings' );
define( 'EME_PEOPLE_TBNAME', 'eme_people' );
define( 'EME_GROUPS_TBNAME', 'eme_groups' );
define( 'EME_USERGROUPS_TBNAME', 'eme_usergroups' );
define( 'EME_CATEGORIES_TBNAME', 'eme_categories' );
define( 'EME_HOLIDAYS_TBNAME', 'eme_holidays' );
define( 'EME_TEMPLATES_TBNAME', 'eme_templates' );
define( 'EME_FORMFIELDS_TBNAME', 'eme_formfields' );
define( 'EME_FIELDTYPES_TBNAME', 'eme_fieldtypes' );
define( 'EME_ANSWERS_TBNAME', 'eme_answers' );
define( 'EME_PAYMENTS_TBNAME', 'eme_payments' );
define( 'EME_DISCOUNTS_TBNAME', 'eme_discounts' );
define( 'EME_DISCOUNTGROUPS_TBNAME', 'eme_dgroups' );
define( 'EME_MQUEUE_TBNAME', 'eme_mqueue' );
define( 'EME_MAILINGS_TBNAME', 'eme_mailings' );
define( 'EME_MEMBERS_TBNAME', 'eme_members' );
define( 'EME_MEMBERSHIPS_TBNAME', 'eme_memberships' );
define( 'EME_MEMBERSHIPS_CF_TBNAME', 'eme_memberships_cf' );
define( 'EME_COUNTRIES_TBNAME', 'eme_countries' );
define( 'EME_STATES_TBNAME', 'eme_states' );
define( 'EME_ATTENDANCES_TBNAME', 'eme_attendances' );
define( 'EME_TODOS_TBNAME', 'eme_todos' );
define( 'EME_TASKS_TBNAME', 'eme_tasks' );
define( 'EME_TASK_SIGNUPS_TBNAME', 'eme_task_signups' );
function eme_install( $networkwide ) {
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
// check if it is a network activation - if so, run the activation function for each blog id
if ( $networkwide ) {
// Loop through sites.
$blog_ids = get_sites( [ 'fields' => 'ids' ] );
foreach ( $blog_ids as $site_id ) {
switch_to_blog( $site_id );
_eme_install();
restore_current_blog();
}
return;
}
}
// executed if no network activation
_eme_install();
}
// the private function; for activation
function _eme_install() {
eme_add_options();
$db_version = intval( get_option( 'eme_version' ) );
if ( $db_version > EME_DB_VERSION ) {
$db_version = EME_DB_VERSION;
}
if ( $db_version != EME_DB_VERSION ) {
eme_update_options( $db_version );
}
// some folders that need to be created (fsevents is for pdf creation when needed, includes is not for upload either)
eme_mkdir_with_index( EME_UPLOAD_DIR );
$upload_folders = [ 'events', 'locations', 'memberships', 'bookings', 'people', 'members', 'fsevents', 'includes' ];
foreach ($upload_folders as $upload_folder) {
eme_mkdir_with_index( EME_UPLOAD_DIR . '/' . $upload_folder );
}
// let's restrict includes folder even more
if ( is_writable( EME_UPLOAD_DIR . '/includes' ) && ! is_file( EME_UPLOAD_DIR . '/includes/.htaccess' ) ) {
$content = "Deny from all";
file_put_contents(EME_UPLOAD_DIR . '/includes/.htaccess', $content);
}
// Create events page if necessary
$events_page_id = eme_get_events_page_id();
if ( $events_page_id ) {
$events_page = get_page( $events_page_id );
if ( ! $events_page || $events_page->post_status != 'publish' ) {
eme_create_events_page();
}
} else {
eme_create_events_page();
}
// SEO rewrite rules
flush_rewrite_rules();
// create/update the db tables needed
if ( $db_version != EME_DB_VERSION ) {
eme_create_tables( $db_version );
}
// some cron we want
$eme_date_obj = new ExpressiveDate( 'now', EME_TIMEZONE );
// midnight
$timestamp = $eme_date_obj->addOneDay()->setTime( 0, 0, 0 )->getTimestamp();
// to make sure summer/winter starts at the same day, we add one hour (WP "daily" uses 24 hours/day fixed)
$timestamp += 3600;
if ( $db_version < 349 ) {
wp_unschedule_hook( 'eme_cron_member_daily_actions' );
wp_unschedule_hook( 'eme_cron_gdpr_daily_actions' );
wp_unschedule_hook( 'eme_cron_events_daily_actions' );
}
if ( ! wp_next_scheduled( 'eme_cron_member_daily_actions' ) ) {
wp_schedule_event( $timestamp, 'daily', 'eme_cron_member_daily_actions' );
}
if ( ! wp_next_scheduled( 'eme_cron_gdpr_daily_actions' ) ) {
wp_schedule_event( $timestamp + 300, 'daily', 'eme_cron_gdpr_daily_actions' );
}
if ( ! wp_next_scheduled( 'eme_cron_events_daily_actions' ) ) {
wp_schedule_event( $timestamp, 'daily', 'eme_cron_events_daily_actions' );
}
if ( ! wp_next_scheduled( 'eme_cron_daily_actions' ) ) {
$res = wp_schedule_event( $timestamp + 600, 'daily', 'eme_cron_daily_actions' );
}
if ( ! wp_next_scheduled( 'eme_cron_cleanup_actions' ) ) {
$res = wp_schedule_event( time(), 'eme_5min', 'eme_cron_cleanup_actions' );
}
// now cleanup old crons
$crons_to_remove = [ 'eme_cron_cleanup_unpaid', 'eme_cron_cleanup_unconfirmed', 'eme_cron_cleanup_captcha' ];
foreach ( $crons_to_remove as $tmp_cron ) {
if ( wp_next_scheduled( $tmp_cron ) ) {
wp_unschedule_hook( $tmp_cron );
}
}
// we'll restore some planned actions too, if previously deactivated
$cron_actions = [ 'eme_cron_send_new_events', 'eme_cron_send_queued' ];
foreach ( $cron_actions as $cron_action ) {
$schedule = get_option( $cron_action );
// old schedule names are renamed to eme_*
if (preg_match( '/^(1min|5min|15min|30min|4weeks)$/', $schedule, $matches ) ) {
$res = $matches[0];
$schedule = "eme_".$res;
update_option($cron_action, $schedule);
wp_unschedule_hook( $cron_action );
}
// if the action is planned, keep the planning in an option (if we're not clearing all data) and then clear the planning
if ( ! empty( $schedule ) && ! wp_next_scheduled( $cron_action ) ) {
wp_schedule_event( time(), $schedule, $cron_action );
}
}
// make sure queue sending is configured properly
if ( wp_next_scheduled( 'eme_cron_send_queued' ) ) {
$schedule = wp_get_schedule( 'eme_cron_send_queued' );
update_option( 'eme_cron_send_queued', $schedule );
}
eme_plan_queue_mails();
// remove possible translations in WP (but leave frontend submit)
array_map( 'wp_delete_file', preg_grep('/.*frontend.*/', glob( WP_CONTENT_DIR."/languages/plugins/events-made-easy*" ), PREG_GREP_INVERT) );
// now set the version correct
update_option( 'eme_version', EME_DB_VERSION );
}
function eme_uninstall( $networkwide ) {
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
// check if it is a network activation - if so, run the activation function for each blog id
if ( $networkwide ) {
// Get all blog ids
$blog_ids = get_sites( [ 'fields' => 'ids' ] );
foreach ( $blog_ids as $site_id ) {
switch_to_blog( $site_id );
_eme_uninstall();
restore_current_blog();
}
return;
}
}
// executed if no network activation
_eme_uninstall();
}
function _eme_uninstall( $force_drop = 0 ) {
global $wpdb;
$drop_data = get_option( 'eme_uninstall_drop_data' );
$drop_settings = get_option( 'eme_uninstall_drop_settings' );
// these crons get planned with a fixed schedule at activation time, so we don't need to store their planned setting when deactivating
$cron_actions1 = [ 'eme_cron_daily_actions', 'eme_cron_member_daily_actions', 'eme_cron_gdpr_daily_actions', 'eme_cron_events_daily_actions', 'eme_cron_cleanup_actions' ];
foreach ( $cron_actions1 as $cron_action ) {
if ( wp_next_scheduled( $cron_action ) ) {
wp_unschedule_hook( $cron_action );
}
}
$cron_actions2 = [ 'eme_cron_cleanup_unpaid', 'eme_cron_send_new_events', 'eme_cron_send_queued' ];
foreach ( $cron_actions2 as $cron_action ) {
// if the action is planned, keep the planning in an option (if we're not clearing all data) and then clear the planning
if ( wp_next_scheduled( $cron_action ) ) {
if ( ! ( $drop_settings || $force_drop ) ) {
$scheduled = wp_get_schedule( $cron_action );
update_option( $cron_action, $scheduled );
}
wp_unschedule_hook( $cron_action );
}
}
if ( $drop_data || $force_drop ) {
// during uninstall, we only take the prefix per blog (not based on the settings "is_multisite() && get_option( 'eme_multisite_active' )" in the function eme_get_db_prefix)
$db_prefix = $wpdb->prefix;
eme_drop_table( $db_prefix . EME_EVENTS_TBNAME );
eme_drop_table( $db_prefix . EME_RECURRENCE_TBNAME );
eme_drop_table( $db_prefix . EME_LOCATIONS_TBNAME );
eme_drop_table( $db_prefix . EME_BOOKINGS_TBNAME );
eme_drop_table( $db_prefix . EME_PEOPLE_TBNAME );
eme_drop_table( $db_prefix . EME_GROUPS_TBNAME );
eme_drop_table( $db_prefix . EME_USERGROUPS_TBNAME );
eme_drop_table( $db_prefix . EME_CATEGORIES_TBNAME );
eme_drop_table( $db_prefix . EME_HOLIDAYS_TBNAME );
eme_drop_table( $db_prefix . EME_TEMPLATES_TBNAME );
eme_drop_table( $db_prefix . EME_FORMFIELDS_TBNAME );
eme_drop_table( $db_prefix . EME_FIELDTYPES_TBNAME );
eme_drop_table( $db_prefix . EME_ANSWERS_TBNAME );
eme_drop_table( $db_prefix . EME_PAYMENTS_TBNAME );
eme_drop_table( $db_prefix . EME_DISCOUNTS_TBNAME );
eme_drop_table( $db_prefix . EME_DISCOUNTGROUPS_TBNAME );
eme_drop_table( $db_prefix . EME_MQUEUE_TBNAME );
eme_drop_table( $db_prefix . EME_MAILINGS_TBNAME );
eme_drop_table( $db_prefix . EME_MEMBERS_TBNAME );
eme_drop_table( $db_prefix . EME_MEMBERSHIPS_TBNAME );
eme_drop_table( $db_prefix . EME_COUNTRIES_TBNAME );
eme_drop_table( $db_prefix . EME_STATES_TBNAME );
eme_drop_table( $db_prefix . EME_ATTENDANCES_TBNAME );
eme_drop_table( $db_prefix . EME_TODOS_TBNAME );
eme_drop_table( $db_prefix . EME_TASKS_TBNAME );
eme_drop_table( $db_prefix . EME_TASK_SIGNUPS_TBNAME );
}
if ( $drop_settings || $force_drop ) {
eme_delete_events_page();
eme_options_delete();
}
if ( $drop_data && ! $drop_settings ) {
// make sure eme_version is deleted if drop_data is selected
// this is not needed if drop_settings is set, since that already removes all eme related options
delete_option( 'eme_version' );
}
// unschedule the update checker when uninstalling only
if ($force_drop) {
$cron_action = 'puc_cron_check_updates-events-made-easy';
if ( wp_next_scheduled( $cron_action ) ) {
wp_unschedule_hook( $cron_action );
}
}
// SEO rewrite rules
flush_rewrite_rules();
}
function eme_new_blog( WP_Site $new_site, $args ) {
// we don't use $args here
if ( is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) {
switch_to_blog( $new_site->blog_id );
_eme_install();
restore_current_blog();
}
}
function eme_create_tables( $db_version ) {
global $wpdb;
// Creates the events table if necessary
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
// during install, the prefix changes per blog, so get it here
$db_prefix = eme_get_db_prefix();
$charset = '';
$collate = '';
if ( $wpdb->has_cap( 'collation' ) ) {
if ( ! empty( $wpdb->charset ) ) {
$charset = "DEFAULT CHARACTER SET $wpdb->charset";
}
if ( ! empty( $wpdb->collate ) ) {
$collate = "COLLATE $wpdb->collate";
}
}
// db_version returns incorrect info
// $mysql_version = $wpdb->db_version();
//$mysql_version = $wpdb->get_var("SELECT VERSION();");
//$mysql_version = preg_replace( '/[^0-9.].*/', '', $mysql_version);
//$mysql_old = version_compare( $mysql_version, "5.6", '<' );
eme_create_events_table( $charset, $collate, $db_version, $db_prefix );
eme_create_recurrence_table( $charset, $collate, $db_version, $db_prefix );
eme_create_locations_table( $charset, $collate, $db_version, $db_prefix );
eme_create_bookings_table( $charset, $collate, $db_version, $db_prefix );
eme_create_people_table( $charset, $collate, $db_version, $db_prefix );
eme_create_members_table( $charset, $collate, $db_version, $db_prefix );
eme_create_categories_table( $charset, $collate, $db_version, $db_prefix );
eme_create_holidays_table( $charset, $collate, $db_version, $db_prefix );
eme_create_templates_table( $charset, $collate, $db_version, $db_prefix );
eme_create_formfields_table( $charset, $collate, $db_version, $db_prefix );
eme_create_answers_table( $charset, $collate, $db_version, $db_prefix );
eme_create_payments_table( $charset, $collate, $db_version, $db_prefix );
eme_create_discounts_table( $charset, $collate, $db_version, $db_prefix );
eme_create_discountgroups_table( $charset, $collate, $db_version, $db_prefix );
eme_create_mqueue_table( $charset, $collate, $db_version, $db_prefix );
eme_create_countries_table( $charset, $collate, $db_version, $db_prefix );
eme_create_states_table( $charset, $collate, $db_version, $db_prefix );
eme_create_attendances_table( $charset, $collate, $db_version, $db_prefix );
eme_create_task_tables( $charset, $collate, $db_version, $db_prefix );
eme_create_todos_tables( $charset, $collate, $db_version, $db_prefix );
}
function eme_create_events_table( $charset, $collate, $db_version, $db_prefix ) {
global $wpdb;
$table_name = $db_prefix . EME_EVENTS_TBNAME;
if ( ! eme_table_exists( $table_name ) ) {
// Creating the events table
$sql = 'CREATE TABLE ' . $table_name . " (
event_id mediumint(9) NOT NULL AUTO_INCREMENT,
event_status mediumint(9) DEFAULT 1,
event_author mediumint(9) DEFAULT 0,
event_name text NOT NULL,
event_prefix text,
event_slug text,
event_url text,
event_start datetime,
event_end datetime,
creation_date datetime,
modif_date datetime,
event_notes longtext,
event_rsvp bool DEFAULT 0,
event_tasks bool DEFAULT 0,
event_todos bool DEFAULT 0,
price text,
currency text,
event_seats text,
event_contactperson_id mediumint(9) DEFAULT 0,
location_id mediumint(9) DEFAULT 0,
recurrence_id mediumint(9) DEFAULT 0,
event_category_ids text,
event_attributes text,
event_properties text,
event_page_title_format text,
event_single_event_format text,
event_contactperson_email_body text,
event_respondent_email_body text,
event_registration_recorded_ok_html text,
event_registration_pending_email_body text,
event_registration_updated_email_body text,
event_registration_cancelled_email_body text,
event_registration_paid_email_body text,
event_registration_trashed_email_body text,
event_registration_form_format text,
event_cancel_form_format text,
registration_requires_approval bool DEFAULT 0,
registration_wp_users_only bool DEFAULT 0,
event_image_url text,
event_image_id mediumint(9) DEFAULT 0,
event_external_ref text,
UNIQUE KEY (event_id),
KEY (event_start),
KEY (event_end)
) $charset $collate;";
maybe_create_table( $table_name, $sql );
// insert a few events in the new table
// get the current timestamp into an array
$eme_date_obj = new ExpressiveDate( 'now', EME_TIMEZONE );
$eme_date_obj->addDays( 7 );
$in_one_week = $eme_date_obj->getDate();
$eme_date_obj->minusDays( 7 );
$eme_date_obj->addWeeks( 4 );
$in_four_weeks = $eme_date_obj->getDate();
$eme_date_obj->minusWeeks( 4 );
$eme_date_obj->addOneYear();
$in_one_year = $eme_date_obj->getDate();
// some events
$event = eme_new_event();
$event['event_name'] = 'Orality in James Joyce Conference';
$event['event_start'] = "$in_one_week 16:00:00";
$event['event_end'] = "$in_one_week 18:00:00";
$event['location_id'] = 1;
$event = eme_sanitize_event( $event );
// the fourth param is 1 to indicate we're in plugin install mode
// this will cause eme_db_insert_event to check the prefix itself
// since during install plugin globals are not available ...
eme_db_insert_event( $event, 0, 0, 1 );
$event = eme_new_event();
$event['event_name'] = 'Traditional music session';
$event['event_start'] = "$in_four_weeks 20:00:00";
$event['event_end'] = "$in_four_weeks 22:00:00";
$event['location_id'] = 2;
$event = eme_sanitize_event( $event );
// the fourth param is 1 to indicate we're in plugin install mode
// this will cause eme_db_insert_event to check the prefix itself
// since during install plugin globals are not available ...
eme_db_insert_event( $event, 0, 0, 1 );
$event = eme_new_event();
$event['event_name'] = '6 Nations, Italy VS Ireland';
$event['event_start'] = "$in_one_year 22:00:00";
$event['event_end'] = "$in_one_year 23:59:59";
$event['location_id'] = 3;
$event = eme_sanitize_event( $event );
// the fourth param is 1 to indicate we're in plugin install mode
// this will cause eme_db_insert_event to check the prefix itself
// since during install plugin globals are not available ...
eme_db_insert_event( $event, 0, 0, 1 );
} else {
// eventual maybe_add_column() for later versions
maybe_add_column( $table_name, 'event_status', "ALTER TABLE $table_name ADD event_status mediumint(9) DEFAULT 1;" );
maybe_add_column( $table_name, 'event_start', "ALTER TABLE $table_name ADD event_start datetime;" );
maybe_add_column( $table_name, 'event_end', "ALTER TABLE $table_name ADD event_end datetime;" );
maybe_add_column( $table_name, 'event_rsvp', "ALTER TABLE $table_name ADD event_rsvp bool DEFAULT 0;" );
maybe_add_column( $table_name, 'event_tasks', "ALTER TABLE $table_name ADD event_tasks bool DEFAULT 0;" );
maybe_add_column( $table_name, 'event_todos', "ALTER TABLE $table_name ADD event_todos bool DEFAULT 0;" );
maybe_add_column( $table_name, 'price', "ALTER TABLE $table_name ADD price text;" );
maybe_add_column( $table_name, 'currency', "ALTER TABLE $table_name ADD currency text;" );
maybe_add_column( $table_name, 'event_seats', "ALTER TABLE $table_name ADD event_seats text;" );
maybe_add_column( $table_name, 'location_id', "ALTER TABLE $table_name ADD location_id mediumint(9) DEFAULT 0;" );
maybe_add_column( $table_name, 'recurrence_id', "ALTER TABLE $table_name ADD recurrence_id mediumint(9) DEFAULT 0;" );
maybe_add_column( $table_name, 'event_contactperson_id', "ALTER TABLE $table_name ADD event_contactperson_id mediumint(9) DEFAULT 0;" );
maybe_add_column( $table_name, 'event_attributes', "ALTER TABLE $table_name ADD event_attributes text;" );
maybe_add_column( $table_name, 'event_properties', "ALTER TABLE $table_name ADD event_properties text;" );
maybe_add_column( $table_name, 'event_url', "ALTER TABLE $table_name ADD event_url text;" );
maybe_add_column( $table_name, 'event_prefix', "ALTER TABLE $table_name ADD event_prefix text;" );
maybe_add_column( $table_name, 'event_slug', "ALTER TABLE $table_name ADD event_slug text;" );
maybe_add_column( $table_name, 'event_category_ids', "ALTER TABLE $table_name ADD event_category_ids text;" );
maybe_add_column( $table_name, 'event_page_title_format', "ALTER TABLE $table_name ADD event_page_title_format text;" );
maybe_add_column( $table_name, 'event_single_event_format', "ALTER TABLE $table_name ADD event_single_event_format text;" );
maybe_add_column( $table_name, 'event_contactperson_email_body', "ALTER TABLE $table_name ADD event_contactperson_email_body text;" );
maybe_add_column( $table_name, 'event_respondent_email_body', "ALTER TABLE $table_name ADD event_respondent_email_body text;" );
maybe_add_column( $table_name, 'event_registration_pending_email_body', "ALTER TABLE $table_name ADD event_registration_pending_email_body text;" );
maybe_add_column( $table_name, 'event_registration_updated_email_body', "ALTER TABLE $table_name ADD event_registration_updated_email_body text;" );
maybe_add_column( $table_name, 'event_registration_cancelled_email_body', "ALTER TABLE $table_name ADD event_registration_cancelled_email_body text;" );
maybe_add_column( $table_name, 'event_registration_paid_email_body', "ALTER TABLE $table_name ADD event_registration_paid_email_body text;" );
maybe_add_column( $table_name, 'event_registration_recorded_ok_html', "ALTER TABLE $table_name ADD event_registration_recorded_ok_html text;" );
maybe_add_column( $table_name, 'registration_requires_approval', "ALTER TABLE $table_name ADD registration_requires_approval bool DEFAULT 0;" );
$registration_wp_users_only = get_option( 'eme_rsvp_registered_users_only' );
maybe_add_column( $table_name, 'registration_wp_users_only', "ALTER TABLE $table_name ADD registration_wp_users_only bool DEFAULT $registration_wp_users_only;" );
maybe_add_column( $table_name, 'event_author', "ALTER TABLE $table_name ADD event_author mediumint(9) DEFAULT 0;" );
maybe_add_column( $table_name, 'creation_date', "ALTER TABLE $table_name ADD creation_date datetime;" );
maybe_add_column( $table_name, 'modif_date', "ALTER TABLE $table_name ADD modif_date datetime" );
eme_maybe_drop_column( $table_name, 'creation_date_gmt' );
eme_maybe_drop_column( $table_name, 'modif_date_gmt' );
maybe_add_column( $table_name, 'event_registration_form_format', "ALTER TABLE $table_name ADD event_registration_form_format text;" );
maybe_add_column( $table_name, 'event_cancel_form_format', "ALTER TABLE $table_name ADD event_cancel_form_format text;" );
maybe_add_column( $table_name, 'event_image_url', "ALTER TABLE $table_name ADD event_image_url text;" );
maybe_add_column( $table_name, 'event_image_id', "ALTER TABLE $table_name ADD event_image_id mediumint(9) DEFAULT 0;" );
maybe_add_column( $table_name, 'event_external_ref', "ALTER TABLE $table_name ADD event_external_ref text;" );
if ( $db_version < 3 ) {
$wpdb->query( "ALTER TABLE $table_name MODIFY event_name text;" );
$wpdb->query( "ALTER TABLE $table_name MODIFY event_notes longtext;" );
}
if ( $db_version < 4 ) {
$wpdb->query( "ALTER TABLE $table_name CHANGE event_category_id event_category_ids text;" );
$wpdb->query( "ALTER TABLE $table_name MODIFY event_author mediumint(9) DEFAULT 0;" );
$wpdb->query( "ALTER TABLE $table_name MODIFY event_contactperson_id mediumint(9) DEFAULT 0;" );
$wpdb->query( "ALTER TABLE $table_name MODIFY event_seats mediumint(9) DEFAULT 0;" );
$wpdb->query( "ALTER TABLE $table_name MODIFY location_id mediumint(9) DEFAULT 0;" );
$wpdb->query( "ALTER TABLE $table_name MODIFY recurrence_id mediumint(9) DEFAULT 0;" );
$wpdb->query( "ALTER TABLE $table_name MODIFY event_rsvp bool DEFAULT 0;" );
}
if ( $db_version < 5 ) {
$wpdb->query( "ALTER TABLE $table_name MODIFY event_rsvp bool DEFAULT 0;" );
}
if ( $db_version < 11 ) {
if ( eme_column_exists( $table_name, 'event_creator_id' ) ) {
eme_maybe_drop_column( $table_name, 'event_author' );
$wpdb->query( "ALTER TABLE $table_name CHANGE event_creator_id event_author mediumint(9) DEFAULT 0;" );
}
// in case event_creator_id didn't exist ...
maybe_add_column( $table_name, 'event_author', "ALTER TABLE $table_name ADD event_author mediumint(9) DEFAULT 0;" );
}
if ( $db_version < 29 ) {
$wpdb->query( "ALTER TABLE $table_name MODIFY price text;" );
}
if ( $db_version < 33 ) {
$post_table_name = $db_prefix . 'posts';
$wpdb->query( "UPDATE $table_name SET event_image_id = (select ID from $post_table_name where post_type = 'attachment' AND guid = $table_name.event_image_url);" );
}
if ( $db_version < 38 ) {
$wpdb->query( "ALTER TABLE $table_name MODIFY event_seats text;" );
}
if ( $db_version < 70 ) {
eme_maybe_drop_column( $table_name, 'use_google' );
}
if ( $db_version < 247 ) {
if ( eme_column_exists( $table_name, 'event_registration_denied_email_body' ) && ! eme_column_exists( $table_name, 'event_registration_trashed_email_body' ) ) {
$wpdb->query( "ALTER TABLE $table_name CHANGE event_registration_denied_email_body event_registration_trashed_email_body text;" );
}
maybe_add_column( $table_name, 'event_registration_trashed_email_body', "ALTER TABLE $table_name ADD event_registration_trashed_email_body text;" );
}
if ( $db_version < 294 ) {
eme_migrate_event_payment_options();
eme_maybe_drop_column( $table_name, 'use_paypal' );
eme_maybe_drop_column( $table_name, 'use_2co' );
eme_maybe_drop_column( $table_name, 'use_webmoney' );
eme_maybe_drop_column( $table_name, 'use_fdgg' );
eme_maybe_drop_column( $table_name, 'use_mollie' );
eme_maybe_drop_column( $table_name, 'use_sagepay' );
}
if ( $db_version < 296 ) {
$wpdb->query( "ALTER TABLE $table_name MODIFY creation_date datetime ;" );
$wpdb->query( "ALTER TABLE $table_name MODIFY modif_date datetime ;" );
}
if ( $db_version < 302 ) {
$wpdb->query( "UPDATE $table_name SET event_start = CONCAT(event_start_date,' ',event_start_time), event_end = CONCAT(event_end_date,' ',event_end_time) WHERE event_start_date IS NOT NULL and event_start_date <> '0000-00-00';" );
}
if ( $db_version < 303 ) {
$wpdb->query( "ALTER TABLE `$table_name` ADD INDEX ( `event_start` )" );
$wpdb->query( "ALTER TABLE `$table_name` ADD INDEX ( `event_end` )" );
}
if ( $db_version < 311 ) {
eme_maybe_drop_column( $table_name, 'event_start_date' );
eme_maybe_drop_column( $table_name, 'event_end_date' );
eme_maybe_drop_column( $table_name, 'event_start_time' );
eme_maybe_drop_column( $table_name, 'event_end_time' );
}
if ( $db_version < 380 ) {
if ( eme_column_exists( $table_name, 'rsvp_number_hours' ) && eme_column_exists( $table_name, 'rsvp_number_days' ) ) {
eme_migrate_event_rsvpstartend_options();
eme_maybe_drop_column( $table_name, 'rsvp_number_hours' );
eme_maybe_drop_column( $table_name, 'rsvp_number_days' );
}
}
}
}
function eme_create_recurrence_table( $charset, $collate, $db_version, $db_prefix ) {
global $wpdb;
$table_name = $db_prefix . EME_RECURRENCE_TBNAME;
if ( ! eme_table_exists( $table_name ) ) {
$sql = 'CREATE TABLE ' . $table_name . " (
recurrence_id mediumint(9) NOT NULL AUTO_INCREMENT,
recurrence_start_date date NOT NULL,
recurrence_end_date date NOT NULL,
recurrence_interval tinyint NOT NULL,
recurrence_freq tinytext NOT NULL,
recurrence_byday tinytext NOT NULL,
recurrence_byweekno tinyint NOT NULL,
event_duration mediumint(9) DEFAULT 0,
specific_days text,
specific_months varchar(256),
holidays_id mediumint(9) DEFAULT 0,
UNIQUE KEY (recurrence_id)
) $charset $collate;";
maybe_create_table( $table_name, $sql );
} else {
maybe_add_column( $table_name, 'event_duration', "ALTER TABLE $table_name ADD event_duration mediumint(9) DEFAULT 0;" );
eme_maybe_drop_column( $table_name, 'creation_date_gmt' );
eme_maybe_drop_column( $table_name, 'modif_date' );
eme_maybe_drop_column( $table_name, 'creation_date' );
maybe_add_column( $table_name, 'specific_months', "ALTER TABLE $table_name ADD specific_months varchar(256);" );
maybe_add_column( $table_name, 'holidays_id', "ALTER TABLE $table_name ADD holidays_id mediumint(9) DEFAULT 0;" );
if ( $db_version < 3 ) {
$wpdb->query( "ALTER TABLE $table_name MODIFY recurrence_byday tinytext NOT NULL ;" );
}
if ( $db_version < 4 ) {
eme_maybe_drop_column( $table_name, 'recurrence_name' );
eme_maybe_drop_column( $table_name, 'recurrence_start_time' );
eme_maybe_drop_column( $table_name, 'recurrence_end_time' );
eme_maybe_drop_column( $table_name, 'recurrence_notes' );
eme_maybe_drop_column( $table_name, 'location_id' );
eme_maybe_drop_column( $table_name, 'event_contactperson_id' );
eme_maybe_drop_column( $table_name, 'event_category_id' );
eme_maybe_drop_column( $table_name, 'event_page_title_format' );
eme_maybe_drop_column( $table_name, 'event_single_event_format' );
eme_maybe_drop_column( $table_name, 'event_contactperson_email_body' );
eme_maybe_drop_column( $table_name, 'event_respondent_email_body' );
eme_maybe_drop_column( $table_name, 'registration_requires_approval' );
}
if ( $db_version < 376 ) {
if ( eme_column_exists( $table_name, 'recurrence_specific_days' ) ) {
$wpdb->query( "ALTER TABLE $table_name CHANGE recurrence_specific_days specific_days text;" );
} else {
maybe_add_column( $table_name, 'specific_days', "ALTER TABLE $table_name ADD specific_days text;" );
}
}
}
}
function eme_create_locations_table( $charset, $collate, $db_version, $db_prefix ) {
global $wpdb;
$table_name = $db_prefix . EME_LOCATIONS_TBNAME;
if ( ! eme_table_exists( $table_name ) ) {
$sql = 'CREATE TABLE ' . $table_name . " (
location_id mediumint(9) NOT NULL AUTO_INCREMENT,
location_name text NOT NULL,
location_prefix text,
location_slug text,
location_url text,
location_address1 tinytext,
location_address2 tinytext,
location_city tinytext,
location_state tinytext,
location_zip tinytext,
location_country tinytext,
location_latitude tinytext,
location_longitude tinytext,
location_description text,
location_author mediumint(9) DEFAULT 0,
location_category_ids text,
location_image_url text,
location_image_id mediumint(9) DEFAULT 0,
location_attributes text,
location_properties text,
location_external_ref text,
UNIQUE KEY (location_id)
) $charset $collate;";
maybe_create_table( $table_name, $sql );
$wpdb->query(
'INSERT INTO ' . $table_name . " (location_name, location_address1, location_city, location_latitude, location_longitude)
VALUES ('Arts Millenium Building', 'Newcastle Road','Galway', '53.275', '-9.06532')"
);
$wpdb->query(
'INSERT INTO ' . $table_name . " (location_name, location_address1, location_city, location_latitude, location_longitude)
VALUES ('The Crane Bar', '2, Sea Road','Galway', '53.2683224', '-9.0626223')"
);
$wpdb->query(
'INSERT INTO ' . $table_name . " (location_name, location_address1, location_city, location_latitude, location_longitude)
VALUES ('Taaffes Bar', '19 Shop Street','Galway', '53.2725', '-9.05321')"
);
} else {
maybe_add_column( $table_name, 'location_author', "ALTER TABLE $table_name ADD location_author mediumint(9) DEFAULT 0;" );
maybe_add_column( $table_name, 'location_category_ids', "ALTER TABLE $table_name ADD location_category_ids text;" );
eme_maybe_drop_column( $table_name, 'location_creation_date_gmt' );
eme_maybe_drop_column( $table_name, 'location_creation_date' );
eme_maybe_drop_column( $table_name, 'location_modif_date' );
maybe_add_column( $table_name, 'location_url', "ALTER TABLE $table_name ADD location_url text;" );
maybe_add_column( $table_name, 'location_prefix', "ALTER TABLE $table_name ADD location_prefix text;" );
maybe_add_column( $table_name, 'location_slug', "ALTER TABLE $table_name ADD location_slug text;" );
maybe_add_column( $table_name, 'location_image_url', "ALTER TABLE $table_name ADD location_image_url text;" );
maybe_add_column( $table_name, 'location_image_id', "ALTER TABLE $table_name ADD location_image_id mediumint(9) DEFAULT 0;" );
maybe_add_column( $table_name, 'location_attributes', "ALTER TABLE $table_name ADD location_attributes text;" );
maybe_add_column( $table_name, 'location_properties', "ALTER TABLE $table_name ADD location_properties text;" );
maybe_add_column( $table_name, 'location_external_ref', "ALTER TABLE $table_name ADD location_external_ref text;" );
if ( $db_version < 3 ) {
$wpdb->query( "ALTER TABLE $table_name MODIFY location_name text NOT NULL ;" );
}
if ( $db_version < 33 ) {
$post_table_name = $db_prefix . 'posts';
$wpdb->query( "UPDATE $table_name SET location_image_id = (select ID from $post_table_name where post_type = 'attachment' AND guid = $table_name.location_image_url);" );
}
if ( $db_version < 110 ) {
$wpdb->query( "ALTER TABLE $table_name CHANGE location_address location_address1 tinytext;" );
$wpdb->query( "ALTER TABLE $table_name CHANGE location_town location_city tinytext;" );
maybe_add_column( $table_name, 'location_address2', "ALTER TABLE $table_name ADD location_address2 tinytext;" );
maybe_add_column( $table_name, 'location_state', "ALTER TABLE $table_name ADD location_state tinytext;" );
maybe_add_column( $table_name, 'location_zip', "ALTER TABLE $table_name ADD location_zip tinytext;" );
maybe_add_column( $table_name, 'location_country', "ALTER TABLE $table_name ADD location_country tinytext;" );
}
if ( $db_version < 183 ) {
$wpdb->query( "ALTER TABLE $table_name CHANGE location_latitude location_latitude tinytext;" );
$wpdb->query( "ALTER TABLE $table_name CHANGE location_longitude location_longitude tinytext;" );
}
}
}
function eme_create_bookings_table( $charset, $collate, $db_version, $db_prefix ) {
global $wpdb;
$table_name = $db_prefix . EME_BOOKINGS_TBNAME;
// column discount: effective calculated discount value
// columns discountid , dgroupid: pointer to discount/discout group applied
if ( ! eme_table_exists( $table_name ) ) {
$sql = 'CREATE TABLE ' . $table_name . " (
booking_id mediumint(9) NOT NULL AUTO_INCREMENT,
event_id mediumint(9) NOT NULL,
person_id mediumint(9) NOT NULL,
payment_id mediumint(9) DEFAULT NULL,
status tinyint DEFAULT 1,
booking_seats mediumint(9) NOT NULL,
booking_seats_mp varchar(250),
waitinglist bool DEFAULT 0,
booking_comment text,
event_price text,
extra_charge tinytext,
creation_date datetime,
modif_date datetime,
payment_date datetime DEFAULT '0000-00-00 00:00:00',
booking_paid bool DEFAULT 0,
received tinytext,
remaining tinytext,
pg tinytext,
pg_pid tinytext,
reminder INT(11) DEFAULT 0,
unique_nbr varchar(20),
discount tinytext,
discountids tinytext,
dcodes_entered tinytext,
dcodes_used tinytext,
dgroupid INT(11) DEFAULT 0,
attend_count INT(11) DEFAULT 0,
UNIQUE KEY (booking_id),
KEY (status)
) $charset $collate;";
maybe_create_table( $table_name, $sql );
} else {
maybe_add_column( $table_name, 'attend_count', "ALTER TABLE $table_name ADD attend_count INT(11) DEFAULT 0;" );
maybe_add_column( $table_name, 'status', "ALTER TABLE $table_name ADD status tinyint DEFAULT 1;" );
maybe_add_column( $table_name, 'booking_comment', "ALTER TABLE $table_name ADD booking_comment text;" );
maybe_add_column( $table_name, 'waitinglist', "ALTER TABLE $table_name ADD waitinglist bool DEFAULT 0;" );
maybe_add_column( $table_name, 'payment_date', "ALTER TABLE $table_name ADD payment_date datetime DEFAULT '0000-00-00 00:00:00';" );
maybe_add_column( $table_name, 'creation_date', "ALTER TABLE $table_name ADD creation_date datetime;" );
maybe_add_column( $table_name, 'modif_date', "ALTER TABLE $table_name ADD modif_date datetime;" );
eme_maybe_drop_column( $table_name, 'creation_date_gmt' );
eme_maybe_drop_column( $table_name, 'modif_date_gmt' );
maybe_add_column( $table_name, 'booking_seats_mp', "ALTER TABLE $table_name ADD booking_seats_mp varchar(250);" );
eme_maybe_drop_column( $table_name, 'ip' );
eme_maybe_drop_column( $table_name, 'wp_id' );
eme_maybe_drop_column( $table_name, 'lang' );
maybe_add_column( $table_name, 'extra_charge', "ALTER TABLE $table_name ADD extra_charge tinytext;" );
maybe_add_column( $table_name, 'discount', "ALTER TABLE $table_name ADD discount tinytext;" );
maybe_add_column( $table_name, 'dcodes_entered', "ALTER TABLE $table_name ADD dcodes_entered tinytext ;" );
maybe_add_column( $table_name, 'dcodes_used', "ALTER TABLE $table_name ADD dcodes_used tinytext ;" );
maybe_add_column( $table_name, 'dgroupid', "ALTER TABLE $table_name ADD dgroupid INT(11) DEFAULT 0;" );
maybe_add_column( $table_name, 'reminder', "ALTER TABLE $table_name ADD reminder INT(11) DEFAULT 0;" );
maybe_add_column( $table_name, 'received', "ALTER TABLE $table_name ADD received tinytext;" );
maybe_add_column( $table_name, 'remaining', "ALTER TABLE $table_name ADD remaining tinytext;" );
if ( eme_column_exists( $table_name, 'discountid' ) ) {
$wpdb->query( "ALTER TABLE $table_name CHANGE discountid discountids tinytext;" );
} else {
maybe_add_column( $table_name, 'discountids', "ALTER TABLE $table_name ADD discountids tinytext;" );
}
if ( eme_column_exists( $table_name, 'transfer_nbr_be97' ) ) {
$wpdb->query( "ALTER TABLE $table_name CHANGE transfer_nbr_be97 unique_nbr varchar(20);" );
} else {
maybe_add_column( $table_name, 'unique_nbr', "ALTER TABLE $table_name ADD unique_nbr varchar(20);" );
}
maybe_add_column( $table_name, 'pg', "ALTER TABLE $table_name ADD pg tinytext;" );
maybe_add_column( $table_name, 'pg_pid', "ALTER TABLE $table_name ADD pg_pid tinytext;" );
if ( $db_version < 3 ) {
$wpdb->query( "ALTER TABLE $table_name MODIFY event_id mediumint(9) NOT NULL;" );
$wpdb->query( "ALTER TABLE $table_name MODIFY person_id mediumint(9) NOT NULL;" );
$wpdb->query( "ALTER TABLE $table_name MODIFY booking_seats mediumint(9) NOT NULL;" );
}
if ( $db_version < 47 ) {
$people_table_name = $db_prefix . EME_PEOPLE_TBNAME;
$wpdb->query( "update $table_name a JOIN $people_table_name b on (a.person_id = b.person_id) set a.wp_id=b.wp_id;" );
}
if ( $db_version < 92 ) {
maybe_add_column( $table_name, 'payment_id', "ALTER TABLE $table_name ADD payment_id mediumint(9) DEFAULT NULL;" );
$payment_table_name = $db_prefix . EME_PAYMENTS_TBNAME;
$sql = "SELECT id,booking_ids from $payment_table_name";
$rows = $wpdb->get_results( $sql, ARRAY_A );
if ( $rows !== false && ! empty( $rows ) ) {
foreach ( $rows as $row ) {
$booking_ids = explode( ',', $row['booking_ids'] );
if ( is_array( $booking_ids ) && count( $booking_ids ) > 0 ) {
foreach ( $booking_ids as $booking_id ) {
$sql = $wpdb->prepare( "UPDATE $table_name SET payment_id=%d WHERE booking_id=%d", $row['id'], $booking_id );
$wpdb->query( $sql );
}
}
}
eme_maybe_drop_column( $payment_table_name, 'booking_ids' );
}
}
if ( $db_version < 107 ) {
$wpdb->query( "ALTER TABLE $table_name CHANGE booking_payed booking_paid bool DEFAULT 0;" );
}
if ( $db_version < 208 ) {
if ( eme_column_exists( $table_name, 'booking_price' ) ) {
$wpdb->query( "ALTER TABLE $table_name CHANGE booking_price event_price text;" );
} else {
maybe_add_column( $table_name, 'event_price', "ALTER TABLE $table_name ADD event_price text;" );
}
}
if ( $db_version < 296 ) {
$wpdb->query( "ALTER TABLE $table_name MODIFY creation_date datetime;" );
$wpdb->query( "ALTER TABLE $table_name MODIFY modif_date datetime;" );
}
if ( $db_version < 302 ) {
// we forgot to add the index in the past when adding the table, so: drop the index and set it again
$wpdb->query( "ALTER TABLE `$table_name` ADD INDEX ( `status` )" );
}
if ( $db_version < 345 ) {
// old records that were marked as active and not approved, now get PENDING as status
$sql = $wpdb->prepare( "UPDATE $table_name SET status=%d WHERE booking_approved=0 AND status=1", EME_RSVP_STATUS_PENDING );
$wpdb->query( $sql );
eme_maybe_drop_column( $table_name, 'booking_approved' );
}
}
}
function eme_create_people_table( $charset, $collate, $db_version, $db_prefix ) {
global $wpdb;
$table_name = $db_prefix . EME_PEOPLE_TBNAME;
$grouptable_name = $db_prefix . EME_GROUPS_TBNAME;
$usergrouptable_name = $db_prefix . EME_USERGROUPS_TBNAME;
if ( ! eme_table_exists( $table_name ) ) {
$sql = 'CREATE TABLE ' . $table_name . " (
person_id mediumint(9) NOT NULL AUTO_INCREMENT,
related_person_id mediumint(9) DEFAULT 0,
lastname tinytext,
firstname tinytext,
email tinytext NOT NULL,
status tinyint DEFAULT 1,
phone tinytext,
wp_id bigint(20) unsigned DEFAULT NULL,
address1 tinytext,
address2 tinytext,
city tinytext,
zip tinytext,
state tinytext,
country tinytext,
state_code tinytext,
country_code tinytext,
birthdate date,
bd_email bool DEFAULT 0,
birthplace varchar(50) DEFAULT '',
lang varchar(10) DEFAULT '',
massmail bool DEFAULT 0,
newsletter bool DEFAULT 0,
gdpr bool DEFAULT 0,
properties text,
creation_date datetime,
modif_date datetime,
gdpr_date date,
random_id varchar(50),
UNIQUE KEY (person_id),
KEY (status)
) $charset $collate;";
maybe_create_table( $table_name, $sql );
} else {
maybe_add_column( $table_name, 'random_id', "ALTER TABLE $table_name ADD random_id varchar(50);" );
maybe_add_column( $table_name, 'gdpr', "ALTER TABLE $table_name ADD gdpr bool DEFAULT 0;" );
maybe_add_column( $table_name, 'gdpr_date', "ALTER TABLE $table_name ADD gdpr_date date;" );
maybe_add_column( $table_name, 'birthdate', "ALTER TABLE $table_name ADD birthdate date;" );
maybe_add_column( $table_name, 'birthplace', "ALTER TABLE $table_name ADD birthplace varchar(50) DEFAULT '';" );
maybe_add_column( $table_name, 'status', "ALTER TABLE $table_name ADD status tinyint DEFAULT 1;" );
maybe_add_column( $table_name, 'state_code', "ALTER TABLE $table_name ADD state_code tinytext;" );
maybe_add_column( $table_name, 'country_code', "ALTER TABLE $table_name ADD country_code tinytext;" );
maybe_add_column( $table_name, 'wp_id', "ALTER TABLE $table_name ADD wp_id bigint(20) unsigned DEFAULT NULL;" );
maybe_add_column( $table_name, 'firstname', "ALTER TABLE $table_name ADD firstname tinytext;" );
maybe_add_column( $table_name, 'address1', "ALTER TABLE $table_name ADD address1 tinytext;" );
maybe_add_column( $table_name, 'address2', "ALTER TABLE $table_name ADD address2 tinytext;" );
maybe_add_column( $table_name, 'city', "ALTER TABLE $table_name ADD city tinytext;" );
maybe_add_column( $table_name, 'state', "ALTER TABLE $table_name ADD state tinytext;" );
maybe_add_column( $table_name, 'zip', "ALTER TABLE $table_name ADD zip tinytext;" );
maybe_add_column( $table_name, 'country', "ALTER TABLE $table_name ADD country tinytext;" );
maybe_add_column( $table_name, 'lang', "ALTER TABLE $table_name ADD lang varchar(10) DEFAULT '';" );
// for existing installations, we set massmail and newsletter=1 if the col was missing, to reflect old behaviour
maybe_add_column( $table_name, 'massmail', "ALTER TABLE $table_name ADD massmail bool DEFAULT 1;" );
maybe_add_column( $table_name, 'newsletter', "ALTER TABLE $table_name ADD newsletter bool DEFAULT 1;" );
maybe_add_column( $table_name, 'properties', "ALTER TABLE $table_name ADD properties text;" );
maybe_add_column( $table_name, 'creation_date', "ALTER TABLE $table_name ADD creation_date datetime;" );
maybe_add_column( $table_name, 'modif_date', "ALTER TABLE $table_name ADD modif_date datetime;" );
maybe_add_column( $table_name, 'related_person_id', "ALTER TABLE $table_name ADD related_person_id mediumint(9) DEFAULT 0;" );
maybe_add_column( $table_name, 'bd_email', "ALTER TABLE $table_name ADD bd_email bool DEFAULT 0;" );
if ( $db_version < 10 ) {
$wpdb->query( "ALTER TABLE $table_name MODIFY person_phone tinytext;" );
}
if ( $db_version < 78 ) {
$wpdb->query( "ALTER TABLE $table_name CHANGE person_phone phone tinytext;" );
$wpdb->query( "ALTER TABLE $table_name CHANGE person_name lastname tinytext NOT NULL;" );
$wpdb->query( "ALTER TABLE $table_name CHANGE person_email email tinytext NOT NULL;" );
}
if ( $db_version < 163 ) {
eme_maybe_drop_column( $table_name, 'image_id' );
}
if ( $db_version < 204 ) {
add_clean_index( $table_name, 'status' );
}
if ( $db_version < 296 ) {
$wpdb->query( "ALTER TABLE $table_name MODIFY creation_date datetime ;" );
$wpdb->query( "ALTER TABLE $table_name MODIFY modif_date datetime ;" );
}
if ( $db_version < 306 ) {
$wpdb->query( "ALTER TABLE `$table_name` ADD INDEX ( `related_person_id` )" );
}
}
// now the groups table
if ( ! eme_table_exists( $grouptable_name ) ) {
$sql = 'CREATE TABLE ' . $grouptable_name . " (
group_id int(11) NOT NULL auto_increment,
name varchar(50) DEFAULT NULL,
email tinytext,
description tinytext,
type tinytext,
public bool DEFAULT 0,
stored_sql text,
search_terms text,
UNIQUE KEY (group_id)
) $charset $collate;";
maybe_create_table( $grouptable_name, $sql );
} else {
maybe_add_column( $grouptable_name, 'type', "ALTER TABLE $grouptable_name ADD type tinytext;" );
maybe_add_column( $grouptable_name, 'email', "ALTER TABLE $grouptable_name ADD email tinytext;" );
maybe_add_column( $grouptable_name, 'stored_sql', "ALTER TABLE $grouptable_name ADD stored_sql text;" );
maybe_add_column( $grouptable_name, 'search_terms', "ALTER TABLE $grouptable_name ADD search_terms text;" );
if ( $db_version < 175 ) {
$wpdb->query( "UPDATE $grouptable_name SET type = 'static';" );
}
if ( $db_version < 344 ) {
$wpdb->query( "ALTER TABLE $grouptable_name CHANGE mail_only public bool DEFAULT 0;" );
} else {
maybe_add_column( $grouptable_name, 'public', "ALTER TABLE $grouptable_name ADD public bool DEFAULT 0;" );
}
}
// now the table defining group members
if ( ! eme_table_exists( $usergrouptable_name ) ) {
$sql = 'CREATE TABLE ' . $usergrouptable_name . " (
person_id int(11),
group_id int(11)
) $charset $collate;";
maybe_create_table( $usergrouptable_name, $sql );
}
}
function eme_create_categories_table( $charset, $collate, $db_version, $db_prefix ) {
global $wpdb;
$table_name = $db_prefix . EME_CATEGORIES_TBNAME;
if ( ! eme_table_exists( $table_name ) ) {
$sql = 'CREATE TABLE ' . $table_name . " (
category_id int(11) NOT NULL auto_increment,
category_name tinytext NOT NULL,
description text,
category_prefix text,
category_slug text,
UNIQUE KEY (category_id)
) $charset $collate;";
maybe_create_table( $table_name, $sql );
} else {
maybe_add_column( $table_name, 'category_prefix', "ALTER TABLE $table_name ADD category_prefix text;" );
maybe_add_column( $table_name, 'category_slug', "ALTER TABLE $table_name ADD category_slug text;" );
maybe_add_column( $table_name, 'description', "ALTER TABLE $table_name ADD description text;" );
eme_maybe_drop_column( $table_name, 'creation_date' );
eme_maybe_drop_column( $table_name, 'modif_date' );
if ( $db_version < 66 ) {
$categories = $wpdb->get_results( "SELECT * FROM $table_name", ARRAY_A );
foreach ( $categories as $this_category ) {
$where = [];
$fields = [];
$where['category_id'] = $this_category['category_id'];
$fields['category_slug'] = eme_permalink_convert_noslash( $this_category['category_name'] );
$wpdb->update( $table_name, $fields, $where );
}
}
}
}
function eme_create_holidays_table( $charset, $collate, $db_version, $db_prefix ) {
$table_name = $db_prefix . EME_HOLIDAYS_TBNAME;
if ( ! eme_table_exists( $table_name ) ) {
$sql = 'CREATE TABLE ' . $table_name . " (
id int(11) NOT NULL auto_increment,
name tinytext NOT NULL,
list text NOT NULL,
UNIQUE KEY (id)
) $charset $collate;";
maybe_create_table( $table_name, $sql );
} else {
eme_maybe_drop_column( $table_name, 'creation_date' );
eme_maybe_drop_column( $table_name, 'modif_date' );
}
}
function eme_create_templates_table( $charset, $collate, $db_version, $db_prefix ) {
global $wpdb;
$table_name = $db_prefix . EME_TEMPLATES_TBNAME;
if ( ! eme_table_exists( $table_name ) ) {
$sql = 'CREATE TABLE ' . $table_name . " (
id int(11) NOT NULL auto_increment,
name tinytext,
description tinytext,
format text NOT NULL,
type tinytext,
properties text,
modif_date datetime,
UNIQUE KEY (id)
) $charset $collate;";
maybe_create_table( $table_name, $sql );
} else {
maybe_add_column( $table_name, 'type', "ALTER TABLE $table_name ADD type tinytext;" );
maybe_add_column( $table_name, 'properties', "ALTER TABLE $table_name ADD properties text;" );
maybe_add_column( $table_name, 'modif_date', "ALTER TABLE $table_name ADD modif_date datetime;" );
eme_maybe_drop_column( $table_name, 'creation_date' );
if ( $db_version < 41 ) {
$wpdb->query( "ALTER TABLE $table_name MODIFY format text NOT NULL;" );
}
if ( $db_version < 144 ) {