1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Stats\Commands\Database; |
4
|
|
|
|
5
|
|
|
use Joomla\Controller\AbstractController; |
6
|
|
|
use Stats\CommandInterface; |
7
|
|
|
use Stats\Database\Migrations; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* CLI command for checking the database migration status |
11
|
|
|
* |
12
|
|
|
* @method \Stats\CliApplication getApplication() Get the application object. |
13
|
|
|
* @property-read \Stats\CliApplication $app Application object |
14
|
|
|
* |
15
|
|
|
* @since 1.0 |
16
|
|
|
*/ |
17
|
|
|
class StatusCommand extends AbstractController implements CommandInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Database migrations helper |
21
|
|
|
* |
22
|
|
|
* @var Migrations |
23
|
|
|
* @since 1.0 |
24
|
|
|
*/ |
25
|
|
|
private $migrations; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Constructor. |
29
|
|
|
* |
30
|
|
|
* @param Migrations $migrations Database migrations helper |
31
|
|
|
* |
32
|
|
|
* @since 1.0 |
33
|
|
|
*/ |
34
|
|
|
public function __construct(Migrations $migrations) |
35
|
|
|
{ |
36
|
|
|
$this->migrations = $migrations; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Execute the controller. |
41
|
|
|
* |
42
|
|
|
* @return boolean |
43
|
|
|
* |
44
|
|
|
* @since 1.0 |
45
|
|
|
*/ |
46
|
|
|
public function execute() |
47
|
|
|
{ |
48
|
|
|
$this->getApplication()->outputTitle('Database Migrations: Check Status'); |
49
|
|
|
|
50
|
|
|
$status = $this->migrations->checkStatus(); |
51
|
|
|
|
52
|
|
|
if ($status['latest']) |
53
|
|
|
{ |
54
|
|
|
$this->getApplication()->out('<fg=green;options=bold>Your database is up-to-date.</fg=green;options=bold>'); |
55
|
|
|
} |
56
|
|
|
else |
57
|
|
|
{ |
58
|
|
|
$this->getApplication()->out( |
59
|
|
|
'<comment>' . sprintf('Your database is not up-to-date. You are missing %d migrations.', $status['missingMigrations']) . '</comment>' |
60
|
|
|
) |
61
|
|
|
->out() |
62
|
|
|
->out('<comment>' . sprintf('Current Version: %1$s', $status['currentVersion']) . '</comment>') |
63
|
|
|
->out('<comment>' . sprintf('Latest Version: %1$s', $status['latestVersion']) . '</comment>') |
64
|
|
|
->out() |
65
|
|
|
->out(sprintf('To update, run the <fg=magenta>%1$s</fg=magenta> command.', 'database:migrate')); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return true; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Get the command's description |
73
|
|
|
* |
74
|
|
|
* @return string |
75
|
|
|
* |
76
|
|
|
* @since 1.0 |
77
|
|
|
*/ |
78
|
|
|
public function getDescription() |
79
|
|
|
{ |
80
|
|
|
return 'Check the database migration status.'; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get the command's title |
85
|
|
|
* |
86
|
|
|
* @return string |
87
|
|
|
* |
88
|
|
|
* @since 1.0 |
89
|
|
|
*/ |
90
|
|
|
public function getTitle() |
91
|
|
|
{ |
92
|
|
|
return 'Database Migrations Status'; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|