private function makeSureThereAreNoMissingRequirements($metadata) { $requires = array(); if (!empty($metadata->require)) { $requires = (array) $metadata->require; } $dependency = new PluginDependency(); $missingDependencies = $dependency->getMissingDependencies($requires); if (!empty($missingDependencies)) { $message = ''; foreach ($missingDependencies as $dep) { $params = array(ucfirst($dep['requirement']), $dep['actualVersion'], $dep['requiredVersion']); $message .= Piwik::translate('CorePluginsAdmin_MissingRequirementsNotice', $params); } throw new PluginInstallerException($message); } }
/** * @param $plugin */ private function addMissingRequirements($plugin) { $plugin['missingRequirements'] = array(); if (empty($plugin['versions']) || !is_array($plugin['versions'])) { return $plugin; } $latestVersion = $plugin['versions'][count($plugin['versions']) - 1]; if (empty($latestVersion['requires'])) { return $plugin; } $requires = $latestVersion['requires']; $dependency = new PluginDependency(); $plugin['missingRequirements'] = $dependency->getMissingDependencies($requires); return $plugin; }
public function getMissingDependencies($piwikVersion = null) { if (empty($this->pluginInformation['require'])) { return array(); } $dependency = new Dependency(); if (!is_null($piwikVersion)) { $dependency->setPiwikVersion($piwikVersion); } return $dependency->getMissingDependencies($this->pluginInformation['require']); }
protected function checkAndUpdateRequiredPiwikVersion($pluginName, OutputInterface $output) { $pluginJsonPath = $this->getPluginPath($pluginName) . '/plugin.json'; $relativePluginJson = $this->getRelativePluginPath($pluginName) . '/plugin.json'; if (!file_exists($pluginJsonPath) || !is_writable($pluginJsonPath)) { return; } $pluginJson = file_get_contents($pluginJsonPath); $pluginJson = json_decode($pluginJson, true); if (empty($pluginJson)) { return; } if (empty($pluginJson['require'])) { $pluginJson['require'] = array(); } $piwikVersion = Version::VERSION; $newRequiredVersion = '>=' . $piwikVersion; if (!empty($pluginJson['require']['piwik'])) { $requiredVersion = $pluginJson['require']['piwik']; if ($requiredVersion === $newRequiredVersion) { return; } $dependency = new Dependency(); $missingVersion = $dependency->getMissingVersions($piwikVersion, $requiredVersion); if (!empty($missingVersion)) { $msg = sprintf('We cannot generate this component as the plugin "%s" requires the Piwik version "%s" in the file "%s". Generating this component requires "%s". If you know your plugin is compatible with your Piwik version remove the required Piwik version in "%s" and try to execute this command again.', $pluginName, $requiredVersion, $relativePluginJson, $newRequiredVersion, $relativePluginJson); throw new \Exception($msg); } $output->writeln(''); $output->writeln(sprintf('<comment>We have updated the required Piwik version from "%s" to "%s" in "%s".</comment>', $requiredVersion, $newRequiredVersion, $relativePluginJson)); } else { $output->writeln(''); $output->writeln(sprintf('<comment>We have updated your "%s" to require the Piwik version "%s".</comment>', $relativePluginJson, $newRequiredVersion)); } $pluginJson['require']['piwik'] = $newRequiredVersion; file_put_contents($pluginJsonPath, $this->toJson($pluginJson)); }
private function assertMissingVersion($currentVersion, $requiredVersion, $expectedMissing) { $missing = $this->dependency->getMissingVersions($currentVersion, $requiredVersion); $this->assertEquals($expectedMissing, $missing); }
public function installAllPaidPlugins() { Piwik::checkUserHasSuperUserAccess(); $this->dieIfPluginsAdminIsDisabled(); Plugin\ControllerAdmin::displayWarningIfConfigFileNotWritable(); Nonce::checkNonce(static::INSTALL_NONCE); $paidPlugins = $this->plugins->getAllPaidPlugins(); $hasErrors = false; foreach ($paidPlugins as $paidPlugin) { if (!$this->canPluginBeInstalled($paidPlugin)) { continue; } $pluginName = $paidPlugin['name']; try { $this->pluginInstaller->installOrUpdatePluginFromMarketplace($pluginName); } catch (\Exception $e) { $notification = new Notification($e->getMessage()); $notification->context = Notification::CONTEXT_ERROR; Notification\Manager::notify('Marketplace_Install' . $pluginName, $notification); $hasErrors = true; } } if ($hasErrors) { Url::redirectToReferrer(); return; } $dependency = new Plugin\Dependency(); for ($i = 0; $i <= 10; $i++) { foreach ($paidPlugins as $index => $paidPlugin) { $pluginName = $paidPlugin['name']; if ($this->pluginManager->isPluginActivated($pluginName)) { unset($paidPlugins[$index]); continue; } if (empty($paidPlugin['require']) || !$dependency->hasDependencyToDisabledPlugin($paidPlugin['require'])) { unset($paidPlugins[$index]); try { $this->pluginManager->activatePlugin($pluginName); } catch (Exception $e) { $hasErrors = true; $notification = new Notification($e->getMessage()); $notification->context = Notification::CONTEXT_ERROR; Notification\Manager::notify('Marketplace_Install' . $pluginName, $notification); } } } } if ($hasErrors) { $notification = new Notification(Piwik::translate('Marketplace_OnlySomePaidPluginsInstalledAndActivated')); $notification->context = Notification::CONTEXT_INFO; } else { $notification = new Notification(Piwik::translate('Marketplace_AllPaidPluginsInstalledAndActivated')); $notification->context = Notification::CONTEXT_SUCCESS; } Notification\Manager::notify('Marketplace_InstallAll', $notification); Url::redirectToReferrer(); }
/** * @param $piwikVersion * @return Dependency */ private function makeDependency($piwikVersion) { $dependency = new Dependency(); if (!is_null($piwikVersion)) { $dependency->setPiwikVersion($piwikVersion); } return $dependency; }
protected function checkAndUpdateRequiredPiwikVersion($pluginName, OutputInterface $output) { $pluginJsonPath = $this->getPluginPath($pluginName) . '/plugin.json'; $relativePluginJson = $this->getRelativePluginPath($pluginName) . '/plugin.json'; if (!file_exists($pluginJsonPath) || !is_writable($pluginJsonPath)) { return; } $pluginJson = file_get_contents($pluginJsonPath); $pluginJson = json_decode($pluginJson, true); if (empty($pluginJson)) { return; } if (empty($pluginJson['require'])) { $pluginJson['require'] = array(); } $piwikVersion = Version::VERSION; $nextMajorVersion = (int) substr($piwikVersion, 0, strpos($piwikVersion, '.')) + 1; $secondPartPiwikVersionRequire = ',<' . $nextMajorVersion . '.0.0-b1'; if (false === strpos($piwikVersion, '-')) { // see https://github.com/composer/composer/issues/4080 we need to specify -stable otherwise it would match // $piwikVersion-dev meaning it would also match all pre-released. However, we only want to match a stable // release $piwikVersion .= '-stable'; } $newRequiredVersion = sprintf('>=%s,<%d.0.0', $piwikVersion, $nextMajorVersion); if (!empty($pluginJson['require']['piwik'])) { $requiredVersion = trim($pluginJson['require']['piwik']); if ($requiredVersion === $newRequiredVersion) { // there is nothing to updated return; } // our generated versions look like ">=2.25.4,<3.0.0-b1". // We only updated the Piwik version in the first part if the piwik version looks like that or if it has only // one piwik version defined. In all other cases, eg user uses || etc we do not update it as user has customized // the piwik version. foreach (['<>', '!=', '<=', '==', '^'] as $comparison) { if (strpos($requiredVersion, $comparison) === 0) { // user is using custom piwik version require, we do not overwrite anything. return; } } if (strpos($requiredVersion, '||') !== false || strpos($requiredVersion, ' ') !== false) { // user is using custom piwik version require, we do not overwrite anything. return; } $requiredPiwikVersions = explode(',', (string) $requiredVersion); $numRequiredPiwikVersions = count($requiredPiwikVersions); if ($numRequiredPiwikVersions > 2) { // user is using custom piwik version require, we do not overwrite anything. return; } if ($numRequiredPiwikVersions === 2 && !Common::stringEndsWith($requiredVersion, $secondPartPiwikVersionRequire)) { // user is using custom piwik version require, we do not overwrite anything return; } // if only one piwik version is defined we update it to make sure it does now specify an upper version limit $dependency = new Dependency(); $missingVersion = $dependency->getMissingVersions($piwikVersion, $requiredVersion); if (!empty($missingVersion)) { $msg = sprintf('We cannot generate this component as the plugin "%s" requires the Piwik version "%s" in the file "%s". Generating this component requires "%s". If you know your plugin is compatible with your Piwik version remove the required Piwik version in "%s" and try to execute this command again.', $pluginName, $requiredVersion, $relativePluginJson, $newRequiredVersion, $relativePluginJson); throw new \Exception($msg); } $output->writeln(''); $output->writeln(sprintf('<comment>We have updated the required Piwik version from "%s" to "%s" in "%s".</comment>', $requiredVersion, $newRequiredVersion, $relativePluginJson)); } else { $output->writeln(''); $output->writeln(sprintf('<comment>We have updated your "%s" to require the Piwik version "%s".</comment>', $relativePluginJson, $newRequiredVersion)); } $pluginJson['require']['piwik'] = $newRequiredVersion; file_put_contents($pluginJsonPath, $this->toJson($pluginJson)); }