<?php declare(strict_types=1);
namespace Wexo\Integration\BusinessCentral;
use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
/**
* Class IntegrationBusinessCentral
* @package Wexo\Integration\BusinessCentral
*/
class IntegrationBusinessCentral extends Plugin
{
/**
* @param InstallContext $installContext
*/
public function install(InstallContext $installContext): void
{
$connection = $this->container->get(Connection::class);
if (! $connection) {
return;
}
// TODO:
try {
$connection->executeStatement(<<<SQL
CREATE TABLE IF NOT EXISTS `wexo_integration_business_central` (
`id` BINARY(16) NOT NULL,
`active` TINYINT(1) NOT NULL,
`message_queue` TINYINT(1) NULL,
`name` VARCHAR(100) NOT NULL,
`profile` VARCHAR(100) NOT NULL,
`service_id` VARCHAR(100) NOT NULL,
`url` VARCHAR(255) NOT NULL,
`username` VARCHAR(50) NOT NULL,
`password` VARCHAR(255) NULL,
`method` VARCHAR(50) NULL,
`company` VARCHAR(255) NULL,
`endpoint` VARCHAR(50) NULL,
`created_at` DATETIME(3) NOT NULL,
`updated_at` DATETIME(3) NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
SQL);
} catch (\Exception $e) {
// do nothing
}
try {
$connection->executeStatement(<<<SQL
CREATE TABLE IF NOT EXISTS `wexo_integration_business_central_sales_channel` (
`id` BINARY(16) NOT NULL,
`business_central_id` BINARY(16) NOT NULL,
`sales_channel_id` BINARY(16) NOT NULL,
`created_at` DATETIME(3) NOT NULL,
`updated_at` DATETIME(3) NULL,
PRIMARY KEY (`id`),
CONSTRAINT `fk.business_central_sales_channel.business_central_id` FOREIGN KEY (`business_central_id`)
REFERENCES `wexo_integration_business_central` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk.business_central_sales_channel.sales_channel_id` FOREIGN KEY (`sales_channel_id`)
REFERENCES `sales_channel` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
SQL);
} catch (\Exception $e) {
// do nothing
}
try {
$connection->executeStatement(<<<SQL
CREATE TABLE IF NOT EXISTS `wexo_integration_business_central_order` (
`order_id` BINARY(16) NOT NULL,
`order_version_id` BINARY(16) NOT NULL,
`exported` TINYINT(1) NULL DEFAULT '0',
`error_message` TEXT NULL,
`created_at` DATETIME(3) NOT NULL,
`updated_at` DATETIME(3) NULL,
CONSTRAINT `fk.wexo_integration_business_central_order.order_id__version_id`
FOREIGN KEY (`order_id`, `order_version_id`) REFERENCES `order` (id, version_id)
ON UPDATE CASCADE ON DELETE CASCADE,
PRIMARY KEY (`order_id`, `order_version_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
SQL);
} catch (\Exception $e) {
//do nothing
}
try {
$connection->executeStatement(<<<SQL
CREATE TABLE IF NOT EXISTS `wexo_integration_business_central_profile` (
`id` BINARY(16) NOT NULL,
`business_central_id` BINARY(16) NOT NULL,
`profile_id` BINARY(16) NOT NULL,
`created_at` DATETIME(3) NOT NULL,
`updated_at` DATETIME(3) NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
SQL);
} catch (\Exception $e) {
//do nothing
}
}
}