fix(webservice): No more doctrine in install
This commit is contained in:
@@ -1,82 +0,0 @@
|
|||||||
<?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 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,7 +11,7 @@ trait Install
|
|||||||
if (!parent::install()) {
|
if (!parent::install()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!$this->installTables()){
|
if (!$this->createTables()){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!$this->registerHooks()){
|
if (!$this->registerHooks()){
|
||||||
@@ -21,6 +21,19 @@ trait Install
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function createTables(): bool
|
||||||
|
{
|
||||||
|
$sql = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'ws_order_reference` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`id_cart` int(11) NOT NULL,
|
||||||
|
`order_reference` varchar(255) NOT NULL,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE KEY `id_cart` (`id_cart`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;';
|
||||||
|
|
||||||
|
return \Db::getInstance()->execute($sql);
|
||||||
|
}
|
||||||
|
|
||||||
public function registerHooks(){
|
public function registerHooks(){
|
||||||
return $this->registerHook('displayShoppingCart')
|
return $this->registerHook('displayShoppingCart')
|
||||||
&& $this->registerHook('displayPDFDeliverySlip')
|
&& $this->registerHook('displayPDFDeliverySlip')
|
||||||
@@ -28,31 +41,4 @@ trait Install
|
|||||||
&& $this->registerHook('actionFrontControllerSetMedia');
|
&& $this->registerHook('actionFrontControllerSetMedia');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getInstaller(): ReferenceInstaller
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$installer = $this->get(ReferenceInstaller::class);
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
$installer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$installer) {
|
|
||||||
$installer = new ReferenceInstaller(
|
|
||||||
$this->get('doctrine.dbal.default_connection'),
|
|
||||||
$this->getContainer()->getParameter('database_prefix')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $installer;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function installTables(): bool
|
|
||||||
{
|
|
||||||
/** @var ReferenceInstaller $installer */
|
|
||||||
$installer = $this->getInstaller();
|
|
||||||
$errors = $installer->createTables();
|
|
||||||
|
|
||||||
return empty($errors);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
CREATE TABLE IF NOT EXISTS `PREFIX_order_reference` (
|
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`id_cart` int(11) NOT NULL,
|
|
||||||
`order_reference` varchar(255) NOT NULL,
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
UNIQUE KEY `id_cart` (`id_cart`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
||||||
Reference in New Issue
Block a user