custom/plugins/UltraWartung/src/UltraWartung.php line 13

Open in your IDE?
  1. <?php declare(strict_types 1);
  2. namespace Ultra\Wartung;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Framework\Plugin;
  5. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  6. use Shopware\Core\Framework\Plugin\Context\UpdateContext
  7. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  8. use Shopware\Core\System\SystemConfig\SystemConfigService;
  9. class UltraWartung extends Plugin {
  10.     
  11.    public function install(InstallContext $context): void
  12.     {
  13.         $this->addDefaultConfiguration();
  14.     
  15.          $connection $this->container->get(Connection::class);
  16.          
  17.          $connection->executeUpdate('drop table if EXISTS ultrawartung');
  18.          
  19.          
  20.         $connection->executeUpdate(
  21.       'CREATE TABLE IF NOT EXISTS ultrawartung
  22.       (
  23.         id int NOT NULL AUTO_INCREMENT,
  24.         username VARCHAR(255) NULL,
  25.         ipadress VARCHAR(255) NULL,
  26.         eingang INT(1) NULL,
  27.         verkaufskanal VARCHAR(255) NULL,
  28.         PRIMARY KEY (id)
  29.       ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;   
  30.       '
  31.     );
  32.     
  33.     $this->setSwVersion();
  34.     
  35.       }
  36.      public function update(UpdateContext $context): void
  37.     {
  38.         $connection $this->container->get(Connection::class);
  39.         
  40.          $connection->executeUpdate('drop table if EXISTS ultrawartung');
  41.          
  42.         $connection->executeUpdate(
  43.       'CREATE TABLE IF NOT EXISTS ultrawartung
  44.       (
  45.         id int NOT NULL AUTO_INCREMENT,
  46.         username VARCHAR(255) NULL,
  47.         ipadress VARCHAR(255) NULL,
  48.         eingang INT(1) NULL,
  49.         verkaufskanal VARCHAR(255) NULL,
  50.         PRIMARY KEY (id)
  51.       ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;   
  52.       '
  53.         );
  54.         
  55.         $this->setSwVersion();
  56.     }
  57.     public function uninstall(UninstallContext $context): void
  58.     {
  59.         parent::uninstall($context);
  60.         
  61.         $connection $this->container->get(Connection::class);
  62.         $connection->executeUpdate('DROP TABLE IF EXISTS ultrawartung');
  63.         
  64.         if ($context->keepUserData()) {
  65.             return;
  66.         }
  67.         $connection->executeUpdate('delete FROM system_config where configuration_key like "UltraWartung.config%"');
  68.     }  
  69.     private function addDefaultConfiguration():void {
  70.         $this->setValue('uwbackgroundcolor''#FFFFFF');
  71.         $this->setValue('uwbackgroundcoloropacity''100');
  72.         $this->setValue('uwbackgroundcolorcontainer''#FFFFFF');
  73.         $this->setValue('uwbackgroundcontaineropacity''100');
  74.         $this->setValue('uwbackgroundcolorpassword''#000000');
  75.         $this->setValue('uwbackgroundcolorpassword''#000000');
  76.         $this->setValue('uwbackgroundcolorcontainertop'30);
  77.         $this->setValue('uwbackbodypicturerepeat'"no-repeat");
  78.         $this->setValue('bodyHintergrundbildposition'"center center");
  79.         $this->setValue('uwbackbodypicturesize'"cover");
  80.         $this->setValue('uwbacklogopictureposition'"center");
  81.         $this->setValue('uwbacklogopicturesize'100);
  82.         $this->setValue('uwbacklogopictureheight'100);
  83.         $this->setValue('uwbackoverlaycolor''#FFFFFF');
  84.         $this->setValue('uwbackstarttime''1000');
  85.         $this->setValue('uwbackfadeintime''1000');
  86.     }
  87.     
  88.      public function setValue(string $configName$default null):void {
  89.         $systemConfigService $this->container->get(SystemConfigService::class);
  90.         $domain $this->getName() .'.config.';
  91.         $systemConfigService->set($domain .$configName$default);
  92.      }
  93.      
  94.      private function setSwVersion() {
  95.         
  96.         $connection $this->container->get(Connection::class);
  97.     
  98.         $composerJsonPathexplode ('/custom'__FILE__)[0] . '/composer.json';
  99.         if (file_exists($composerJsonPath)) {
  100.         
  101.         $composerJson json_decode(file_get_contents($composerJsonPath), true);
  102.         if (isset($composerJson['require']['shopware/core'])) {
  103.             $shopwareVersion $composerJson['require']['shopware/core'];
  104.             $shopwareVersion str_replace('~'''$shopwareVersion);
  105.             $newVersion explode('.'$shopwareVersion);
  106.             $newVersionFinale $newVersion[0] ."." $newVersion[1];
  107.             
  108.             $systemConfigService $this->container->get(SystemConfigService::class);
  109.             $domain $this->getName() . '.config.';
  110.             $systemConfigService->set($domain 'swversion'$newVersionFinale);
  111.             
  112.         } 
  113.         
  114.     }
  115.         
  116.     }
  117. }
  118.