blob: 9188fc4c25167b53dc0ad6d2acd2612d479e2a1d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugin;
use Piwik\Config;
use Piwik\Container\StaticContainer;
use Piwik\UpdateCheck\ReleaseChannel;
/**
* Get release channels that are defined by plugins.
*/
class ReleaseChannels
{
/**
* @var Manager
*/
private $pluginManager;
public function __construct(Manager $pluginManager)
{
$this->pluginManager = $pluginManager;
}
/**
* @return ReleaseChannel[]
*/
public function getAllReleaseChannels()
{
$classNames = $this->pluginManager->findMultipleComponents('ReleaseChannel', 'Piwik\\UpdateCheck\\ReleaseChannel');
$channels = array();
foreach ($classNames as $className) {
$channels[] = StaticContainer::get($className);
}
usort($channels, function (ReleaseChannel $a, ReleaseChannel $b) {
if ($a->getOrder() === $b->getOrder()) {
return 0;
}
return ($a->getOrder() < $b->getOrder()) ? -1 : 1;
});
return $channels;
}
/**
* @return ReleaseChannel
*/
public function getActiveReleaseChannel()
{
$channel = Config::getInstance()->General['release_channel'];
$channel = $this->factory($channel);
if (!empty($channel)) {
return $channel;
}
$channels = $this->getAllReleaseChannels();
// we default to the one with lowest id
return reset($channels);
}
/**
* Sets the given release channel in config but does not save id. $config->forceSave() still needs to be called
* @internal tests only
* @param string $channel
*/
public function setActiveReleaseChannelId($channel)
{
$general = Config::getInstance()->General;
$general['release_channel'] = $channel;
Config::getInstance()->General = $general;
}
public function isValidReleaseChannelId($releaseChannelId)
{
$channel = $this->factory($releaseChannelId);
return !empty($channel);
}
/**
* @param string $releaseChannelId
* @return ReleaseChannel
*/
private function factory($releaseChannelId)
{
$releaseChannelId = strtolower($releaseChannelId);
foreach ($this->getAllReleaseChannels() as $releaseChannel) {
if ($releaseChannelId === strtolower($releaseChannel->getId())) {
return $releaseChannel;
}
}
}
}
|