PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.8.1
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.8.1
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 / app / Hooks / CLI / Commands.php

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

212 lines 5.9 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::whereIn('object_type', ['feed', 'comment'])
109 ->where('type', 'like')
110 ->count()
111 ]
112 ];
113
114 \WP_CLI\Utils\format_items('table', $fluentStats, ['key', 'count']);
115
116 }
117
118 /**
119 * usage: wp fluent_community sync_x_profile --force
120 */
121 public function sync_x_profile($args, $assoc_args = [])
122 {
123 $isForced = Arr::get($assoc_args, 'force', false) == 1;
124
125 $users = User::orderBy('ID', 'ASC')->get();
126
127 foreach ($users as $user) {
128 $result = $user->syncXProfile($isForced);
129 \WP_CLI::line('Synced XProfile for UserID: ' . $user->ID . ' - ' . $result->id);
130 }
131
132 \WP_CLI::success('XProfile Synced Successfully');
133 }
134
135 /**
136 * usage: wp fluent_community recalculate_user_points
137 */
138 public function recalculate_user_points()
139 {
140 $xProfiles = \FluentCommunity\App\Models\XProfile::all();
141
142 $progress = \WP_CLI\Utils\make_progress_bar('Recalculating Points', count($xProfiles));
143
144 foreach ($xProfiles as $xProfile) {
145
146 $progress->tick();
147
148 $currentPoint = BPMigratorHelper::recalculateUserPoints($xProfile->user_id);
149 if ($currentPoint > $xProfile->total_points) {
150 $oldPoints = $xProfile->total_points;
151 $xProfile->total_points = $currentPoint;
152 $xProfile->save();
153 do_action('fluent_community/user_points_updated', $xProfile, $oldPoints);
154 \WP_CLI::line(
155 'Recalculated Points for User: ' . $xProfile->display_name . ' - ' . $oldPoints . ' to ' . $currentPoint
156 );
157 }
158 }
159
160 $progress->finish();
161
162 \WP_CLI::success('Points Recalculated Successfully for ' . count($xProfiles) . ' users');
163 }
164
165
166 public function download()
167 {
168 $baseUrl = 'https://community.buddyboss.com/wp-json/wp/v2/users/?per_page=50&page=';
169
170 $page = 590;
171
172 $dumpDir = wp_upload_dir()['basedir'] . '/fcom-dump';
173 if (!is_dir($dumpDir)) {
174 wp_mkdir_p($dumpDir);
175 }
176
177 while (true) {
178 $response = wp_remote_get($baseUrl . $page, [
179 'timeout' => 60,
180 ]);
181
182 if (is_wp_error($response)) {
183 \WP_CLI::error('Error fetching page ' . $page . ': ' . $response->get_error_message());
184 continue;
185 }
186
187 $json = wp_remote_retrieve_body($response);
188 $users = json_decode($json, true);
189 if (empty($users)) {
190 \WP_CLI::line('No more users found on page ' . $page );
191 break; // No more users to fetch, exit the loop
192 }
193
194 // save the json to a file
195 file_put_contents($dumpDir . '/' . $page . '.json', $json);
196
197 \WP_CLI::line('Downloaded page ' . $page);
198
199
200 $page++;
201 }
202
203 \WP_CLI::success('Download Completed');
204
205
206 }
207
208
209
210
211 }
212