| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Hooks\CLI; |
| 4 |
|
| 5 |
use FluentCart\App\Services\Report\RetentionSnapshotService; |
| 6 |
|
| 7 |
class RetentionSnapshotCommand |
| 8 |
{ |
| 9 |
/** |
| 10 |
* Generate retention snapshots |
| 11 |
*/ |
| 12 |
public function generate($args, $assoc_args) |
| 13 |
{ |
| 14 |
$productIdFilter = isset($assoc_args['product_id']) ? (int) $assoc_args['product_id'] : null; |
| 15 |
|
| 16 |
\WP_CLI::line(''); |
| 17 |
\WP_CLI::line('==========================================='); |
| 18 |
\WP_CLI::line(' Retention Snapshot Generator'); |
| 19 |
\WP_CLI::line('==========================================='); |
| 20 |
\WP_CLI::line(''); |
| 21 |
|
| 22 |
// Progress callback for CLI output |
| 23 |
$progressCallback = function (string $message, string $level = 'info') { |
| 24 |
if ($level === 'success') { |
| 25 |
\WP_CLI::success($message); |
| 26 |
} elseif ($level === 'error') { |
| 27 |
\WP_CLI::error($message); |
| 28 |
} elseif ($level === 'warning') { |
| 29 |
\WP_CLI::warning($message); |
| 30 |
} else { |
| 31 |
\WP_CLI::line($message); |
| 32 |
} |
| 33 |
}; |
| 34 |
|
| 35 |
// Run the service |
| 36 |
$service = new RetentionSnapshotService(); |
| 37 |
$result = $service->generate($productIdFilter, $progressCallback); |
| 38 |
|
| 39 |
// Summary |
| 40 |
\WP_CLI::line(''); |
| 41 |
\WP_CLI::line('==========================================='); |
| 42 |
|
| 43 |
if ($result['success']) { |
| 44 |
\WP_CLI::success('Retention snapshot generation complete!'); |
| 45 |
} else { |
| 46 |
\WP_CLI::error($result['message']); |
| 47 |
} |
| 48 |
|
| 49 |
\WP_CLI::line('==========================================='); |
| 50 |
\WP_CLI::line(''); |
| 51 |
|
| 52 |
// Show summary stats |
| 53 |
if (!empty($result['stats'])) { |
| 54 |
$stats = $result['stats']; |
| 55 |
\WP_CLI::line('Summary:'); |
| 56 |
\WP_CLI::line(" Total Records: {$stats['total_records']}"); |
| 57 |
\WP_CLI::line(" Unique Cohorts: {$stats['unique_cohorts']}"); |
| 58 |
\WP_CLI::line(" Unique Periods: {$stats['unique_periods']}"); |
| 59 |
\WP_CLI::line(" Unique Products: {$stats['unique_products']}"); |
| 60 |
\WP_CLI::line(''); |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
|