This commit is contained in:
2026-02-08 21:43:11 +01:00
parent 45b32a5ee2
commit 58947ad589
33 changed files with 3262 additions and 1597 deletions

View File

@@ -0,0 +1,34 @@
<?php
namespace Empik\Marketplace\Utils;
class DbUtils
{
public static function safeAddColumn($table, $column, $def)
{
if (!self::columnExists($table, $column))
return \Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . $table . '` ADD `' . $column . '` ' . $def);
return true;
}
public static function columnExists($table, $column)
{
$query = 'SELECT COUNT(*)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND COLUMN_NAME = \'' . pSQL($column) . '\'
AND TABLE_NAME = \'' . _DB_PREFIX_ . pSQL($table) . '\'';
return (bool)\Db::getInstance()->getValue($query);
}
public static function safeDropColumn($table, $column)
{
if (self::columnExists($table, $column)) {
\Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . $table . '` DROP `' . $column . '` ');
}
return true;
}
}