Piwik\Plugins\Marketplace\Api\Client::getDownloadUrl PHP Method

getDownloadUrl() public method

public getDownloadUrl ( $pluginOrThemeName ) : string
$pluginOrThemeName
return string
    public function getDownloadUrl($pluginOrThemeName)
    {
        $plugin = $this->getPluginInfo($pluginOrThemeName);
        if (empty($plugin['versions'])) {
            throw new Exception('Plugin has no versions.');
        }
        $latestVersion = array_pop($plugin['versions']);
        $downloadUrl = $latestVersion['download'];
        return $this->service->getDomain() . $downloadUrl . '?coreVersion=' . $this->environment->getPiwikVersion();
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * @return false|string   false on failed download, or a path to the downloaded zip file
  * @throws PluginInstallerException
  */
 private function downloadPluginFromMarketplace()
 {
     try {
         return $this->marketplaceClient->download($this->pluginName);
     } catch (\Exception $e) {
         try {
             $downloadUrl = $this->marketplaceClient->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);
     }
 }