PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 1.0.94
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v1.0.94
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 1.0.94, at database/Migrations/FeedSpaceUserMigrator.php

62 lines 2.2 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 `role` (`role`)
31 ) $charsetCollate;";
32 dbDelta($sql);
33 } else {
34 // check we have column notification_level
35 // if yes then drop it
36 $column_names = $wpdb->get_col("DESC " . $table, 0);
37 if (in_array('notification_level', $column_names)) {
38 $wpdb->query("ALTER TABLE $table DROP INDEX notification_level");
39 $wpdb->query("ALTER TABLE $table DROP COLUMN notification_level");
40 }
41
42 // check if we have meta column
43 // if not then add it
44 if (!in_array('meta', $column_names)) {
45 $wpdb->query("ALTER TABLE $table ADD COLUMN `meta` TEXT NULL AFTER `role`");
46 }
47
48 // now check index for space_id_user_id
49 $index_names = $wpdb->get_col("SHOW INDEX FROM $table", 2);
50 if (!in_array('space_id_user_id', $index_names)) {
51 $wpdb->query("ALTER TABLE $table ADD INDEX `space_id_user_id` (`space_id`, `user_id`)");
52 }
53
54 // now check index for role
55 if (!in_array('role', $index_names)) {
56 $wpdb->query("ALTER TABLE $table ADD INDEX `role` (`role`)");
57 }
58
59 }
60 }
61 }
62