custom/static-plugins/integration-business-central/src/IntegrationBusinessCentral.php line 13

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Wexo\Integration\BusinessCentral;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Framework\Plugin;
  5. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  6. /**
  7.  * Class IntegrationBusinessCentral
  8.  * @package Wexo\Integration\BusinessCentral
  9.  */
  10. class IntegrationBusinessCentral extends Plugin
  11. {
  12.     /**
  13.      * @param InstallContext $installContext
  14.      */
  15.     public function install(InstallContext $installContext): void
  16.     {
  17.         $connection $this->container->get(Connection::class);
  18.         if (! $connection) {
  19.             return;
  20.         }
  21.         // TODO:
  22.         try {
  23.             $connection->executeStatement(<<<SQL
  24.                 CREATE TABLE IF NOT EXISTS `wexo_integration_business_central` (
  25.                 `id` BINARY(16) NOT NULL,
  26.                 `active` TINYINT(1) NOT NULL,
  27.                 `message_queue` TINYINT(1) NULL,
  28.                 `name` VARCHAR(100) NOT NULL,
  29.                 `profile` VARCHAR(100) NOT NULL,
  30.                 `service_id` VARCHAR(100) NOT NULL,
  31.                 `url` VARCHAR(255) NOT NULL,
  32.                 `username` VARCHAR(50) NOT NULL,
  33.                 `password` VARCHAR(255) NULL,
  34.                 `method` VARCHAR(50) NULL,
  35.                 `company` VARCHAR(255) NULL,
  36.                 `endpoint` VARCHAR(50) NULL,
  37.                 `created_at` DATETIME(3) NOT NULL,
  38.                 `updated_at` DATETIME(3) NULL,
  39.                 PRIMARY KEY (`id`)
  40.                 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  41.             SQL);
  42.         } catch (\Exception $e) {
  43.             // do nothing
  44.         }
  45.         try {
  46.             $connection->executeStatement(<<<SQL
  47.                 CREATE TABLE IF NOT EXISTS `wexo_integration_business_central_sales_channel` (
  48.                 `id` BINARY(16) NOT NULL,
  49.                 `business_central_id` BINARY(16) NOT NULL,
  50.                 `sales_channel_id` BINARY(16) NOT NULL,
  51.                 `created_at` DATETIME(3) NOT NULL,
  52.                 `updated_at` DATETIME(3) NULL,
  53.                 PRIMARY KEY (`id`),
  54.                 CONSTRAINT `fk.business_central_sales_channel.business_central_id` FOREIGN KEY (`business_central_id`)
  55.                 REFERENCES `wexo_integration_business_central` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  56.                 CONSTRAINT `fk.business_central_sales_channel.sales_channel_id` FOREIGN KEY (`sales_channel_id`)
  57.                 REFERENCES `sales_channel` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
  58.                 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  59.             SQL);
  60.         } catch (\Exception $e) {
  61.             // do nothing
  62.         }
  63.         try {
  64.             $connection->executeStatement(<<<SQL
  65.                 CREATE TABLE IF NOT EXISTS `wexo_integration_business_central_order` (
  66.                 `order_id` BINARY(16) NOT NULL,
  67.                 `order_version_id` BINARY(16) NOT NULL,
  68.                 `exported` TINYINT(1) NULL DEFAULT '0',
  69.                 `error_message` TEXT NULL,
  70.                 `created_at` DATETIME(3) NOT NULL,
  71.                 `updated_at` DATETIME(3) NULL,
  72.                 CONSTRAINT `fk.wexo_integration_business_central_order.order_id__version_id`
  73.                 FOREIGN KEY (`order_id`, `order_version_id`) REFERENCES `order` (id, version_id)
  74.                 ON UPDATE CASCADE ON DELETE CASCADE,
  75.                 PRIMARY KEY (`order_id`, `order_version_id`)
  76.                 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  77.             SQL);
  78.         } catch (\Exception $e) {
  79.             //do nothing
  80.         }
  81.         try {
  82.             $connection->executeStatement(<<<SQL
  83.                 CREATE TABLE IF NOT EXISTS `wexo_integration_business_central_profile` (
  84.                     `id` BINARY(16) NOT NULL,
  85.                     `business_central_id` BINARY(16) NOT NULL,
  86.                     `profile_id` BINARY(16) NOT NULL,
  87.                     `created_at` DATETIME(3) NOT NULL,
  88.                     `updated_at` DATETIME(3) NULL,
  89.                     PRIMARY KEY (`id`)
  90.                 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  91.             SQL);
  92.         } catch (\Exception $e) {
  93.             //do nothing
  94.         }
  95.     }
  96. }