aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Thauvin <nanardon@mageia.org>2010-10-19 11:42:39 +0000
committerOlivier Thauvin <nanardon@mageia.org>2010-10-19 11:42:39 +0000
commit9fa18a22880f52192667c9df42d37bd75d11f1f4 (patch)
treef66ff2b368c7c4bfea6bfd8031b9875469675c85
parentf438c3aee114497ce57cc3569589e690dbe1a0c3 (diff)
downloadmgamirrors-9fa18a22880f52192667c9df42d37bd75d11f1f4.tar
mgamirrors-9fa18a22880f52192667c9df42d37bd75d11f1f4.tar.gz
mgamirrors-9fa18a22880f52192667c9df42d37bd75d11f1f4.tar.bz2
mgamirrors-9fa18a22880f52192667c9df42d37bd75d11f1f4.tar.xz
mgamirrors-9fa18a22880f52192667c9df42d37bd75d11f1f4.zip
- add initial function to have host changes validation
-rw-r--r--lib/MGA/Mirrors/DB.pm50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/MGA/Mirrors/DB.pm b/lib/MGA/Mirrors/DB.pm
index 1c79d8b..16070dc 100644
--- a/lib/MGA/Mirrors/DB.pm
+++ b/lib/MGA/Mirrors/DB.pm
@@ -422,6 +422,56 @@ sub find_host_ip_overlap {
return keys %{ $res };
}
+sub add_host_change_request {
+ my ($self, $hostname, %info) = @_;
+
+ my $reqid = join("", map { sprintf("%x", int rand(256)) } (0..16));
+ my $add = $self->db->prepare(sprintf(q{
+ INSERT INTO hosts_ch_req(
+ hostname, country, city, readonly, infourl, hostby, sponsorurl,
+ "comment", contact, syncfrom, public, bandwidth, latitude, longitude,
+ added, reqid)
+ select *, '%s' from hosts where hostname = ?
+ }, $reqid)
+ );
+ $add->execute( $hostname );
+ my (@fields, @vals);
+ while (my ($field, $val) = each(%info)) {
+ push(@fields, $field);
+ push(@vals, $val || undef);
+ }
+ if (keys %info) {
+ my $upd = $self->db->prepare(sprintf(q{
+ update hosts_ch_req set %s where reqid = ?
+ }, join(', ', map { "$_ = ?" } @fields)));
+ $upd->execute(@vals, $reqid);
+ }
+
+ $self->db->commit;
+
+ $reqid;
+}
+
+sub apply_change_request {
+ my ($self, $reqid) = @_;
+
+ my $findreq = $self->db->prepare(q{
+ select * from hosts_ch_req where reqid = ?
+ });
+ $findreq->execute($reqid);
+ my $res = $findreq->fetchrow_hashref;
+ $findreq->finish;
+ $res or return;
+
+ my $hostname = $res->{hostname};
+ delete $res->{hostname};
+ delete $res->{reqid};
+
+ $self->add_or_update_host($hostname, %{$res});
+ $self->db->commit;
+ 1
+}
+
sub add_or_update_host {
my ($self, $hostname, %info) = @_;