Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@gmail.com>2015-08-31 16:42:07 +0300
committerThomas Steur <thomas.steur@gmail.com>2015-09-22 15:47:08 +0300
commit8f97ef8dee78aa1fd0bba12f34cd4512ee5959cc (patch)
treeab2f7e57660990d951029b5a6d282265b0ba0cbf /core
parent9611d739b69bd188462588d0b8a0463ea8ae6fde (diff)
refs #8549 support for multiple release channels
Diffstat (limited to 'core')
-rw-r--r--core/Plugin/ReleaseChannels.php103
-rw-r--r--core/UpdateCheck.php52
-rw-r--r--core/UpdateCheck/ReleaseChannel.php73
-rw-r--r--core/Updates/2.15.0-b12.php44
-rw-r--r--core/Version.php2
5 files changed, 247 insertions, 27 deletions
diff --git a/core/Plugin/ReleaseChannels.php b/core/Plugin/ReleaseChannels.php
new file mode 100644
index 0000000000..7ee127ce79
--- /dev/null
+++ b/core/Plugin/ReleaseChannels.php
@@ -0,0 +1,103 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.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
+ * @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;
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/core/UpdateCheck.php b/core/UpdateCheck.php
index 43639da9dc..b176ed87c3 100644
--- a/core/UpdateCheck.php
+++ b/core/UpdateCheck.php
@@ -8,12 +8,10 @@
*/
namespace Piwik;
-use Exception;
-use Piwik\Plugins\SitesManager\API;
+use Piwik\Container\StaticContainer;
/**
* Class to check if a newer version of Piwik is available
- *
*/
class UpdateCheck
{
@@ -51,37 +49,39 @@ class UpdateCheck
) {
// set the time checked first, so that parallel Piwik requests don't all trigger the http requests
Option::set(self::LAST_TIME_CHECKED, time(), $autoLoad = 1);
- $parameters = array(
- 'piwik_version' => Version::VERSION,
- 'php_version' => PHP_VERSION,
- 'url' => Url::getCurrentUrlWithoutQueryString(),
- 'trigger' => Common::getRequestVar('module', '', 'string'),
- 'timezone' => API::getInstance()->getDefaultTimezone(),
- );
-
- $url = Config::getInstance()->General['api_service_url']
- . '/1.0/getLatestVersion/'
- . '?' . http_build_query($parameters, '', '&');
- $timeout = self::SOCKET_TIMEOUT;
-
- if (@Config::getInstance()->Debug['allow_upgrades_to_beta']) {
- $url = 'http://builds.piwik.org/LATEST_BETA';
- }
- try {
- $latestVersion = Http::sendHttpRequest($url, $timeout);
- if (!preg_match('~^[0-9][0-9a-zA-Z_.-]*$~D', $latestVersion)) {
- $latestVersion = '';
- }
- } catch (Exception $e) {
- // e.g., disable_functions = fsockopen; allow_url_open = Off
+ $latestVersion = self::getLatestAvailableVersionNumber();
+ $latestVersion = trim((string) $latestVersion);
+ if (!preg_match('~^[0-9][0-9a-zA-Z_.-]*$~D', $latestVersion)) {
$latestVersion = '';
}
+
Option::set(self::LATEST_VERSION, $latestVersion);
}
}
/**
+ * Get the latest available version number for the currently active release channel. Eg '2.15.0-b4' or '2.15.0'.
+ * Should return a semantic version number in format MAJOR.MINOR.PATCH (http://semver.org/).
+ * Returns an empty string in case one cannot connect to the remote server.
+ * @return string
+ */
+ private static function getLatestAvailableVersionNumber()
+ {
+ $channel = StaticContainer::get('\Piwik\Plugin\ReleaseChannels')->getActiveReleaseChannel();
+ $url = $channel->getUrlToCheckForLatestAvailableVersion();
+
+ try {
+ $latestVersion = Http::sendHttpRequest($url, self::SOCKET_TIMEOUT);
+ } catch (\Exception $e) {
+ // e.g., disable_functions = fsockopen; allow_url_open = Off
+ $latestVersion = '';
+ }
+
+ return $latestVersion;
+ }
+
+ /**
* Returns the latest available version number. Does not perform a check whether a later version is available.
*
* @return false|string
diff --git a/core/UpdateCheck/ReleaseChannel.php b/core/UpdateCheck/ReleaseChannel.php
new file mode 100644
index 0000000000..5f2040747e
--- /dev/null
+++ b/core/UpdateCheck/ReleaseChannel.php
@@ -0,0 +1,73 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ */
+namespace Piwik\UpdateCheck;
+
+/**
+ * Base class to define a custom release channel. Plugins can add their own custom release channels by extending this
+ * class in a `plugin/$plugin/ReleaseChannel` folder. Custom release channels can be useful for example to provide
+ * nightly builds, to manage updates for clients via a central server, to package a special Piwik version for clients
+ * with custom plugins etc.
+ *
+ * This is not a public API and it may change without any anouncement.
+ *
+ * @package Piwik\UpdateCheck
+ */
+abstract class ReleaseChannel
+{
+ /**
+ * Get the ID for this release channel. This string will be eg saved in the config to identify the chosen release
+ * channel
+ * @return string
+ */
+ abstract public function getId();
+
+ /**
+ * Get a human readable name for this release channel, will be visible in the UI. Should be already translated.
+ * @return string
+ */
+ abstract public function getName();
+
+ /**
+ * Get the latest available version number for this release channel. Eg '2.15.0-b4' or '2.15.0'. Should be
+ * a semantic version number in format MAJOR.MINOR.PATCH (http://semver.org/). Returning an empty string in case
+ * one cannot connect to the remote server can be acceptable.
+ * @return string
+ */
+ abstract public function getUrlToCheckForLatestAvailableVersion();
+
+ /**
+ * Get the URL to download a specific Piwik archive for the given version number. The returned URL should not
+ * include a URI scheme, meaning it should start with '://...'.
+ *
+ * @param string $version
+ * @return string
+ */
+ abstract public function getDownloadUrlWithoutScheme($version);
+
+ /**
+ * Get the description for this release channel. Will be shown directly next to the name of the release in the
+ * Admin UI. For example 'Recommended' or 'Long Term Support version'.
+ * @return string
+ */
+ public function getDescription()
+ {
+ return '';
+ }
+
+ /**
+ * Get the order for this release channel. The lower the number the more important this release channel is. The
+ * release channel having the lowest order will be shown first and will be used as default release channel in case
+ * no valid release channel is defined.
+ * @return int
+ */
+ public function getOrder()
+ {
+ return 99;
+ }
+} \ No newline at end of file
diff --git a/core/Updates/2.15.0-b12.php b/core/Updates/2.15.0-b12.php
new file mode 100644
index 0000000000..f780e61610
--- /dev/null
+++ b/core/Updates/2.15.0-b12.php
@@ -0,0 +1,44 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ */
+namespace Piwik\Updates;
+
+use Piwik\Config;
+use Piwik\UpdateCheck;
+use Piwik\Updater;
+use Piwik\Updates;
+
+class Updates_2_15_0_b12 extends Updates
+{
+ public function doUpdate(Updater $updater)
+ {
+ $this->migrateBetaUpgradesToReleaseChannel();
+ }
+
+ private function migrateBetaUpgradesToReleaseChannel()
+ {
+ $config = Config::getInstance();
+ $debug = $config->Debug;
+
+ if (array_key_exists('allow_upgrades_to_beta', $debug)) {
+ $allowUpgradesToBeta = 1 == $debug['allow_upgrades_to_beta'];
+ unset($debug['allow_upgrades_to_beta']);
+
+ $general = $config->General;
+ if ($allowUpgradesToBeta) {
+ $general['release_channel'] = 'latest_beta';
+ } else {
+ $general['release_channel'] = 'latest_stable';
+ }
+
+ $config->Debug = $debug;
+ $config->General = $general;
+ $config->forceSave();
+ }
+ }
+}
diff --git a/core/Version.php b/core/Version.php
index 8b271597fb..ee03eb9381 100644
--- a/core/Version.php
+++ b/core/Version.php
@@ -20,7 +20,7 @@ final class Version
* The current Piwik version.
* @var string
*/
- const VERSION = '2.15.0-b11';
+ const VERSION = '2.15.0-b12';
public function isStableVersion($version)
{