PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.6.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.6.0
2.11.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 All 78 releases
fluent-community / app / Hooks / CLI / Commands.php

Commands.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.6.0, at app/Hooks/CLI/Commands.php

205 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\App\Hooks\CLI;
4
5 use FluentCommunity\App\Models\XProfile;
6 use FluentCommunity\Modules\Migrations\Helpers\BPMigratorHelper;
7 use FluentCommunity\Modules\Migrations\Helpers\PostMigrator;
8 use FluentCommunity\App\Models\User;
9 use FluentCommunity\Framework\Support\Arr;
10
11 class Commands
12 {
13
14 public function migrate_from_bb($args, $assoc_args = [])
15 {
16 $migrator = new BuddyPressMigrator();
17
18 // $migrator->migrateGroups();
19 //
20 // die();
21
22
23 // $migrator->migratePosts();
24 //
25 // die('Yap');
26 //
27 //
28
29 // $postMigrator = new PostMigrator(13461);
30 // $feed = $postMigrator->migrate();
31 // dd($feed);
32
33
34 // \WP_CLI::line('Starting BuddyPress Data Migration...');
35 // BPMigratorHelper::deleteCurrentData();
36 // \WP_CLI::line('Deleted existing Fluent Community data.');
37 // $migrator->migrateGroups();
38 //
39 // die();
40
41 \WP_CLI::line('Starting BuddyPress Data Migration...');
42 BPMigratorHelper::deleteCurrentData();
43 \WP_CLI::line('Deleted existing Fluent Community data.');
44 $migrator->migrateGroups();
45 \WP_CLI::line('Migrated BuddyPress Groups to Fluent Community Spaces.');
46 $migrator->syncGroupMembers();
47 \WP_CLI::line('Synchronized Group Members to Space Members.');
48 $migrator->migratePosts();
49 \WP_CLI::line('Migrated BuddyPress Posts to Fluent Community Feeds.');
50 $migrator->syncUsers();
51 \WP_CLI::line('Synchronized Users.');
52
53 \WP_CLI::line('Calculating User points.');
54 $this->recalculate_user_points();
55
56 \WP_CLI::success('BuddyPress Data Migration Completed Successfully.');
57
58 die();
59
60 //
61 // die();
62
63 // $migrator->migratePosts();
64 // die();
65
66 $postMigrator = new PostMigrator(13052);
67
68 $feed = $postMigrator->migrate();
69
70 dd($feed);
71
72 die();
73
74
75 // $stats = $migrator->getStats();
76 // \WP_CLI::line('BuddyPress Data Stats:');
77 // \WP_CLI\Utils\format_items('table', $stats, ['key', 'count']);
78
79 BPMigratorHelper::deleteCurrentData();
80 $migrator->migratePosts();
81
82 die('OK');
83
84 $migrator->migrateGroups();
85 $migrator->syncGroupMembers();
86 $migrator->migratePosts();
87 $migrator->syncUsers();
88
89 $fluentStats = [
90 [
91 'key' => 'Total Users',
92 'count' => XProfile::count()
93 ],
94 [
95 'key' => 'Total Spaces',
96 'count' => \FluentCommunity\App\Models\Space::count()
97 ],
98 [
99 'key' => 'Total Posts',
100 'count' => \FluentCommunity\App\Models\Feed::count()
101 ],
102 [
103 'key' => 'Total Comments',
104 'count' => \FluentCommunity\App\Models\Comment::count()
105 ],
106 [
107 'key' => 'Total Reactions',
108 'count' => \FluentCommunity\App\Models\Reaction::count()
109 ]
110 ];
111
112 \WP_CLI\Utils\format_items('table', $fluentStats, ['key', 'count']);
113
114 }
115
116 /**
117 * usage: wp fluent_community sync_x_profile --force
118 */
119 public function sync_x_profile($args, $assoc_args = [])
120 {
121 $isForced = Arr::get($assoc_args, 'force', false) == 1;
122
123 $users = User::orderBy('ID', 'ASC')->get();
124
125 foreach ($users as $user) {
126 $result = $user->syncXProfile($isForced);
127 \WP_CLI::line('Synced XProfile for UserID: ' . $user->ID . ' - ' . $result->id);
128 }
129
130 \WP_CLI::success('XProfile Synced Successfully');
131 }
132
133 /**
134 * usage: wp fluent_community recalculate_user_points
135 */
136 public function recalculate_user_points()
137 {
138 $xProfiles = \FluentCommunity\App\Models\XProfile::all();
139
140 $progress = \WP_CLI\Utils\make_progress_bar('Recalculating Points', count($xProfiles));
141
142 foreach ($xProfiles as $xProfile) {
143
144 $progress->tick();
145
146 $currentPoint = BPMigratorHelper::recalculateUserPoints($xProfile->user_id);
147 if ($currentPoint > $xProfile->total_points) {
148 $oldPoints = $xProfile->total_points;
149 $xProfile->total_points = $currentPoint;
150 $xProfile->save();
151 do_action('fluent_community/user_points_updated', $xProfile, $oldPoints);
152 \WP_CLI::line(
153 'Recalculated Points for User: ' . $xProfile->display_name . ' - ' . $oldPoints . ' to ' . $currentPoint
154 );
155 }
156 }
157
158 $progress->finish();
159
160 \WP_CLI::success('Points Recalculated Successfully for ' . count($xProfiles) . ' users');
161 }
162
163
164 public function download()
165 {
166 $baseUrl = 'https://community.buddyboss.com/wp-json/wp/v2/users/?per_page=50&page=';
167
168 $page = 590;
169
170 while (true) {
171 $response = wp_remote_get($baseUrl . $page, [
172 'timeout' => 60,
173 ]);
174
175 if (is_wp_error($response)) {
176 \WP_CLI::error('Error fetching page ' . $page . ': ' . $response->get_error_message());
177 continue;
178 }
179
180 $json = wp_remote_retrieve_body($response);
181 $users = json_decode($json, true);
182 if (empty($users)) {
183 \WP_CLI::line('No more users found on page ' . $page );
184 break; // No more users to fetch, exit the loop
185 }
186
187 // save the json to a file
188 file_put_contents(ABSPATH . '/dump/' . $page . '.json', $json);
189
190 \WP_CLI::line('Downloaded page ' . $page);
191
192
193 $page++;
194 }
195
196 \WP_CLI::success('Download Completed');
197
198
199 }
200
201
202
203
204 }
205