PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.0.3
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.0.3
5.12.1 5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Plugin / Dependency.php
matomo / app / core / Plugin Last commit date
ConsoleCommand 2 years ago Dimension 2 years ago API.php 2 years ago AggregatedMetric.php 2 years ago ArchivedMetric.php 2 years ago Archiver.php 2 years ago Categories.php 2 years ago ComponentFactory.php 2 years ago ComputedMetric.php 2 years ago ConsoleCommand.php 2 years ago Controller.php 2 years ago ControllerAdmin.php 2 years ago Dependency.php 2 years ago LogTablesProvider.php 2 years ago Manager.php 2 years ago Menu.php 2 years ago MetadataLoader.php 2 years ago Metric.php 2 years ago PluginException.php 2 years ago ProcessedMetric.php 2 years ago ReleaseChannels.php 2 years ago Report.php 2 years ago ReportsProvider.php 2 years ago RequestProcessors.php 2 years ago Segment.php 2 years ago SettingsProvider.php 2 years ago Tasks.php 2 years ago ThemeStyles.php 2 years ago ViewDataTable.php 2 years ago Visualization.php 2 years ago WidgetsProvider.php 2 years ago
Dependency.php
160 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 *
9 */
10 namespace Piwik\Plugin;
11
12 use Composer\Semver\VersionParser;
13 use Piwik\Plugin\Manager as PluginManager;
14 use Piwik\Plugins\Marketplace\Environment;
15 use Piwik\Version;
16 /**
17 *
18 */
19 class Dependency
20 {
21 private $piwikVersion;
22 private $phpVersion;
23 public function __construct()
24 {
25 $this->setPiwikVersion(Version::VERSION);
26 $this->setPhpVersion(PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION);
27 }
28 public function setEnvironment(Environment $environment)
29 {
30 $this->setPiwikVersion($environment->getPiwikVersion());
31 $this->setPhpVersion($environment->getPhpVersion());
32 }
33 public function getMissingDependencies($requires)
34 {
35 $missingRequirements = array();
36 if (empty($requires)) {
37 return $missingRequirements;
38 }
39 foreach ($requires as $name => $requiredVersion) {
40 $currentVersion = $this->getCurrentVersion($name);
41 if (in_array(strtolower($name), ['piwik', 'matomo'])) {
42 $requiredVersion = $this->markPluginsWithoutUpperBoundMatomoRequirementAsIncompatible($requiredVersion);
43 }
44 $missingVersions = $this->getMissingVersions($currentVersion, $requiredVersion);
45 if (!empty($missingVersions)) {
46 $missingRequirements[] = array('requirement' => $name, 'actualVersion' => $currentVersion, 'requiredVersion' => $requiredVersion, 'causedBy' => implode(', ', $missingVersions));
47 }
48 }
49 return $missingRequirements;
50 }
51 public function getMissingVersions($currentVersion, $requiredVersion)
52 {
53 $currentVersion = trim($currentVersion ?? '');
54 $missingVersions = array();
55 if (empty($currentVersion)) {
56 if (!empty($requiredVersion)) {
57 $missingVersions[] = (string) $requiredVersion;
58 }
59 return $missingVersions;
60 }
61 $requiredVersion = $this->makeVersionBackwardsCompatibleIfNoComparisonDefined($requiredVersion);
62 $version = new VersionParser();
63 $constraintsExisting = $version->parseConstraints($currentVersion);
64 $requiredVersions = explode(',', (string) $requiredVersion);
65 foreach ($requiredVersions as $required) {
66 $required = trim($required);
67 if (empty($required)) {
68 continue;
69 }
70 $required = $this->makeVersionBackwardsCompatibleIfNoComparisonDefined($required);
71 $constraintRequired = $version->parseConstraints($required);
72 if (!$constraintRequired->matches($constraintsExisting)) {
73 $missingVersions[] = $required;
74 }
75 }
76 return $missingVersions;
77 }
78 /**
79 * Upon Matomo 4 we require a lower and upper version bound for Matomo to be set in plugin.json
80 * If that is not the case we assume the plugin not to be compatible with Matomo 4
81 *
82 * @param string $requiredVersion
83 * @return string
84 */
85 private function markPluginsWithoutUpperBoundMatomoRequirementAsIncompatible($requiredVersion)
86 {
87 if (strpos($requiredVersion, ',') !== false) {
88 return $requiredVersion;
89 }
90 $minVersion = str_replace(array('>', '=', '<', '!', '~', '^'), '', $requiredVersion);
91 if (preg_match("/^\\<=?\\d/", $requiredVersion)) {
92 $upperLimit = '>=' . $minVersion[0] . '.0.0-b1,' . $requiredVersion;
93 } else {
94 if (!empty($minVersion) && is_numeric($minVersion[0])) {
95 $upperLimit = $requiredVersion . ',<' . ($minVersion[0] + 1) . '.0.0-b1';
96 } else {
97 $upperLimit = '>=4.0.0-b1,<5.0.0-b1';
98 }
99 }
100 return $upperLimit;
101 }
102 private function makeVersionBackwardsCompatibleIfNoComparisonDefined($version)
103 {
104 if (!empty($version) && preg_match('/^(\\d+)\\.(\\d+)/', $version)) {
105 // TODO: we should remove this from piwik 3. To stay BC we add >= if no >= is defined yet
106 $version = '>=' . $version;
107 }
108 return $version;
109 }
110 public function setPiwikVersion($piwikVersion)
111 {
112 $this->piwikVersion = $piwikVersion;
113 }
114 public function setPhpVersion($phpVersion)
115 {
116 $this->phpVersion = $phpVersion;
117 }
118 public function hasDependencyToDisabledPlugin($requires)
119 {
120 if (empty($requires)) {
121 return false;
122 }
123 foreach ($requires as $name => $requiredVersion) {
124 $nameLower = strtolower($name);
125 $isPluginRequire = !in_array($nameLower, array('piwik', 'php', 'matomo'));
126 if ($isPluginRequire) {
127 // we do not check version, only whether it's activated. Everything that is not piwik or php is assumed
128 // a plugin so far.
129 if (!PluginManager::getInstance()->isPluginActivated($name)) {
130 return true;
131 }
132 }
133 }
134 return false;
135 }
136 private function getCurrentVersion($name)
137 {
138 switch (strtolower($name)) {
139 case 'matomo':
140 case 'piwik':
141 return $this->piwikVersion;
142 case 'php':
143 return $this->phpVersion;
144 default:
145 try {
146 $pluginNames = PluginManager::getAllPluginsNames();
147 if (!in_array($name, $pluginNames) || !PluginManager::getInstance()->isPluginLoaded($name)) {
148 return '';
149 }
150 $plugin = PluginManager::getInstance()->loadPlugin(ucfirst($name));
151 if (!empty($plugin)) {
152 return $plugin->getVersion();
153 }
154 } catch (\Exception $e) {
155 }
156 }
157 return '';
158 }
159 }
160