parent
b2452d349a
commit
6665933a41
|
@ -4,6 +4,7 @@ namespace App\Repository;
|
|||
|
||||
use App\Controller\DatabaseConnection;
|
||||
use App\Entity\Domain;
|
||||
use Monolog\Logger;
|
||||
use PDO;
|
||||
use PDOException;
|
||||
|
||||
|
@ -12,7 +13,7 @@ use PDOException;
|
|||
*/
|
||||
class DomainRepository
|
||||
{
|
||||
public function __construct(private DatabaseConnection $databaseConnection)
|
||||
public function __construct(private DatabaseConnection $databaseConnection, private array $config, private Logger $log)
|
||||
{}
|
||||
|
||||
|
||||
|
@ -58,6 +59,7 @@ class DomainRepository
|
|||
$statement->bindParam(param: ':id', var: $id);
|
||||
$statement->execute();
|
||||
if ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) {
|
||||
|
||||
return new Domain(name: $result['name'], panelID: $result['panel_id'], a: $result['a'], aaaa: $result['aaaa']);
|
||||
} else {
|
||||
return false;
|
||||
|
@ -85,7 +87,7 @@ class DomainRepository
|
|||
$statement->bindParam(param: ':name', var: $name);
|
||||
$statement->execute();
|
||||
if ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) {
|
||||
return new Domain(name: $result['name'], panelID: $result['panel_id'], a: $result['a'], aaaa: $result['aaaa']);
|
||||
return new Domain(name: $result['name'], id: $result['id'], panelID: $result['panel_id'], a: $result['a'], aaaa: $result['aaaa']);
|
||||
|
||||
} else {
|
||||
return false;
|
||||
|
@ -97,23 +99,28 @@ class DomainRepository
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param String $name
|
||||
* @param int $panelID
|
||||
* @param String $a
|
||||
* @param String $aaaa
|
||||
* @param \App\Entity\Domain $domain
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
public function insert(string $name, int $panelID, string $a, string $aaaa): bool|string
|
||||
public function insert(Domain $domain): bool|string
|
||||
{
|
||||
print("here");
|
||||
if ($this->config['debug']) {
|
||||
$domainName = $domain->getName();
|
||||
$this->log->debug(message: "insert($domainName)");
|
||||
}
|
||||
|
||||
$sql = "
|
||||
INSERT INTO " . DatabaseConnection::TABLE_DOMAINS . " (name, panel_id, a, aaaa)
|
||||
VALUES (:name, :panel_id, :a, :aaaa)";
|
||||
|
||||
try {
|
||||
$name = $domain->getName();
|
||||
$panelID = $domain->getPanelID();
|
||||
$a = $domain->getA();
|
||||
$aaaa = $domain->getAaaa();
|
||||
|
||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
$statement->bindParam(param: ':name', var: $name);
|
||||
$statement->bindParam(param: ':panel_id', var: $panelID);
|
||||
|
@ -129,17 +136,18 @@ class DomainRepository
|
|||
|
||||
|
||||
/**
|
||||
* @param Int $id
|
||||
* @param String $name
|
||||
* @param int $panelID
|
||||
* @param String $a
|
||||
* @param String $aaaa
|
||||
* @param \App\Entity\Domain $domain
|
||||
*
|
||||
* @return false|int
|
||||
*/
|
||||
public function update(int $id, string $name, int $panelID, string $a, string $aaaa): bool|int
|
||||
public function update(Domain $domain): bool|int
|
||||
{
|
||||
$current = $this->findByID(id: $id);
|
||||
if ($this->config['debug']) {
|
||||
$domainName = $domain->getName();
|
||||
$this->log->debug(message: "update($domainName)");
|
||||
}
|
||||
|
||||
$current = $this->findByID(id: $domain->getId());
|
||||
|
||||
/* doesn't work
|
||||
$statement = "
|
||||
|
@ -151,10 +159,10 @@ class DomainRepository
|
|||
aaaa=COALESCE(:aaaa, aaaa)";
|
||||
*/
|
||||
|
||||
if (empty($name)) {
|
||||
if (empty($domain->getName())) {
|
||||
$name = $current['name'];
|
||||
}
|
||||
if (empty($panelID)) {
|
||||
if (empty($domain->getPanelID())) {
|
||||
$panelID = $current['panel_id'];
|
||||
}
|
||||
$panelID = intval(value: $panelID);
|
||||
|
@ -191,18 +199,24 @@ class DomainRepository
|
|||
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param \App\Entity\Domain $domain
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function delete($id): int
|
||||
public function delete(Domain $domain): int
|
||||
{
|
||||
if ($this->config['debug']) {
|
||||
$domainName = $domain->getName();
|
||||
$this->log->debug(message: "delete($domainName)");
|
||||
}
|
||||
|
||||
$sql = "
|
||||
DELETE FROM " . DatabaseConnection::TABLE_DOMAINS . "
|
||||
WHERE id = :id";
|
||||
|
||||
try {
|
||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
$id = $domain->getId();
|
||||
$statement->bindParam(param: 'id', var: $id);
|
||||
$statement->execute();
|
||||
|
||||
|
|
Loading…
Reference in New Issue