PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.27
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.27
1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk All 48 releases
fluent-cart / app / Hooks / CLI / RetentionSnapshotCommand.php

RetentionSnapshotCommand.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.27, at app/Hooks/CLI/RetentionSnapshotCommand.php

64 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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