Commit 0c0ac67e authored by Sascha Brüggenolte's avatar Sascha Brüggenolte
Browse files

Merge branch '2.1' into 3.1

parents 9a21f60f cf5641b5
......@@ -7,19 +7,70 @@
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
{
public const MINIMUM_SDK_VERSION = '2.0.0';
public 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
......@@ -5,11 +5,18 @@
<label lang="de">Google SDK</label>
<label lang="en">Google SDK</label>
<version>3.0.0</version>
<version>3.1.0</version>
<link>http://www.netinventors.de</link>
<author>Net Inventors GmbH</author>
<changelog version="3.1.0">
<changes lang="de"><![CDATA[
[#33222] SDK wird nun gedownloaded</changes>
]]><changes lang="en"><![CDATA[
[#33222] SDK will now be downloaded</changes>
]]></changelog>
<compatibility minVersion="5.6.0" />
<changelog version="3.0.0">
......
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