1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Jitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) Jitamin Team |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Jitamin\Console; |
13
|
|
|
|
14
|
|
|
use Jitamin\Foundation\Plugin\Base as BasePlugin; |
15
|
|
|
use Jitamin\Foundation\Plugin\Directory; |
16
|
|
|
use Jitamin\Foundation\Plugin\Installer; |
17
|
|
|
use LogicException; |
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Plugin Upgrade command class. |
23
|
|
|
*/ |
24
|
|
|
class PluginUpgradeCommand extends BaseCommand |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Configure the console command. |
28
|
|
|
* |
29
|
|
|
* @return void |
30
|
|
|
*/ |
31
|
|
|
protected function configure() |
32
|
|
|
{ |
33
|
|
|
$this |
34
|
|
|
->setName('plugin:upgrade') |
35
|
|
|
->setDescription('Update all installed plugins'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Execute the console command. |
40
|
|
|
* |
41
|
|
|
* @param InputInterface $output |
42
|
|
|
* @param OutputInterface $output |
43
|
|
|
* |
44
|
|
|
* @return void |
45
|
|
|
*/ |
46
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
47
|
|
|
{ |
48
|
|
|
if (!Installer::isConfigured()) { |
49
|
|
|
throw new LogicException('Jitamin is not configured to install plugins itself'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$installer = new Installer($this->container); |
53
|
|
|
$availablePlugins = Directory::getInstance($this->container)->getAvailablePlugins(); |
54
|
|
|
|
55
|
|
|
foreach ($this->pluginLoader->getPlugins() as $installedPlugin) { |
|
|
|
|
56
|
|
|
$pluginDetails = $this->getPluginDetails($availablePlugins, $installedPlugin); |
57
|
|
|
|
58
|
|
|
if ($pluginDetails === null) { |
59
|
|
|
$output->writeln('<error>* Plugin not available in the directory: '.$installedPlugin->getPluginName().'</error>'); |
60
|
|
|
} elseif ($pluginDetails['version'] > $installedPlugin->getPluginVersion()) { |
61
|
|
|
$output->writeln('<comment>* Updating plugin: '.$installedPlugin->getPluginName().'</comment>'); |
62
|
|
|
$installer->update($pluginDetails['download']); |
63
|
|
|
} else { |
64
|
|
|
$output->writeln('<info>* Plugin up to date: '.$installedPlugin->getPluginName().'</info>'); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get plugin details. |
71
|
|
|
* |
72
|
|
|
* @param array $availablePlugins |
73
|
|
|
* @param BasePlugin $installedPlugin |
74
|
|
|
* |
75
|
|
|
* @return mixed |
76
|
|
|
*/ |
77
|
|
|
protected function getPluginDetails(array $availablePlugins, BasePlugin $installedPlugin) |
78
|
|
|
{ |
79
|
|
|
foreach ($availablePlugins as $availablePlugin) { |
80
|
|
|
if ($availablePlugin['title'] === $installedPlugin->getPluginName()) { |
81
|
|
|
return $availablePlugin; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.