Commit 1683f75a authored by Sascha Brüggenolte's avatar Sascha Brüggenolte
Browse files

Merge branch '33509' into '1.0'

33509-Add SDK Download

See merge request shopware/labs/NetiGoogleSdk!3
parents 0ee95825 53091bba
......@@ -7,19 +7,71 @@
namespace NetiGoogleSdk;
use GuzzleHttp\Client;
use NetiGoogleSdk\Exceptions\GoogleSdkFactoryException;
use Shopware\Components\Plugin;
use Shopware\Components\Plugin\Context\InstallContext;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use ZipArchive;
class NetiGoogleSdk extends Plugin
{
const MINIMUM_SDK_VERSION = "2.0.0";
const BREAKING_SDK_VERSION = "2.1.0";
const SDK_REPO = 'https://api.github.com/repos/googleapis/google-api-php-client/releases/tags/v2.0.3'; //newest supported version
/**
* @param InstallContext $context
*
* @throws GoogleSdkFactoryException
*/
public function install(InstallContext $context)
{
$client = new Client([
'base_url' => self::SDK_REPO,
'timeout' => 5.0,
]);
//Sends a request to the Github API for repo information
$response = $client->get('', ['verify' => true]);
//Gets proper Link for Download(We do it this way in case the download link changes), afterwards opens two streams for the download and archive
$content = $response->json();
$downloadUrl = $content['assets'][0]['browser_download_url'];
$handle = fopen($downloadUrl, 'r');
$archiveDir = $this->getPath() . '/temp/google.zip';
$archive = fopen($archiveDir, 'w+');
if (!$handle || !$archive) {
throw new GoogleSdkFactoryException('There was an error when trying to download the SDK');
} else {
while (!feof($handle)) {
$file = fgets($handle, 128);
fwrite($archive, $file);
}
fclose($handle);
fclose($archive);
$zip = new ZipArchive();
$result = $zip->open($archiveDir);
if (true === $result) {
$zip->extractTo($this->getPath() . '/vendor/');
$zip->close();
unlink($archiveDir);
} else {
throw new GoogleSdkFactoryException('There was an error when trying to extract the SDK');
}
}
}
public function build(ContainerBuilder $container)
{
$container->setParameter('neti_google_sdk.vendor_dir', $this->getPath() . '/vendor');
$container->setParameter('neti_google_sdk.vendor_dir', $this->getPath() . '/vendor/google-api-php-client-2.0.3/vendor');
parent::build($container);
}
}
\ No newline at end of file
......@@ -2,12 +2,6 @@
"name": "netinventors/google-sdk",
"description": "Wrapper plugin for Google API Client PHP Library",
"type": "project",
"require": {
"google/apiclient": "^2.0"
},
"require-dev": {
"shopware/shopware": "^5.2.6"
},
"config": {
"prepend-autoloader": false
},
......
......@@ -5,10 +5,15 @@
<label lang="de">Google SDK</label>
<label lang="en">Google SDK</label>
<version>1.0.0</version>
<version>1.1.0</version>
<link>http://www.netinventors.de</link>
<author>Net Inventors GmbH</author>
<compatibility minVersion="5.2.6"/>
<compatibility minVersion="5.4.0"/>
<changelog version="1.1.0">
<changes lang="de">SDK wird nun gedownloaded</changes>
<changes lang="en">SDK will now be downloaded</changes>
</changelog>
<changelog version="1.0.0">
<changes lang="de">Erstes Release</changes>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment