| 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 |
|