Skip to content

Commit

Permalink
refactor: use prepared statements.
Browse files Browse the repository at this point in the history
  • Loading branch information
edmondas committed Dec 2, 2023
1 parent 684901c commit 8c6b45e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/DnsRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,7 @@ public static function get_domain_slave_master($db, int $id)

/** Change Zone Type
*
* @param $db
* @param string $type New Zone Type [NATIVE,MASTER,SLAVE]
* @param int $id Zone ID
*
Expand All @@ -1519,14 +1520,20 @@ public static function get_domain_slave_master($db, int $id)
public static function change_zone_type($db, string $type, int $id): void
{
$add = '';
$params = array(':type' => $type, ':id' => $id);

// It is not really necessary to clear the field that contains the IP address
// of the master if the type changes from slave to something else. PowerDNS will
// ignore the field if the type isn't something else then slave. But then again,
// it's much clearer this way.
if ($type != "SLAVE") {
$add = ", master=" . $db->quote('', 'text');
$add = ", master = :master";
$params[':master'] = '';
}
$db->query("UPDATE domains SET type = " . $db->quote($type, 'text') . $add . " WHERE id = " . $db->quote($id, 'integer'));
$query = "UPDATE domains SET type = :type" . $add . " WHERE id = :id";
$stmt = $db->prepare($query);

$stmt->execute($params);
}

/** Change Slave Zone's Master IP Address
Expand Down

0 comments on commit 8c6b45e

Please sign in to comment.