replaced PDO with DatabaseConnection

Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
tracer 2022-01-22 18:25:18 +01:00
parent 657eeb0496
commit 53e942f077
1 changed files with 18 additions and 17 deletions

View File

@ -15,7 +15,7 @@ class DomainController
private String $namedConfLocalFile;
private string $zoneCachePath;
public function __construct(private PDO $dbConnection)
public function __construct(private DatabaseConnection $databaseConnection)
{
$this->localZoneFile = '/etc/bind/local.zones';
$this->localZonesDir = '/etc/bind/zones/';
@ -31,10 +31,10 @@ class DomainController
{
$statement = "
SELECT id, name, a, aaaa
FROM domains";
FROM " . DatabaseConnection::TABLE_DOMAINS;
try {
$statement = $this->dbConnection->query($statement);
$statement = $this->databaseConnection->getConnection()->query($statement);
return $statement->fetchAll(mode: PDO::FETCH_ASSOC);
} catch (PDOException $e) {
exit($e->getMessage());
@ -51,11 +51,11 @@ class DomainController
{
$sql = "
SELECT id, name, a, aaaa
FROM domains
FROM " . DatabaseConnection::TABLE_DOMAINS . "
WHERE name = :name";
try {
$statement = $this->dbConnection->prepare($sql);
$statement = $this->databaseConnection->getConnection()->prepare($sql);
$statement->bindParam(param: ':name', var: $name);
$statement->execute();
return $statement->fetch(PDO::FETCH_ASSOC);
@ -74,11 +74,11 @@ class DomainController
{
$sql = "
SELECT id, name, a, aaaa
FROM domains
FROM . " . DatabaseConnection::TABLE_DOMAINS . "
WHERE id = :id";
try {
$statement = $this->dbConnection->prepare($sql);
$statement = $this->databaseConnection->getConnection()->prepare($sql);
$statement->bindParam(param:':id', var: $id);
$statement->execute();
return $statement->fetch(PDO::FETCH_ASSOC);
@ -99,11 +99,11 @@ class DomainController
{
// TODO create zone file and include
$sql = "
INSERT INTO domains (name, a, aaaa)
INSERT INTO " . DatabaseConnection::TABLE_DOMAINS . " (name, a, aaaa)
VALUES (:name, :a, :aaaa)";
try {
$statement = $this->dbConnection->prepare($sql);
$statement = $this->databaseConnection->getConnection()->prepare($sql);
$statement->bindParam(param: ':name', var: $name);
$statement->bindParam(param: ':a', var: $a);
$statement->bindParam(param: ':aaaa', var: $aaaa);
@ -121,7 +121,7 @@ class DomainController
exit(1);
}
return $this->dbConnection->lastInsertId();
return $this->databaseConnection->getConnection()->lastInsertId();
} catch (PDOException $e) {
exit($e->getMessage());
}
@ -135,9 +135,9 @@ class DomainController
* @param String $a
* @param String $aaaa
*
* @return int|void
* @return false|int
*/
public function update(Int $id, String $name, String $a, String $aaaa)
public function update(Int $id, String $name, String $a, String $aaaa): bool|int
{
$current = $this->findByID($id);
@ -162,14 +162,14 @@ class DomainController
}
$sql = "
UPDATE domains SET
UPDATE " . DatabaseConnection::TABLE_DOMAINS . " SET
name = :name,
a = :a,
aaaa = :aaaa
WHERE id = :id";
try {
$statement = $this->dbConnection->prepare($sql);
$statement = $this->databaseConnection->getConnection()->prepare($sql);
$statement->bindParam(param: 'id', var: $id);
$statement->bindParam(param: 'name', var: $name);
$statement->bindParam(param: 'a', var: $a);
@ -178,7 +178,7 @@ class DomainController
// recreate zonefile
$this->createZoneFile(name: $name, a: $a, aaaa: $aaaa);
exec('/usr/sbin/rndc reload');
exec(command: '/usr/sbin/rndc reload');
return $statement->rowCount();
} catch (PDOException $e) {
@ -197,11 +197,11 @@ class DomainController
{
// TODO delete zone file and include
$statement = "
DELETE FROM domains
DELETE FROM " . DatabaseConnection::TABLE_DOMAINS . "
WHERE id = :id";
try {
$statement = $this->dbConnection->prepare($statement);
$statement = $this->databaseConnection->getConnection()->prepare($statement);
$statement->bindParam(param: 'id', var: $id);
$statement->execute();
return $statement->rowCount();
@ -251,6 +251,7 @@ class DomainController
}
}
/**
* @param mixed $name
* @param mixed $a