PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.8.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.8.0
2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 1.1.0 All 77 releases
fluent-community / database / Migrations / FeedSpaceUserMigrator.php

FeedSpaceUserMigrator.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.8.0, at database/Migrations/FeedSpaceUserMigrator.php

77 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // phpcs:disable
3 namespace FluentCommunity\Database\Migrations;
4
5 class FeedSpaceUserMigrator
6 {
7 /**
8 * @param bool $isForced
9 * @return void
10 */
11 public static function migrate($isForced = false)
12 {
13 global $wpdb;
14
15 $charsetCollate = $wpdb->get_charset_collate();
16 $table = $wpdb->prefix . 'fcom_space_user';
17
18 if ($wpdb->get_var("SHOW TABLES LIKE '$table'") != $table || $isForced) {
19 $sql = "CREATE TABLE $table (
20 `id` BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
21 `space_id` BIGINT UNSIGNED NULL,
22 `user_id` VARCHAR(194) NOT NULL,
23 `status` VARCHAR(100) NULL DEFAULT 'active',
24 `role` VARCHAR(100) NULL DEFAULT 'member',
25 `meta` TEXT NULL,
26 `created_at` TIMESTAMP NULL,
27 `updated_at` TIMESTAMP NULL,
28 INDEX `status` (`status`),
29 INDEX `space_id_user_id` (`space_id`, `user_id`),
30 INDEX `user_id_status` (`user_id`, `status`),
31 INDEX `space_status_created` (`space_id`, `status`, `created_at`),
32 INDEX `space_role_created` (`space_id`, `role`, `created_at`),
33 INDEX `role` (`role`)
34 ) $charsetCollate;";
35 dbDelta($sql);
36 } else {
37 // check we have column notification_level
38 // if yes then drop it
39 $column_names = $wpdb->get_col("DESC " . $table, 0);
40 if (in_array('notification_level', $column_names)) {
41 $wpdb->query("ALTER TABLE $table DROP INDEX notification_level");
42 $wpdb->query("ALTER TABLE $table DROP COLUMN notification_level");
43 }
44
45 // check if we have meta column
46 // if not then add it
47 if (!in_array('meta', $column_names)) {
48 $wpdb->query("ALTER TABLE $table ADD COLUMN `meta` TEXT NULL AFTER `role`");
49 }
50
51 // now check index for space_id_user_id
52 $index_names = $wpdb->get_col("SHOW INDEX FROM $table", 2);
53 if (!in_array('space_id_user_id', $index_names)) {
54 $wpdb->query("ALTER TABLE $table ADD INDEX `space_id_user_id` (`space_id`, `user_id`)");
55 }
56
57 // now check index for role
58 if (!in_array('role', $index_names)) {
59 $wpdb->query("ALTER TABLE $table ADD INDEX `role` (`role`)");
60 }
61
62 if (!in_array('user_id_status', $index_names)) {
63 $wpdb->query("ALTER TABLE $table ADD INDEX `user_id_status` (`user_id`, `status`)");
64 }
65
66 if (!in_array('space_status_created', $index_names)) {
67 $wpdb->query("ALTER TABLE $table ADD INDEX `space_status_created` (`space_id`, `status`, `created_at`)");
68 }
69
70 if (!in_array('space_role_created', $index_names)) {
71 $wpdb->query("ALTER TABLE $table ADD INDEX `space_role_created` (`space_id`, `role`, `created_at`)");
72 }
73
74 }
75 }
76 }
77