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

download() public method

public download ( $pluginOrThemeName )
    public function download($pluginOrThemeName)
    {
        @ignore_user_abort(true);
        SettingsServer::setMaxExecutionTime(0);
        $downloadUrl = $this->getDownloadUrl($pluginOrThemeName);
        if (empty($downloadUrl)) {
            return false;
        }
        // in the beginning we allowed to specify a download path but this way we make sure security is always taken
        // care of and we always generate a random download filename.
        $target = $this->getRandomTmpPluginDownloadFilename();
        Filesystem::deleteFileIfExists($target);
        $success = $this->service->download($downloadUrl, $target, static::HTTP_REQUEST_TIMEOUT);
        if ($success) {
            return $target;
        }
        return false;
    }

Usage Example

Example #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);
     }
 }
All Usage Examples Of Piwik\Plugins\Marketplace\Api\Client::download