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