<?php declare(strict_types=1);
namespace Cogi\CogiEtracker;
use Doctrine\DBAL\Connection;
use Exception;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
class CogiEtracker extends Plugin {
const SERVICEWORKER_CONTENT = 'importScripts("https://api.signalize.com/sw.js");';
public function install(InstallContext $context): void {
// install signalise service worker file
file_put_contents('sw.js', self::SERVICEWORKER_CONTENT, FILE_APPEND);
}
public function uninstall(UninstallContext $context): void
{
if ($context->keepUserData()) {
parent::uninstall($context);
return;
}
// delete service worker if its only signalise content
$filecontent = file_get_contents('sw.js');
if($filecontent === self::SERVICEWORKER_CONTENT)
unlink('sw.js');
$connection = $this->container->get(Connection::class);
$connection->executeStatement('DELETE FROM `system_config` WHERE `configuration_key` LIKE :name;', ['name' => '%CogiEtracker.config%']);
}
}