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>2013-09-19 02:07:38 +0400
committerThomas Steur <thomas.steur@gmail.com>2013-09-19 02:07:38 +0400
commitea2ae320e98a04ba94ae91cd5efd80abfdb12d96 (patch)
tree48cce6edddd8f12f252de263ec5bd81935c441f0
parent7761b37afdbfa096be6f360877057541ab44da6d (diff)
display errors during installing plugin, improved display of themes
-rw-r--r--plugins/CorePluginsAdmin/Controller.php27
-rw-r--r--plugins/CorePluginsAdmin/PluginInstaller.php26
-rw-r--r--plugins/CorePluginsAdmin/PluginInstallerException.php20
-rw-r--r--plugins/CorePluginsAdmin/templates/installPlugin.twig24
4 files changed, 73 insertions, 24 deletions
diff --git a/plugins/CorePluginsAdmin/Controller.php b/plugins/CorePluginsAdmin/Controller.php
index 1937f08018..95f9b73706 100644
--- a/plugins/CorePluginsAdmin/Controller.php
+++ b/plugins/CorePluginsAdmin/Controller.php
@@ -49,6 +49,7 @@ class Controller extends \Piwik\Controller\Admin
Nonce::discardNonce('CorePluginsAdmin.activatePlugin');
PluginsManager::getInstance()->activatePlugin($pluginName);
+ // TODO perform redirect otherwise page reload won't work afterwards
$this->extend();
}
@@ -80,24 +81,36 @@ class Controller extends \Piwik\Controller\Admin
public function installPlugin()
{
+ $view = $this->configureView('@CorePluginsAdmin/installPlugin');
+
$pluginName = Common::getRequestVar('pluginName', '', 'string');
$nonce = Common::getRequestVar('nonce', '', 'string');
if (empty($pluginName)) {
- return;
+ throw new \Exception('Plugin parameter is missing');
}
+ $view->plugin = array('name' => $pluginName);
+
if (!Nonce::verifyNonce('CorePluginsAdmin.installPlugin', $nonce)) {
- // todo display error
+ $view->errorMessage = Piwik_Translate('ExceptionNonceMismatch');
+ echo $view->render();
return;
}
Nonce::discardNonce('CorePluginsAdmin.installPlugin');
- $pluginInstaller = new PluginInstaller($pluginName);
- $pluginInstaller->installOrUpdatePluginFromMarketplace();
- $marketplace = new MarketplaceApiClient();
- $view = $this->configureView('@CorePluginsAdmin/installPlugin');
+ try {
+ $pluginInstaller = new PluginInstaller($pluginName);
+ $pluginInstaller->installOrUpdatePluginFromMarketplace();
+
+ } catch (PluginInstallerException $e) {
+ $view->errorMessage = $e->getMessage();
+ echo $view->render();
+ return;
+ }
+
+ $marketplace = new MarketplaceApiClient();
$view->plugin = $marketplace->getPluginInfo($pluginName);
$view->nonce = Nonce::getNonce('CorePluginsAdmin.activatePlugin');
@@ -170,7 +183,7 @@ class Controller extends \Piwik\Controller\Admin
$plugin->isInstalled = !empty($loadedPlugins[$plugin->name]);
$plugin->createdDateTime = Date::factory($plugin->createdDateTime)->getLocalized(Piwik_Translate('CoreHome_ShortDateFormatWithYear'));
}
-
+
$view->plugins = $plugins;
$view->query = $query;
diff --git a/plugins/CorePluginsAdmin/PluginInstaller.php b/plugins/CorePluginsAdmin/PluginInstaller.php
index 192264feca..e77b79757d 100644
--- a/plugins/CorePluginsAdmin/PluginInstaller.php
+++ b/plugins/CorePluginsAdmin/PluginInstaller.php
@@ -53,11 +53,21 @@ class PluginInstaller
{
$this->removeFileIfExists($pluginZipTargetFile);
- $marketplace = new MarketplaceApiClient();
- $success = $marketplace->download($this->pluginName, $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');
+ }
- if (!$success) {
- throw new \Exception('Failed to download plugin');
+ try {
+ $marketplace->download($this->pluginName, $pluginZipTargetFile);
+ } catch (\Exception $e) {
+ throw new PluginInstallerException('Failed to download plugin: ' . $e->getMessage());
}
}
@@ -73,18 +83,18 @@ class PluginInstaller
$this->removeFolderIfExists($pathExtracted);
if (0 == ($pluginFiles = $archive->extract($pathExtracted))) {
- throw new \Exception(Piwik_TranslateException('Plugin_ExceptionArchiveIncompatible', $archive->errorInfo()));
+ throw new PluginInstallerException(Piwik_TranslateException('Plugin_ExceptionArchiveIncompatible', $archive->errorInfo()));
}
if (0 == count($pluginFiles)) {
- throw new \Exception(Piwik_TranslateException('Plugin Zip File Is Empty'));
+ throw new PluginInstallerException(Piwik_TranslateException('Plugin Zip File Is Empty'));
}
}
private function makeSurePluginJsonExists($tmpPluginFolder)
{
- if (!file_exists($tmpPluginFolder . '/' . $this->pluginName . '/plugin.json')) {
- throw new \Exception('It is not a valid Plugin, missing plugin.json');
+ if (!file_exists($tmpPluginFolder . DIRECTORY_SEPARATOR . $this->pluginName . DIRECTORY_SEPARATOR . 'plugin.json')) {
+ throw new PluginInstallerException('Plugin is not valid, missing plugin.json');
}
}
diff --git a/plugins/CorePluginsAdmin/PluginInstallerException.php b/plugins/CorePluginsAdmin/PluginInstallerException.php
new file mode 100644
index 0000000000..87d3ea27af
--- /dev/null
+++ b/plugins/CorePluginsAdmin/PluginInstallerException.php
@@ -0,0 +1,20 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ * @category Piwik_Plugins
+ * @package CorePluginsAdmin
+ */
+namespace Piwik\Plugins\CorePluginsAdmin;
+
+/**
+ * PluginInstallerException
+ * @package CorePluginsAdmin
+ */
+class PluginInstallerException extends \Exception
+{
+
+}
diff --git a/plugins/CorePluginsAdmin/templates/installPlugin.twig b/plugins/CorePluginsAdmin/templates/installPlugin.twig
index eddfe8dab1..554b667716 100644
--- a/plugins/CorePluginsAdmin/templates/installPlugin.twig
+++ b/plugins/CorePluginsAdmin/templates/installPlugin.twig
@@ -6,19 +6,25 @@
<h2>Installing plugin {{ plugin.name}}</h2>
- <div>
- <p>Downloading plugin from Marketplace</p>
+ {% if errorMessage %}
+ <div class="ajaxError" style="">{{ errorMessage }}</div>
+ {% else %}
- <p>Unzipping plugin</p>
+ <div>
+ <p>Downloading plugin from Marketplace</p>
- <p>Installing plugin</p>
+ <p>Unzipping plugin</p>
- <p>You have successfully installed the Plugin {{ plugin.name }} {{ plugin.latestVersion }}.</p>
+ <p>Installing plugin</p>
- <p><strong><a href="{{ linkTo({'action': 'activatePlugin', 'pluginName': plugin.name, 'nonce': nonce}) }}">Activate Plugin</a></strong>
- |
- <a href="{{ linkTo({'action': 'extend'}) }}">Back to Extend Piwik</a></p>
- </div>
+ <p>You have successfully installed the Plugin {{ plugin.name }} {{ plugin.latestVersion }}.</p>
+
+ <p><strong><a href="{{ linkTo({'action': 'activatePlugin', 'pluginName': plugin.name, 'nonce': nonce}) }}">Activate Plugin</a></strong>
+ |
+ <a href="{{ linkTo({'action': 'extend'}) }}">Back to Extend Piwik</a></p>
+ </div>
+
+ {% endif %}
</div>
{% endblock %}