|
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
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Update command |
|
16
|
|
|
* |
|
17
|
|
|
* @method \Joomla\StatsServer\CliApplication getApplication() Get the application object. |
|
18
|
|
|
* @property-read \Joomla\StatsServer\CliApplication $app Application object |
|
19
|
|
|
*/ |
|
20
|
|
|
class UpdateCommand extends AbstractController implements CommandInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Execute the controller. |
|
24
|
|
|
* |
|
25
|
|
|
* @return boolean |
|
26
|
|
|
*/ |
|
27
|
|
|
public function execute() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->getApplication()->outputTitle('Update Server'); |
|
30
|
|
|
|
|
31
|
|
|
$this->getApplication()->out('<info>Updating server to git HEAD</info>'); |
|
32
|
|
|
|
|
33
|
|
|
// Pull from remote repo |
|
34
|
|
|
$this->runCommand('cd ' . APPROOT . ' && git pull 2>&1'); |
|
35
|
|
|
|
|
36
|
|
|
$this->getApplication()->out('<info>Updating Composer resources</info>'); |
|
37
|
|
|
|
|
38
|
|
|
// Run Composer install |
|
39
|
|
|
$this->runCommand('cd ' . APPROOT . ' && composer install --no-dev -o 2>&1'); |
|
40
|
|
|
|
|
41
|
|
|
$this->getApplication()->out('<info>Update complete</info>'); |
|
42
|
|
|
|
|
43
|
|
|
return true; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Get the command's description |
|
48
|
|
|
* |
|
49
|
|
|
* @return string |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getDescription() : string |
|
52
|
|
|
{ |
|
53
|
|
|
return 'Update the server to the current git HEAD.'; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Get the command's title |
|
58
|
|
|
* |
|
59
|
|
|
* @return string |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getTitle() : string |
|
62
|
|
|
{ |
|
63
|
|
|
return 'Update Server'; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Execute a command on the server. |
|
68
|
|
|
* |
|
69
|
|
|
* @param string $command The command to execute. |
|
70
|
|
|
* |
|
71
|
|
|
* @return string Return data from the command |
|
72
|
|
|
* |
|
73
|
|
|
* @throws \RuntimeException |
|
74
|
|
|
*/ |
|
75
|
|
|
private function runCommand(string $command) : string |
|
76
|
|
|
{ |
|
77
|
|
|
$lastLine = system($command, $status); |
|
78
|
|
|
|
|
79
|
|
|
if ($status) |
|
|
|
|
|
|
80
|
|
|
{ |
|
81
|
|
|
// Command exited with a status != 0 |
|
82
|
|
|
if ($lastLine) |
|
83
|
|
|
{ |
|
84
|
|
|
$this->getApplication()->out($lastLine); |
|
85
|
|
|
|
|
86
|
|
|
throw new \RuntimeException($lastLine); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
$this->getApplication()->out('<error>An unknown error occurred</error>'); |
|
90
|
|
|
|
|
91
|
|
|
throw new \RuntimeException('An unknown error occurred'); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return $lastLine; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: