PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 1.0.97
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v1.0.97
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 / Modules / CLI / Commands.php

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

56 lines 1.7 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\Modules\CLI;
4
5
6 use FluentCommunity\App\Models\User;
7 use FluentCommunity\Framework\Support\Arr;
8 use FluentCommunityPro\App\Modules\LeaderBoard\Services\LeaderBoardHelper;
9
10 class Commands
11 {
12
13 /*
14 * usage: wp fluent_community sync_x_profile --all --force
15 */
16 public function sync_x_profile($args, $assoc_args = [])
17 {
18 $isForced = Arr::get($assoc_args, 'force', false) == 1;
19
20 $users = User::orderBy('ID', 'ASC')->get();
21
22 foreach ($users as $user) {
23 $result = $user->syncXProfile($isForced);
24
25 \WP_CLI::line('Synced XProfile for UserID: ' . $user->ID . ' - ' . $result->id);
26 }
27
28 \WP_CLI::success('XProfile Synced Successfully');
29
30 }
31
32 public function recalculate_user_points()
33 {
34 if (!defined('FLUENT_COMMUNITY_PRO')) {
35 \WP_CLI::error('This command is only available in Fluent Community Pro');
36 }
37
38 $xProfiles = \FluentCommunity\App\Models\XProfile::all();
39
40 foreach ($xProfiles as $xProfile) {
41 $currentPoint = LeaderBoardHelper::recalculateUserPoints($xProfile->user_id);
42 if ($currentPoint > $xProfile->total_points) {
43 $oldPoints = $xProfile->total_points;
44 $xProfile->total_points = $currentPoint;
45 $xProfile->save();
46
47 do_action('fluent_community/user_points_updated', $xProfile, $oldPoints);
48
49 \WP_CLI::line('Recalculated Points for User: ' . $xProfile->display_name . ' - ' . $oldPoints . ' to ' . $currentPoint);
50 }
51 }
52
53 \WP_CLI::success('Points Recalculated Successfully for ' . count($xProfiles) . ' users');
54 }
55 }
56