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 <tsteur@users.noreply.github.com>2016-11-15 04:03:59 +0300
committerMatthieu Aubry <mattab@users.noreply.github.com>2016-11-15 04:03:59 +0300
commit587cc39e0362719332d410b7a4d5ddcc68788eeb (patch)
treec982c369cdda542c3a4de08be11c893e5364838c /plugins/Marketplace/API.php
parent64314b26dbc6619d535002bdb79b9e55d1fc87db (diff)
Update Marketplace to work with new API (#10799)
* starting to port marketplace to piwik 3 * updating tests * fix translation key * fix various issues * use material select * fix plugin upload * deprecate license_homepage plugin metadata and link to a LICENSE[.md|.txt] file if found (#10756) * deprecate license_homepage plugin metadata, and link to a LICENSE[.md|.txt] file if found * Make license view HTML only without menu * fix tests and update * fix some links did not work * we need to show warnings even when plugin is installed, not only when activated. otherwise it is not clear why something is not downloadable * fix install was not working * improved responsiveness of marketplace * fix more tests * fix search was shown when only a few plugins are there * fix ui tests * fix some translations * fix tests and remove duplicated test
Diffstat (limited to 'plugins/Marketplace/API.php')
-rw-r--r--plugins/Marketplace/API.php106
1 files changed, 106 insertions, 0 deletions
diff --git a/plugins/Marketplace/API.php b/plugins/Marketplace/API.php
new file mode 100644
index 0000000000..0ebdaec905
--- /dev/null
+++ b/plugins/Marketplace/API.php
@@ -0,0 +1,106 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+
+namespace Piwik\Plugins\Marketplace;
+
+use Exception;
+use Piwik\Piwik;
+use Piwik\Plugins\Marketplace\Api\Client;
+use Piwik\Plugins\Marketplace\Api\Service;
+use Piwik\Plugins\Marketplace\Plugins\InvalidLicenses;
+
+/**
+ * The Marketplace API lets you manage your license key so you can download & install in one-click <a target="_blank" rel="noreferrer" href="https://plugins.piwik.org/premium">paid premium plugins</a> you have subscribed to.
+ *
+ * @method static \Piwik\Plugins\Marketplace\API getInstance()
+ */
+class API extends \Piwik\Plugin\API
+{
+ /**
+ * @var Client
+ */
+ private $marketplaceClient;
+
+ /**
+ * @var Service
+ */
+ private $marketplaceService;
+
+ /**
+ * @var InvalidLicenses
+ */
+ private $expired;
+
+ public function __construct(Service $service, Client $client, InvalidLicenses $expired)
+ {
+ $this->marketplaceService = $service;
+ $this->marketplaceClient = $client;
+ $this->expired = $expired;
+ }
+
+ /**
+ * Deletes an existing license key if one is set.
+ *
+ * @return bool
+ */
+ public function deleteLicenseKey()
+ {
+ Piwik::checkUserHasSuperUserAccess();
+
+ $this->setLicenseKey(null);
+ return true;
+ }
+
+ /**
+ * Saves the given license key in case the key is actually valid (exists on the Piwik Marketplace and is not
+ * yet expired).
+ *
+ * @param string $licenseKey
+ * @return bool
+ *
+ * @throws Exception In case of an invalid license key
+ * @throws Service\Exception In case of any network problems
+ */
+ public function saveLicenseKey($licenseKey)
+ {
+ Piwik::checkUserHasSuperUserAccess();
+
+ $licenseKey = trim($licenseKey);
+
+ // we are currently using the Marketplace service directly to 1) change LicenseKey and 2) not use any cache
+ $this->marketplaceService->authenticate($licenseKey);
+
+ try {
+ $consumer = $this->marketplaceService->fetch('consumer/validate', array());
+ } catch (Api\Service\Exception $e) {
+ if ($e->getCode() === Api\Service\Exception::HTTP_ERROR) {
+ throw $e;
+ }
+
+ $consumer = array();
+ }
+
+ if (empty($consumer['isValid'])) {
+ throw new Exception(Piwik::translate('Marketplace_ExceptionLinceseKeyIsNotValid'));
+ }
+
+ $this->setLicenseKey($licenseKey);
+
+ return true;
+ }
+
+ private function setLicenseKey($licenseKey)
+ {
+ $key = new LicenseKey();
+ $key->set($licenseKey);
+
+ $this->marketplaceClient->clearAllCacheEntries();
+ $this->expired->clearCache();
+ }
+
+}