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