<?php declare(strict_types = 1);
namespace Ultra\Wartung;
use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\System\SystemConfig\SystemConfigService;
class UltraWartung extends Plugin {
public function install(InstallContext $context): void
{
$this->addDefaultConfiguration();
$connection = $this->container->get(Connection::class);
$connection->executeUpdate('drop table if EXISTS ultrawartung');
$connection->executeUpdate(
'CREATE TABLE IF NOT EXISTS ultrawartung
(
id int NOT NULL AUTO_INCREMENT,
username VARCHAR(255) NULL,
ipadress VARCHAR(255) NULL,
eingang INT(1) NULL,
verkaufskanal VARCHAR(255) NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
'
);
$this->setSwVersion();
}
public function update(UpdateContext $context): void
{
$connection = $this->container->get(Connection::class);
$connection->executeUpdate('drop table if EXISTS ultrawartung');
$connection->executeUpdate(
'CREATE TABLE IF NOT EXISTS ultrawartung
(
id int NOT NULL AUTO_INCREMENT,
username VARCHAR(255) NULL,
ipadress VARCHAR(255) NULL,
eingang INT(1) NULL,
verkaufskanal VARCHAR(255) NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
'
);
$this->setSwVersion();
}
public function uninstall(UninstallContext $context): void
{
parent::uninstall($context);
$connection = $this->container->get(Connection::class);
$connection->executeUpdate('DROP TABLE IF EXISTS ultrawartung');
if ($context->keepUserData()) {
return;
}
$connection->executeUpdate('delete FROM system_config where configuration_key like "UltraWartung.config%"');
}
private function addDefaultConfiguration():void {
$this->setValue('uwbackgroundcolor', '#FFFFFF');
$this->setValue('uwbackgroundcoloropacity', '100');
$this->setValue('uwbackgroundcolorcontainer', '#FFFFFF');
$this->setValue('uwbackgroundcontaineropacity', '100');
$this->setValue('uwbackgroundcolorpassword', '#000000');
$this->setValue('uwbackgroundcolorpassword', '#000000');
$this->setValue('uwbackgroundcolorcontainertop', 30);
$this->setValue('uwbackbodypicturerepeat', "no-repeat");
$this->setValue('bodyHintergrundbildposition', "center center");
$this->setValue('uwbackbodypicturesize', "cover");
$this->setValue('uwbacklogopictureposition', "center");
$this->setValue('uwbacklogopicturesize', 100);
$this->setValue('uwbacklogopictureheight', 100);
$this->setValue('uwbackoverlaycolor', '#FFFFFF');
$this->setValue('uwbackstarttime', '1000');
$this->setValue('uwbackfadeintime', '1000');
}
public function setValue(string $configName, $default = null):void {
$systemConfigService = $this->container->get(SystemConfigService::class);
$domain = $this->getName() .'.config.';
$systemConfigService->set($domain .$configName, $default);
}
private function setSwVersion() {
$connection = $this->container->get(Connection::class);
$composerJsonPath= explode ('/custom', __FILE__)[0] . '/composer.json';
if (file_exists($composerJsonPath)) {
$composerJson = json_decode(file_get_contents($composerJsonPath), true);
if (isset($composerJson['require']['shopware/core'])) {
$shopwareVersion = $composerJson['require']['shopware/core'];
$shopwareVersion = str_replace('~', '', $shopwareVersion);
$newVersion = explode('.', $shopwareVersion);
$newVersionFinale = $newVersion[0] ."." . $newVersion[1];
$systemConfigService = $this->container->get(SystemConfigService::class);
$domain = $this->getName() . '.config.';
$systemConfigService->set($domain . 'swversion', $newVersionFinale);
}
}
}
}