DBDNSZone::save PHP Method

save() public method

public save ( $update_system_records = false )
    public function save($update_system_records = false)
    {
        $row = $this->unBind();
        unset($row['id']);
        unset($row['dtlastmodified']);
        $this->db->BeginTrans();
        // Prepare SQL statement
        $set = array();
        $bind = array();
        foreach ($row as $field => $value) {
            $set[] = "`{$field}` = ?";
            $bind[] = $value;
        }
        $set = join(', ', $set);
        try {
            //Save zone;
            if ($this->id) {
                if ($update_system_records) {
                    $this->updateSystemRecords();
                }
                // Perform Update
                $bind[] = $this->id;
                $this->db->Execute("UPDATE dns_zones SET {$set}, `dtlastmodified` = NOW() WHERE id = ?", $bind);
                //TODO:
                if ($update_system_records) {
                    $this->db->Execute("UPDATE dns_zones SET status=?, `dtlastmodified` = NOW() WHERE id = ?", array($this->status, $this->id));
                }
            } else {
                // Perform Insert
                $this->db->Execute("INSERT INTO dns_zones SET {$set}", $bind);
                $this->id = $this->db->Insert_ID();
                if ($update_system_records) {
                    $this->updateSystemRecords();
                    $this->db->Execute("UPDATE dns_zones SET status=?, `dtlastmodified` = NOW() WHERE id = ?", array($this->status, $this->id));
                }
            }
            if ($this->updateRecords) {
                $this->db->Execute("DELETE FROM dns_zone_records WHERE zone_id=? AND issystem='0'", array($this->id));
                foreach ($this->records as $record) {
                    //UNIQUE KEY `zoneid` (`zone_id`,`type`(1),`value`,`name`)
                    $this->db->Execute("\n                        INSERT INTO dns_zone_records\n                        SET `zone_id` = ?,\n                            `type` = ?,\n                            `value` = ?,\n                            `name` = ?,\n                            `issystem` = '0',\n                            `ttl` = ?,\n                            `priority` = ?,\n                            `weight` = ?,\n                            `port` = ?\n                        ON DUPLICATE KEY UPDATE\n                            `issystem` = '0',\n                            `ttl` = ?,\n                            `priority` = ?,\n                            `weight` = ?,\n                            `port` = ?\n                    ", array($this->id, $record['type'], $record['value'], $record['name'], (int) $record['ttl'], (int) $record['priority'], (int) $record['weight'], (int) $record['port'], (int) $record['ttl'], (int) $record['priority'], (int) $record['weight'], (int) $record['port']));
                }
            }
        } catch (Exception $e) {
            $this->db->RollbackTrans();
            throw new Exception("Cannot save DBDNS zone. Error: " . $e->getMessage(), $e->getCode());
        }
        $this->db->CommitTrans();
    }