added debugging
Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
parent
9271752843
commit
05db619afd
@ -14,7 +14,12 @@ use PDOException;
|
||||
class DomainRepository
|
||||
{
|
||||
public function __construct(private DatabaseConnection $databaseConnection, private array $config, private Logger $log)
|
||||
{}
|
||||
{
|
||||
if ($this->config['debug']) {
|
||||
$this->log->debug(message: "DomainRepository::__construct()");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -22,9 +27,13 @@ class DomainRepository
|
||||
*/
|
||||
public function findAll(): array
|
||||
{
|
||||
if ($this->config['debug']) {
|
||||
$this->log->debug(message: "findAll()");
|
||||
}
|
||||
|
||||
$domains = [];
|
||||
$sql = "
|
||||
SELECT id, name, panel_id, a, aaaa
|
||||
SELECT id, name, content
|
||||
FROM " . DatabaseConnection::TABLE_DOMAINS . "
|
||||
ORDER BY name";
|
||||
|
||||
@ -32,7 +41,9 @@ class DomainRepository
|
||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
$statement->execute();
|
||||
while ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) {
|
||||
$domain = new Domain(name: $result['name'], id: $result['id'], panelID: $result['panel_id'], a: $result['a'], aaaa: $result['aaaa']);
|
||||
//print_r($result);
|
||||
//die();
|
||||
$domain = new Domain(name: $result['name'], id: $result['id'], content: $result['content']);
|
||||
$domains[] = $domain;
|
||||
}
|
||||
return $domains;
|
||||
@ -49,8 +60,12 @@ class DomainRepository
|
||||
*/
|
||||
public function findByID(int $id): bool|Domain
|
||||
{
|
||||
if ($this->config['debug']) {
|
||||
$this->log->debug(message: "findById($id)");
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT id, name, panel_id, a, aaaa
|
||||
SELECT id, name, content
|
||||
FROM . " . DatabaseConnection::TABLE_DOMAINS . "
|
||||
WHERE id = :id";
|
||||
|
||||
@ -60,7 +75,7 @@ class DomainRepository
|
||||
$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'], content: $result['content']);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@ -77,8 +92,12 @@ class DomainRepository
|
||||
*/
|
||||
public function findByName(string $name): Domain|bool
|
||||
{
|
||||
if ($this->config['debug']) {
|
||||
$this->log->debug(message: "findByName($name)");
|
||||
}
|
||||
print("xxx: $name");
|
||||
$sql = "
|
||||
SELECT id, name, panel_id, a, aaaa
|
||||
SELECT id, name, content
|
||||
FROM " . DatabaseConnection::TABLE_DOMAINS . "
|
||||
WHERE name = :name";
|
||||
|
||||
@ -87,12 +106,10 @@ class DomainRepository
|
||||
$statement->bindParam(param: ':name', var: $name);
|
||||
$statement->execute();
|
||||
if ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) {
|
||||
return new Domain(name: $result['name'], id: $result['id'], panelID: $result['panel_id'], a: $result['a'], aaaa: $result['aaaa']);
|
||||
|
||||
return new Domain(name: $result['name'], id: $result['id'], content: $result['content']);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
exit($e->getMessage());
|
||||
}
|
||||
@ -112,20 +129,15 @@ class DomainRepository
|
||||
}
|
||||
|
||||
$sql = "
|
||||
INSERT INTO " . DatabaseConnection::TABLE_DOMAINS . " (name, panel_id, a, aaaa)
|
||||
VALUES (:name, :panel_id, :a, :aaaa)";
|
||||
INSERT INTO " . DatabaseConnection::TABLE_DOMAINS . " (name, content)
|
||||
VALUES (:name, :content)";
|
||||
|
||||
try {
|
||||
$name = $domain->getName();
|
||||
$panelID = $domain->getPanelID();
|
||||
$a = $domain->getA();
|
||||
$aaaa = $domain->getAaaa();
|
||||
|
||||
$content = $domain->getContent();
|
||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
$statement->bindParam(param: ':name', var: $name);
|
||||
$statement->bindParam(param: ':panel_id', var: $panelID);
|
||||
$statement->bindParam(param: ':a', var: $a);
|
||||
$statement->bindParam(param: ':aaaa', var: $aaaa);
|
||||
$statement->bindParam(param: ':content', var: $content);
|
||||
$statement->execute();
|
||||
|
||||
return $this->databaseConnection->getConnection()->lastInsertId();
|
||||
@ -147,47 +159,31 @@ class DomainRepository
|
||||
$this->log->debug(message: "update($domainName)");
|
||||
}
|
||||
|
||||
$current = $this->findByID(id: $domain->getId());
|
||||
|
||||
/* doesn't work
|
||||
$statement = "
|
||||
INSERT INTO domains(id, name, a, aaaa)
|
||||
VALUES(:id, :name, :a, :aaaa)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
name=COALESCE(VALUES(name), :name),
|
||||
a=COALESCE(:a, a),
|
||||
aaaa=COALESCE(:aaaa, aaaa)";
|
||||
*/
|
||||
$id = $domain->getId();
|
||||
$current = $this->findByID(id: $id);
|
||||
|
||||
if (empty($domain->getName())) {
|
||||
$name = $current['name'];
|
||||
$name = $current->getName();
|
||||
} else {
|
||||
$name = $domain->getName();
|
||||
}
|
||||
if (empty($domain->getPanelID())) {
|
||||
$panelID = $current['panel_id'];
|
||||
}
|
||||
$panelID = intval(value: $panelID);
|
||||
if (empty($a)) {
|
||||
$a = $current['a'];
|
||||
}
|
||||
if (empty($aaaa)) {
|
||||
$aaaa = $current['aaaa'];
|
||||
if (empty($domain->getContent())) {
|
||||
$content = $current->getContent();
|
||||
} else {
|
||||
$content = $domain->getContent();
|
||||
}
|
||||
|
||||
$sql = "
|
||||
UPDATE " . DatabaseConnection::TABLE_DOMAINS . " SET
|
||||
name = :name,
|
||||
panel_id = :panel_id,
|
||||
a = :a,
|
||||
aaaa = :aaaa
|
||||
content = :content
|
||||
WHERE id = :id";
|
||||
|
||||
try {
|
||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
$statement->bindParam(param: 'id', var: $id);
|
||||
$statement->bindParam(param: 'name', var: $name);
|
||||
$statement->bindParam(param: 'panel_id', var: $panelID);
|
||||
$statement->bindParam(param: 'a', var: $a);
|
||||
$statement->bindParam(param: 'aaaa', var: $aaaa);
|
||||
$statement->bindParam(param: 'content', var: $content);
|
||||
$statement->execute();
|
||||
|
||||
return $statement->rowCount();
|
||||
|
Loading…
Reference in New Issue
Block a user