Init project

Future fixes:
-Remove logic for showing current order reference in ajax.js. Instead grab from database using cart ID
This commit is contained in:
2026-02-09 10:08:02 +01:00
committed by Isabelle
parent 65e21d48c3
commit e5fe85c8e5
21 changed files with 702 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
<?php
/**
* 2026 De Websmid
*
* @author De Websmid <contact@De Websmid.com>
* @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 Module\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;
}
}