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
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@gmail.com>2014-01-09 07:41:17 +0400
committerThomas Steur <thomas.steur@gmail.com>2014-01-09 07:41:17 +0400
commitb671c49014e2793a758cd4aa99fda82bd0f5dab1 (patch)
treefb6b9e40471b0575549cf3e4a636ddf9258b2999 /plugins/CorePluginsAdmin/PluginInstaller.php
parent8f6a07bba0d945dc87c2836c76d0ec25154c059d (diff)
refs #4183 verify require definition when uploading a plugin zip file or when installing/updating a plugin
Diffstat (limited to 'plugins/CorePluginsAdmin/PluginInstaller.php')
-rw-r--r--plugins/CorePluginsAdmin/PluginInstaller.php66
1 files changed, 53 insertions, 13 deletions
diff --git a/plugins/CorePluginsAdmin/PluginInstaller.php b/plugins/CorePluginsAdmin/PluginInstaller.php
index 70cb27de76..284f2bdd52 100644
--- a/plugins/CorePluginsAdmin/PluginInstaller.php
+++ b/plugins/CorePluginsAdmin/PluginInstaller.php
@@ -40,12 +40,23 @@ class PluginInstaller
$tmpPluginZip = SettingsPiwik::rewriteTmpPathWithHostname($tmpPluginZip);
$tmpPluginFolder = SettingsPiwik::rewriteTmpPathWithHostname($tmpPluginFolder);
- $this->makeSureFoldersAreWritable();
- $this->makeSurePluginNameIsValid();
- $this->downloadPluginFromMarketplace($tmpPluginZip);
- $this->extractPluginFiles($tmpPluginZip, $tmpPluginFolder);
- $this->makeSurePluginJsonExists($tmpPluginFolder);
- $this->copyPluginToDestination($tmpPluginFolder);
+ try {
+ $this->makeSureFoldersAreWritable();
+ $this->makeSurePluginNameIsValid();
+ $this->downloadPluginFromMarketplace($tmpPluginZip);
+ $this->extractPluginFiles($tmpPluginZip, $tmpPluginFolder);
+ $this->makeSurePluginJsonExists($tmpPluginFolder);
+ $metadata = $this->getPluginMetadataIfValid($tmpPluginFolder);
+ $this->makeSureThereAreNoMissingRequirements($metadata);
+ $this->copyPluginToDestination($tmpPluginFolder);
+
+ } catch (\Exception $e) {
+
+ $this->removeFileIfExists($tmpPluginZip);
+ $this->removeFolderIfExists($tmpPluginFolder);
+
+ throw $e;
+ }
$this->removeFileIfExists($tmpPluginZip);
$this->removeFolderIfExists($tmpPluginFolder);
@@ -56,16 +67,27 @@ class PluginInstaller
$tmpPluginFolder = PIWIK_USER_PATH . self::PATH_TO_DOWNLOAD . $this->pluginName;
$tmpPluginFolder = SettingsPiwik::rewriteTmpPathWithHostname($tmpPluginFolder);
- $this->makeSureFoldersAreWritable();
- $this->extractPluginFiles($pathToZip, $tmpPluginFolder);
+ try {
+ $this->makeSureFoldersAreWritable();
+ $this->extractPluginFiles($pathToZip, $tmpPluginFolder);
+
+ $this->makeSurePluginJsonExists($tmpPluginFolder);
+ $metadata = $this->getPluginMetadataIfValid($tmpPluginFolder);
+ $this->makeSureThereAreNoMissingRequirements($metadata);
+
+ $this->pluginName = $metadata->name;
- $this->makeSurePluginJsonExists($tmpPluginFolder);
- $metadata = $this->getPluginMetadataIfValid($tmpPluginFolder);
+ $this->fixPluginFolderIfNeeded($tmpPluginFolder);
+ $this->copyPluginToDestination($tmpPluginFolder);
+
+ } catch (\Exception $e) {
- $this->pluginName = $metadata->name;
+ $this->removeFileIfExists($pathToZip);
+ $this->removeFolderIfExists($tmpPluginFolder);
+
+ throw $e;
+ }
- $this->fixPluginFolderIfNeeded($tmpPluginFolder);
- $this->copyPluginToDestination($tmpPluginFolder);
$this->removeFileIfExists($pathToZip);
$this->removeFolderIfExists($tmpPluginFolder);
@@ -128,6 +150,24 @@ class PluginInstaller
}
}
+ private function makeSureThereAreNoMissingRequirements($metadata)
+ {
+ $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);
+ }
+ }
+
private function getPluginMetadataIfValid($tmpPluginFolder)
{
$pluginJsonPath = $this->getPathToPluginJson($tmpPluginFolder);