Implement academy analytics, billing, and web stories updates
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\AcademyContentMetricDaily;
|
||||
use App\Services\Academy\AcademyPopularityService;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
final class AcademyAnalyticsRecalculatePopularityCommand extends Command
|
||||
{
|
||||
protected $signature = 'academy:analytics-recalculate-popularity {--days=30}';
|
||||
|
||||
protected $description = 'Recalculate Academy daily popularity and conversion scores';
|
||||
|
||||
public function __construct(private readonly AcademyPopularityService $popularity)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$days = max(1, (int) $this->option('days'));
|
||||
|
||||
AcademyContentMetricDaily::query()
|
||||
->where('date', '>=', now()->subDays($days - 1)->toDateString())
|
||||
->chunkById(500, function ($rows): void {
|
||||
foreach ($rows as $row) {
|
||||
$row->forceFill([
|
||||
'popularity_score' => $this->popularity->calculatePopularityScore($row->toArray()),
|
||||
'conversion_score' => $this->popularity->calculateConversionScore($row->toArray()),
|
||||
])->save();
|
||||
}
|
||||
});
|
||||
|
||||
$this->info(sprintf('Recalculated Academy popularity for the last %d day(s).', $days));
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user