diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2013-09-23 06:25:22 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2013-09-23 06:25:22 +0400 |
commit | b67827bbd2215cefeac5f4d65c23846619c8d223 (patch) | |
tree | 33cdf7f03327175a3918ca865d19be4527956598 /plugins/CorePluginsAdmin/PluginInstaller.php | |
parent | 4620a36ad5bbf08e3b510bac495a3e802edff970 (diff) |
refs #4053 cleanup code of marketplace integration
Diffstat (limited to 'plugins/CorePluginsAdmin/PluginInstaller.php')
-rw-r--r-- | plugins/CorePluginsAdmin/PluginInstaller.php | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/plugins/CorePluginsAdmin/PluginInstaller.php b/plugins/CorePluginsAdmin/PluginInstaller.php index e77b79757d..cd664b3aef 100644 --- a/plugins/CorePluginsAdmin/PluginInstaller.php +++ b/plugins/CorePluginsAdmin/PluginInstaller.php @@ -35,6 +35,7 @@ class PluginInstaller $tmpPluginFolder = PIWIK_USER_PATH . self::PATH_TO_DOWNLOAD . $this->pluginName; $this->makeSureFoldersAreWritable(); + $this->makeSurePluginNameIsValid(); $this->downloadPluginFromMarketplace($tmpPluginZip); $this->extractPluginFiles($tmpPluginZip, $tmpPluginFolder); $this->makeSurePluginJsonExists($tmpPluginFolder); @@ -53,21 +54,21 @@ class PluginInstaller { $this->removeFileIfExists($pluginZipTargetFile); - try { - $marketplace = new MarketplaceApiClient(); - $pluginDetails = $marketplace->getPluginInfo($this->pluginName); - } catch (\Exception $e) { - throw new PluginInstallerException($e->getMessage()); - } - - if (empty($pluginDetails)) { - throw new PluginInstallerException('A plugin with this name does not exist'); - } + $marketplace = new MarketplaceApiClient(); try { $marketplace->download($this->pluginName, $pluginZipTargetFile); } catch (\Exception $e) { - throw new PluginInstallerException('Failed to download plugin: ' . $e->getMessage()); + + try { + $downloadUrl = $marketplace->getDownloadUrl($this->pluginName); + $errorMessage = sprintf('Failed to download plugin from %s: %s', $downloadUrl, $e->getMessage()); + + } catch (\Exception $ex) { + $errorMessage = sprintf('Failed to download plugin: %s', $e->getMessage()); + } + + throw new PluginInstallerException($errorMessage); } } @@ -94,7 +95,7 @@ class PluginInstaller private function makeSurePluginJsonExists($tmpPluginFolder) { if (!file_exists($tmpPluginFolder . DIRECTORY_SEPARATOR . $this->pluginName . DIRECTORY_SEPARATOR . 'plugin.json')) { - throw new PluginInstallerException('Plugin is not valid, missing plugin.json'); + throw new PluginInstallerException('Plugin is not valid, it is missing the plugin.json file.'); } } @@ -112,9 +113,7 @@ class PluginInstaller */ private function removeFolderIfExists($pathExtracted) { - if (file_exists($pathExtracted)) { - Filesystem::unlinkRecursive($pathExtracted, true); - } + Filesystem::unlinkRecursive($pathExtracted, true); } /** @@ -127,4 +126,21 @@ class PluginInstaller } } + /** + * @throws PluginInstallerException + */ + private function makeSurePluginNameIsValid() + { + try { + $marketplace = new MarketplaceApiClient(); + $pluginDetails = $marketplace->getPluginInfo($this->pluginName); + } catch (\Exception $e) { + throw new PluginInstallerException($e->getMessage()); + } + + if (empty($pluginDetails)) { + throw new PluginInstallerException('This plugin was not found in the Marketplace.'); + } + } + } |