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
|
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\Marketplace;
use Piwik\Common;
use Piwik\Db;
use Piwik\Plugin\ReleaseChannels;
use Piwik\Plugins\CoreUpdater\ReleaseChannel;
use Piwik\Version;
class Environment
{
/**
* @var ReleaseChannel
*/
private $releaseChannel;
private $usersCache = null;
private $websitesCache = null;
private $mySqlCache = null;
private $piwikVersion = null;
public function __construct(ReleaseChannels $releaseChannels)
{
$this->releaseChannel = $releaseChannels->getActiveReleaseChannel();
}
public function setPiwikVersion($piwikVersion)
{
$this->piwikVersion = $piwikVersion;
}
public function getNumUsers()
{
if (!isset($this->usersCache)) {
$this->usersCache = (int)Db::get()->fetchOne('SELECT count(login) FROM `' . Common::prefixTable('user') . '` WHERE login <> "anonymous" ');
}
return $this->usersCache;
}
public function getNumWebsites()
{
if (!isset($this->websitesCache)) {
$this->websitesCache = (int)Db::get()->fetchOne('SELECT count(idsite) FROM `' . Common::prefixTable('site') . '`');
}
return $this->websitesCache;
}
public function getPhpVersion()
{
return PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION;
}
public function getPiwikVersion()
{
if (!empty($this->piwikVersion)) {
return $this->piwikVersion;
}
return Version::VERSION;
}
public function doesPreferStable()
{
if (!empty($this->releaseChannel)) {
return $this->releaseChannel->doesPreferStable();
}
return true;
}
public function getReleaseChannel()
{
if (!empty($this->releaseChannel)) {
return $this->releaseChannel->getId();
}
}
public function getMySQLVersion()
{
if (isset($this->mySqlCache)) {
return $this->mySqlCache;
}
$this->mySqlCache = '';
$db = Db::get();
if (method_exists($db, 'getServerVersion')) {
$this->mySqlCache = $db->getServerVersion();
}
return $this->mySqlCache;
}
}
|