Skip to content

Commit

Permalink
FIX composer bundled sdk conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Höchtl committed Oct 2, 2020
1 parent 7e0e511 commit d1db2f0
Show file tree
Hide file tree
Showing 3 changed files with 390 additions and 310 deletions.
12 changes: 12 additions & 0 deletions Subscriber/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Enlight\Event\SubscriberInterface;
use Enlight_Event_EventArgs;
use OdSentry\OdSentry;
use PackageVersions\Versions;
use Sentry\SentrySdk;
use Sentry\State\Scope;
use Shopware\Components\DependencyInjection\Container;
Expand Down Expand Up @@ -43,6 +44,17 @@ class ErrorHandler implements SubscriberInterface
public function __construct(ContainerInterface $container)
{
$this->pluginDirectory = $container->getParameter('od_sentry.plugin_dir');
// Hot fix the ClientBuilder of the sentry sdk if the SDK is not installed via composer but bundled in the plugin
if (class_exists('\PackageVersions\Versions') && !isset(Versions::VERSIONS['sentry/sdk']) && is_dir($this->pluginDirectory . '/vendor')) {
$composerLock = json_decode(file_get_contents($this->pluginDirectory . '/composer.lock'), true);
$sentryPackage = current(array_filter($composerLock['packages'], function(array $package) {
return $package['name'] === 'sentry/sdk';
}));
$sentryVersion = $sentryPackage['version'];
$clientBuilder = file_get_contents($this->pluginDirectory . '/vendor/sentry/sentry/src/ClientBuilder.php');
$clientBuilder = str_replace('PrettyVersions::getVersion(\'sentry/sentry\')->getPrettyVersion()', "'" . $sentryVersion . "'", $clientBuilder);
file_put_contents($this->pluginDirectory . '/vendor/sentry/sentry/src/ClientBuilder.php', $clientBuilder, LOCK_EX);
}
// Use composer autoloader if dependencies are bundles within the plugin (non-composer mode)
if (file_exists($this->pluginDirectory . '/vendor/autoload.php')) {
require_once $this->pluginDirectory . '/vendor/autoload.php';
Expand Down
Loading

0 comments on commit d1db2f0

Please sign in to comment.