* @copyright 2026 De Websmid * @license De Websmid * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License 3.0 (AFL-3.0). * It is also available through the world-wide-web at this URL: https://opensource.org/licenses/AFL-3.0 */ declare(strict_types=1); namespace Websmid\WsOrderReference\Database; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Exception as DBALException; class ReferenceInstaller { private Connection $connection; private string $dbPrefix; public function __construct(Connection $connection, string $dbPrefix) { $this->connection = $connection; $this->dbPrefix = $dbPrefix; } public function createTables(): array { $errors = []; $this->dropTables(); $sqlInstallFile = dirname(__DIR__) . '/Resources/data/install.sql'; $sqlContent = file_get_contents($sqlInstallFile); $sqlContent = str_replace('PREFIX_', $this->dbPrefix, $sqlContent); $sqlQueries = array_filter(array_map('trim', explode(';', $sqlContent))); foreach ($sqlQueries as $query) { if (empty($query)) { continue; } try { $this->connection->executeQuery($query); } catch (DBALException $e) { $errors[] = [ 'key' => $e->getMessage(), 'parameters' => [], 'domain' => 'Admin.Modules.Notification', ]; } } return $errors; } public function dropTables(): array { $errors = []; $tableNames = [ 'ws_orderreference', ]; foreach ($tableNames as $tableName) { $sql = 'DROP TABLE IF EXISTS ' . $this->dbPrefix . $tableName; try { $this->connection->executeQuery($sql); } catch (DBALException $e) { $errors[] = [ 'key' => $e->getMessage(), 'parameters' => [], 'domain' => 'Admin.Modules.Notification', ]; } } return $errors; } }