@@ 21-84 (lines=64) @@ | ||
18 | * @method \Joomla\StatsServer\CliApplication getApplication() Get the application object. |
|
19 | * @property-read \Joomla\StatsServer\CliApplication $app Application object |
|
20 | */ |
|
21 | class RecentCommand extends AbstractController implements CommandInterface |
|
22 | { |
|
23 | /** |
|
24 | * JSON view for displaying the statistics. |
|
25 | * |
|
26 | * @var StatsJsonView |
|
27 | */ |
|
28 | private $view; |
|
29 | ||
30 | /** |
|
31 | * Constructor. |
|
32 | * |
|
33 | * @param StatsJsonView $view JSON view for displaying the statistics. |
|
34 | */ |
|
35 | public function __construct(StatsJsonView $view) |
|
36 | { |
|
37 | $this->view = $view; |
|
38 | } |
|
39 | ||
40 | /** |
|
41 | * Execute the controller. |
|
42 | * |
|
43 | * @return boolean |
|
44 | */ |
|
45 | public function execute() |
|
46 | { |
|
47 | $this->getApplication()->outputTitle('Creating Statistics Snapshot'); |
|
48 | ||
49 | // We want the full raw data set for our snapshot |
|
50 | $this->view->isAuthorizedRaw(true); |
|
51 | $this->view->isRecent(true); |
|
52 | ||
53 | $file = APPROOT . '/snapshots/' . date('YmdHis') . '_recent'; |
|
54 | ||
55 | if (!file_put_contents($file, $this->view->render())) |
|
56 | { |
|
57 | throw new \RuntimeException('Failed writing snapshot to the filesystem at ' . $file); |
|
58 | } |
|
59 | ||
60 | $this->getApplication()->out('<info>Snapshot successfully recorded.</info>'); |
|
61 | ||
62 | return true; |
|
63 | } |
|
64 | ||
65 | /** |
|
66 | * Get the command's description |
|
67 | * |
|
68 | * @return string |
|
69 | */ |
|
70 | public function getDescription() : string |
|
71 | { |
|
72 | return 'Takes a snapshot of the recently updated statistics data.'; |
|
73 | } |
|
74 | ||
75 | /** |
|
76 | * Get the command's title |
|
77 | * |
|
78 | * @return string |
|
79 | */ |
|
80 | public function getTitle() : string |
|
81 | { |
|
82 | return 'Recent Stats Snapshot'; |
|
83 | } |
|
84 | } |
|
85 |
@@ 21-83 (lines=63) @@ | ||
18 | * @method \Joomla\StatsServer\CliApplication getApplication() Get the application object. |
|
19 | * @property-read \Joomla\StatsServer\CliApplication $app Application object |
|
20 | */ |
|
21 | class SnapshotCommand extends AbstractController implements CommandInterface |
|
22 | { |
|
23 | /** |
|
24 | * JSON view for displaying the statistics. |
|
25 | * |
|
26 | * @var StatsJsonView |
|
27 | */ |
|
28 | private $view; |
|
29 | ||
30 | /** |
|
31 | * Constructor. |
|
32 | * |
|
33 | * @param StatsJsonView $view JSON view for displaying the statistics. |
|
34 | */ |
|
35 | public function __construct(StatsJsonView $view) |
|
36 | { |
|
37 | $this->view = $view; |
|
38 | } |
|
39 | ||
40 | /** |
|
41 | * Execute the controller. |
|
42 | * |
|
43 | * @return boolean |
|
44 | */ |
|
45 | public function execute() |
|
46 | { |
|
47 | $this->getApplication()->outputTitle('Creating Statistics Snapshot'); |
|
48 | ||
49 | // We want the full raw data set for our snapshot |
|
50 | $this->view->isAuthorizedRaw(true); |
|
51 | ||
52 | $file = APPROOT . '/snapshots/' . date('YmdHis'); |
|
53 | ||
54 | if (!file_put_contents($file, $this->view->render())) |
|
55 | { |
|
56 | throw new \RuntimeException('Failed writing snapshot to the filesystem at ' . $file); |
|
57 | } |
|
58 | ||
59 | $this->getApplication()->out('<info>Snapshot successfully recorded.</info>'); |
|
60 | ||
61 | return true; |
|
62 | } |
|
63 | ||
64 | /** |
|
65 | * Get the command's description |
|
66 | * |
|
67 | * @return string |
|
68 | */ |
|
69 | public function getDescription() : string |
|
70 | { |
|
71 | return 'Takes a snapshot of the statistics data.'; |
|
72 | } |
|
73 | ||
74 | /** |
|
75 | * Get the command's title |
|
76 | * |
|
77 | * @return string |
|
78 | */ |
|
79 | public function getTitle() : string |
|
80 | { |
|
81 | return 'Stats Snapshot'; |
|
82 | } |
|
83 | } |
|
84 |