Completed
Push — mysql_improvements ( 2e95ce...dedbef )
by Michael
03:52
created

SnapshotCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * Joomla! Statistics Server
4
 *
5
 * @copyright  Copyright (C) 2013 - 2017 Open Source Matters, Inc. All rights reserved.
6
 * @license    http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License Version 2 or Later
7
 */
8
9
namespace Joomla\StatsServer\Commands;
10
11
use Joomla\Controller\AbstractController;
12
use Joomla\StatsServer\CommandInterface;
13
use Joomla\StatsServer\Views\Stats\StatsJsonView;
14
15
/**
16
 * Snapshot command
17
 *
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