replaced PDO with DatabaseConnection
Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
parent
657eeb0496
commit
53e942f077
|
@ -15,7 +15,7 @@ class DomainController
|
||||||
private String $namedConfLocalFile;
|
private String $namedConfLocalFile;
|
||||||
private string $zoneCachePath;
|
private string $zoneCachePath;
|
||||||
|
|
||||||
public function __construct(private PDO $dbConnection)
|
public function __construct(private DatabaseConnection $databaseConnection)
|
||||||
{
|
{
|
||||||
$this->localZoneFile = '/etc/bind/local.zones';
|
$this->localZoneFile = '/etc/bind/local.zones';
|
||||||
$this->localZonesDir = '/etc/bind/zones/';
|
$this->localZonesDir = '/etc/bind/zones/';
|
||||||
|
@ -31,10 +31,10 @@ class DomainController
|
||||||
{
|
{
|
||||||
$statement = "
|
$statement = "
|
||||||
SELECT id, name, a, aaaa
|
SELECT id, name, a, aaaa
|
||||||
FROM domains";
|
FROM " . DatabaseConnection::TABLE_DOMAINS;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->dbConnection->query($statement);
|
$statement = $this->databaseConnection->getConnection()->query($statement);
|
||||||
return $statement->fetchAll(mode: PDO::FETCH_ASSOC);
|
return $statement->fetchAll(mode: PDO::FETCH_ASSOC);
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
exit($e->getMessage());
|
exit($e->getMessage());
|
||||||
|
@ -51,11 +51,11 @@ class DomainController
|
||||||
{
|
{
|
||||||
$sql = "
|
$sql = "
|
||||||
SELECT id, name, a, aaaa
|
SELECT id, name, a, aaaa
|
||||||
FROM domains
|
FROM " . DatabaseConnection::TABLE_DOMAINS . "
|
||||||
WHERE name = :name";
|
WHERE name = :name";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->dbConnection->prepare($sql);
|
$statement = $this->databaseConnection->getConnection()->prepare($sql);
|
||||||
$statement->bindParam(param: ':name', var: $name);
|
$statement->bindParam(param: ':name', var: $name);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
return $statement->fetch(PDO::FETCH_ASSOC);
|
return $statement->fetch(PDO::FETCH_ASSOC);
|
||||||
|
@ -74,11 +74,11 @@ class DomainController
|
||||||
{
|
{
|
||||||
$sql = "
|
$sql = "
|
||||||
SELECT id, name, a, aaaa
|
SELECT id, name, a, aaaa
|
||||||
FROM domains
|
FROM . " . DatabaseConnection::TABLE_DOMAINS . "
|
||||||
WHERE id = :id";
|
WHERE id = :id";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->dbConnection->prepare($sql);
|
$statement = $this->databaseConnection->getConnection()->prepare($sql);
|
||||||
$statement->bindParam(param:':id', var: $id);
|
$statement->bindParam(param:':id', var: $id);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
return $statement->fetch(PDO::FETCH_ASSOC);
|
return $statement->fetch(PDO::FETCH_ASSOC);
|
||||||
|
@ -99,11 +99,11 @@ class DomainController
|
||||||
{
|
{
|
||||||
// TODO create zone file and include
|
// TODO create zone file and include
|
||||||
$sql = "
|
$sql = "
|
||||||
INSERT INTO domains (name, a, aaaa)
|
INSERT INTO " . DatabaseConnection::TABLE_DOMAINS . " (name, a, aaaa)
|
||||||
VALUES (:name, :a, :aaaa)";
|
VALUES (:name, :a, :aaaa)";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->dbConnection->prepare($sql);
|
$statement = $this->databaseConnection->getConnection()->prepare($sql);
|
||||||
$statement->bindParam(param: ':name', var: $name);
|
$statement->bindParam(param: ':name', var: $name);
|
||||||
$statement->bindParam(param: ':a', var: $a);
|
$statement->bindParam(param: ':a', var: $a);
|
||||||
$statement->bindParam(param: ':aaaa', var: $aaaa);
|
$statement->bindParam(param: ':aaaa', var: $aaaa);
|
||||||
|
@ -121,7 +121,7 @@ class DomainController
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->dbConnection->lastInsertId();
|
return $this->databaseConnection->getConnection()->lastInsertId();
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
exit($e->getMessage());
|
exit($e->getMessage());
|
||||||
}
|
}
|
||||||
|
@ -135,9 +135,9 @@ class DomainController
|
||||||
* @param String $a
|
* @param String $a
|
||||||
* @param String $aaaa
|
* @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);
|
$current = $this->findByID($id);
|
||||||
|
|
||||||
|
@ -162,14 +162,14 @@ class DomainController
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "
|
$sql = "
|
||||||
UPDATE domains SET
|
UPDATE " . DatabaseConnection::TABLE_DOMAINS . " SET
|
||||||
name = :name,
|
name = :name,
|
||||||
a = :a,
|
a = :a,
|
||||||
aaaa = :aaaa
|
aaaa = :aaaa
|
||||||
WHERE id = :id";
|
WHERE id = :id";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->dbConnection->prepare($sql);
|
$statement = $this->databaseConnection->getConnection()->prepare($sql);
|
||||||
$statement->bindParam(param: 'id', var: $id);
|
$statement->bindParam(param: 'id', var: $id);
|
||||||
$statement->bindParam(param: 'name', var: $name);
|
$statement->bindParam(param: 'name', var: $name);
|
||||||
$statement->bindParam(param: 'a', var: $a);
|
$statement->bindParam(param: 'a', var: $a);
|
||||||
|
@ -178,7 +178,7 @@ class DomainController
|
||||||
|
|
||||||
// recreate zonefile
|
// recreate zonefile
|
||||||
$this->createZoneFile(name: $name, a: $a, aaaa: $aaaa);
|
$this->createZoneFile(name: $name, a: $a, aaaa: $aaaa);
|
||||||
exec('/usr/sbin/rndc reload');
|
exec(command: '/usr/sbin/rndc reload');
|
||||||
|
|
||||||
return $statement->rowCount();
|
return $statement->rowCount();
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
|
@ -197,11 +197,11 @@ class DomainController
|
||||||
{
|
{
|
||||||
// TODO delete zone file and include
|
// TODO delete zone file and include
|
||||||
$statement = "
|
$statement = "
|
||||||
DELETE FROM domains
|
DELETE FROM " . DatabaseConnection::TABLE_DOMAINS . "
|
||||||
WHERE id = :id";
|
WHERE id = :id";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->dbConnection->prepare($statement);
|
$statement = $this->databaseConnection->getConnection()->prepare($statement);
|
||||||
$statement->bindParam(param: 'id', var: $id);
|
$statement->bindParam(param: 'id', var: $id);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
return $statement->rowCount();
|
return $statement->rowCount();
|
||||||
|
@ -251,6 +251,7 @@ class DomainController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $name
|
* @param mixed $name
|
||||||
* @param mixed $a
|
* @param mixed $a
|
||||||
|
|
Loading…
Reference in New Issue