1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2018, michag86 ([email protected]) |
4
|
|
|
* |
5
|
|
|
* @license GNU AGPL version 3 or any later version |
6
|
|
|
* |
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU Affero General Public License as |
9
|
|
|
* published by the Free Software Foundation, either version 3 of the |
10
|
|
|
* License, or (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace OC\Core\Command\App; |
23
|
|
|
|
24
|
|
|
use OCP\App\IAppManager; |
25
|
|
|
use OC\Installer; |
26
|
|
|
use OCP\ILogger; |
27
|
|
|
use Symfony\Component\Console\Command\Command; |
28
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
29
|
|
|
use Symfony\Component\Console\Input\InputOption; |
30
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
31
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
32
|
|
|
|
33
|
|
|
class Update extends Command { |
34
|
|
|
|
35
|
|
|
/** @var IAppManager */ |
36
|
|
|
protected $manager; |
37
|
|
|
/** @var Installer */ |
38
|
|
|
private $installer; |
39
|
|
|
/** @var ILogger */ |
40
|
|
|
private $logger; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param IAppManager $manager |
44
|
|
|
* @param Installer $installer |
45
|
|
|
*/ |
46
|
|
|
public function __construct(IAppManager $manager, Installer $installer, ILogger $logger) { |
47
|
|
|
parent::__construct(); |
48
|
|
|
$this->manager = $manager; |
49
|
|
|
$this->installer = $installer; |
50
|
|
|
$this->logger = $logger; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
protected function configure() { |
54
|
|
|
$this |
55
|
|
|
->setName('app:update') |
56
|
|
|
->setDescription('update an app or all apps') |
57
|
|
|
->addArgument( |
58
|
|
|
'app-id', |
59
|
|
|
InputArgument::OPTIONAL, |
60
|
|
|
'update the specified app' |
61
|
|
|
) |
62
|
|
|
->addOption( |
63
|
|
|
'all', |
64
|
|
|
null, |
65
|
|
|
InputOption::VALUE_NONE, |
66
|
|
|
'update all updatable apps' |
67
|
|
|
) |
68
|
|
|
->addOption( |
69
|
|
|
'showonly', |
70
|
|
|
null, |
71
|
|
|
InputOption::VALUE_NONE, |
72
|
|
|
'show update(s) without updating' |
73
|
|
|
) |
74
|
|
|
|
75
|
|
|
; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
79
|
|
|
$singleAppId = $input->getArgument('app-id'); |
80
|
|
|
|
81
|
|
|
if ($singleAppId) { |
82
|
|
|
$apps = array($singleAppId); |
83
|
|
|
try { |
84
|
|
|
$this->manager->getAppPath($singleAppId); |
|
|
|
|
85
|
|
|
} catch (\OCP\App\AppPathNotFoundException $e) { |
86
|
|
|
$output->writeln($singleAppId . ' not installed'); |
|
|
|
|
87
|
|
|
return 1; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
} else if ($input->getOption('all') || $input->getOption('showonly')) { |
91
|
|
|
$apps = \OC_App::getAllApps(); |
92
|
|
|
} else { |
93
|
|
|
$output->writeln("<error>Please specify an app to update or \"--all\" to update all updatable apps\"</error>"); |
94
|
|
|
return 1; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$return = 0; |
98
|
|
|
foreach ($apps as $appId) { |
99
|
|
|
$newVersion = $this->installer->isUpdateAvailable($appId); |
100
|
|
|
if ($newVersion) { |
101
|
|
|
$output->writeln($appId . ' new version available: ' . $newVersion); |
102
|
|
|
|
103
|
|
|
if (!$input->getOption('showonly')) { |
104
|
|
|
try { |
105
|
|
|
$result = $this->installer->updateAppstoreApp($appId); |
106
|
|
|
} catch(\Exception $e) { |
107
|
|
|
$this->logger->logException($e, ['message' => 'Failure during update of app "' . $appId . '"','app' => 'app:update']); |
108
|
|
|
$output->writeln('Error: ' . $e->getMessage()); |
109
|
|
|
$return = 1; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
if ($result === false) { |
113
|
|
|
$output->writeln($appId . ' couldn\'t be updated'); |
114
|
|
|
$return = 1; |
115
|
|
|
} else if($result === true) { |
116
|
|
|
$output->writeln($appId . ' updated'); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
return $return; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|