ConsoleCommand
1 month ago
Dimension
1 month ago
API.php
6 months ago
AggregatedMetric.php
2 years ago
ArchivedMetric.php
1 year ago
Archiver.php
1 month ago
Categories.php
2 years ago
ComponentFactory.php
3 months ago
ComputedMetric.php
1 year ago
ConsoleCommand.php
1 month ago
Controller.php
1 month ago
ControllerAdmin.php
2 weeks ago
Dependency.php
1 month ago
LogTablesProvider.php
2 years ago
Manager.php
1 month ago
Menu.php
1 month ago
MetadataLoader.php
1 month ago
Metric.php
1 month ago
PluginException.php
1 year ago
ProcessedMetric.php
3 months ago
ReleaseChannels.php
3 months ago
Report.php
1 month ago
ReportsProvider.php
2 years ago
RequestProcessors.php
4 months ago
Segment.php
3 months ago
SettingsProvider.php
1 month ago
Tasks.php
1 month ago
ThemeStyles.php
2 weeks ago
ViewDataTable.php
3 months ago
Visualization.php
1 year ago
WidgetsProvider.php
3 months ago
ReleaseChannels.php
89 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Matomo - free/libre analytics platform |
| 5 | * |
| 6 | * @link https://matomo.org |
| 7 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 8 | */ |
| 9 | namespace Piwik\Plugin; |
| 10 | |
| 11 | use Piwik\Config; |
| 12 | use Piwik\Container\StaticContainer; |
| 13 | use Piwik\UpdateCheck\ReleaseChannel; |
| 14 | /** |
| 15 | * Get release channels that are defined by plugins. |
| 16 | */ |
| 17 | class ReleaseChannels |
| 18 | { |
| 19 | /** |
| 20 | * @var Manager |
| 21 | */ |
| 22 | private $pluginManager; |
| 23 | public function __construct(\Piwik\Plugin\Manager $pluginManager) |
| 24 | { |
| 25 | $this->pluginManager = $pluginManager; |
| 26 | } |
| 27 | /** |
| 28 | * @return ReleaseChannel[] |
| 29 | */ |
| 30 | public function getAllReleaseChannels() |
| 31 | { |
| 32 | $classNames = $this->pluginManager->findMultipleComponents('ReleaseChannel', 'Piwik\\UpdateCheck\\ReleaseChannel'); |
| 33 | $channels = array(); |
| 34 | foreach ($classNames as $className) { |
| 35 | $channels[] = StaticContainer::get($className); |
| 36 | } |
| 37 | usort($channels, function (ReleaseChannel $a, ReleaseChannel $b) { |
| 38 | if ($a->getOrder() === $b->getOrder()) { |
| 39 | return 0; |
| 40 | } |
| 41 | return $a->getOrder() < $b->getOrder() ? -1 : 1; |
| 42 | }); |
| 43 | return $channels; |
| 44 | } |
| 45 | /** |
| 46 | * @return ReleaseChannel |
| 47 | */ |
| 48 | public function getActiveReleaseChannel() |
| 49 | { |
| 50 | $channel = Config::getInstance()->General['release_channel']; |
| 51 | $channel = $this->factory($channel); |
| 52 | if (!empty($channel)) { |
| 53 | return $channel; |
| 54 | } |
| 55 | $channels = $this->getAllReleaseChannels(); |
| 56 | // we default to the one with lowest id |
| 57 | return reset($channels); |
| 58 | } |
| 59 | /** |
| 60 | * Sets the given release channel in config but does not save id. $config->forceSave() still needs to be called |
| 61 | * @internal tests only |
| 62 | * @param string $channel |
| 63 | */ |
| 64 | public function setActiveReleaseChannelId($channel) |
| 65 | { |
| 66 | $general = Config::getInstance()->General; |
| 67 | $general['release_channel'] = $channel; |
| 68 | Config::getInstance()->General = $general; |
| 69 | } |
| 70 | public function isValidReleaseChannelId($releaseChannelId) |
| 71 | { |
| 72 | $channel = $this->factory($releaseChannelId); |
| 73 | return !empty($channel); |
| 74 | } |
| 75 | /** |
| 76 | * @param string $releaseChannelId |
| 77 | */ |
| 78 | private function factory($releaseChannelId) : ?ReleaseChannel |
| 79 | { |
| 80 | $releaseChannelId = strtolower($releaseChannelId); |
| 81 | foreach ($this->getAllReleaseChannels() as $releaseChannel) { |
| 82 | if ($releaseChannelId === strtolower($releaseChannel->getId())) { |
| 83 | return $releaseChannel; |
| 84 | } |
| 85 | } |
| 86 | return null; |
| 87 | } |
| 88 | } |
| 89 |