Load DB helper for edge gateway schema bootstrap
This commit is contained in:
@@ -18,7 +18,7 @@ class edge_gateway_schema_bootstrap
|
||||
return;
|
||||
}
|
||||
|
||||
$pdo = \db::getPDO();
|
||||
$pdo = self::pdo();
|
||||
$queries = [
|
||||
"CREATE TABLE IF NOT EXISTS edge_gateways (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
@@ -343,7 +343,7 @@ class edge_gateway_schema_bootstrap
|
||||
throw new \RuntimeException('Invalid schema bootstrap identifier');
|
||||
}
|
||||
|
||||
\db::getPDO()->exec(
|
||||
self::pdo()->exec(
|
||||
"ALTER TABLE `$table`
|
||||
ADD COLUMN `$column` $definition"
|
||||
);
|
||||
@@ -369,7 +369,7 @@ class edge_gateway_schema_bootstrap
|
||||
|
||||
$positionClause = $afterColumn === null ? '' : " AFTER `$afterColumn`";
|
||||
|
||||
\db::getPDO()->exec(
|
||||
self::pdo()->exec(
|
||||
"ALTER TABLE `$table`
|
||||
CHANGE COLUMN `$from` `$to` $definition$positionClause"
|
||||
);
|
||||
@@ -381,7 +381,7 @@ class edge_gateway_schema_bootstrap
|
||||
throw new \RuntimeException('Invalid schema bootstrap identifier');
|
||||
}
|
||||
|
||||
$statement = \db::getPDO()->prepare(
|
||||
$statement = self::pdo()->prepare(
|
||||
"SELECT COUNT(*) AS c
|
||||
FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
@@ -404,7 +404,7 @@ class edge_gateway_schema_bootstrap
|
||||
return;
|
||||
}
|
||||
|
||||
$pdo = \db::getPDO();
|
||||
$pdo = self::pdo();
|
||||
$pdo->exec(
|
||||
"UPDATE edge_gateway_operations
|
||||
SET type = operation_type
|
||||
@@ -421,4 +421,20 @@ class edge_gateway_schema_bootstrap
|
||||
AND (operation_type IS NULL OR operation_type = '')"
|
||||
);
|
||||
}
|
||||
|
||||
private static function pdo(): \PDO
|
||||
{
|
||||
if (!class_exists('db', false)) {
|
||||
$dbClassPath = __DIR__ . '/../../../classes/db.php';
|
||||
if (is_file($dbClassPath)) {
|
||||
require_once $dbClassPath;
|
||||
}
|
||||
}
|
||||
|
||||
if (!class_exists('db')) {
|
||||
throw new \RuntimeException('Database connection helper is not available.');
|
||||
}
|
||||
|
||||
return \db::getPDO();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user