1 # This module is part of debbugs, and is released
2 # under the terms of the GPL version 2, or any later version. See the
3 # file README and COPYING for more information.
4 # Copyright 2016 by Don Armstrong <don@donarmstrong.com>.
6 package Debbugs::DB::ResultSet::Maintainer;
10 Debbugs::DB::ResultSet::Maintainer - Package maintainer result set operations
25 use base 'DBIx::Class::ResultSet';
27 use Debbugs::DB::Util qw(select_one);
34 $s->resultset('Maintainers')->get_maintainers();
36 $s->resultset('Maintainers')->get_maintainers(@maints);
38 Retrieve a HASHREF of all maintainers with the maintainer name as the key and
39 the id of the database as the value. If given an optional list of maintainers,
40 adds those maintainers to the database if they do not already exist in the
45 my ($self,@maints) = @_;
47 for my $m ($self->result_source->schema->resultset('Maintainer')->
49 {result_class => 'DBIx::Class::ResultClass::HashRefInflator',
50 columns => [qw[id name] ]
52 $maints{$m->{name}} = $m->{id};
54 my @maint_names = grep {not exists $maints{$_}} @maints;
55 my @maint_ids = $self->result_source->schema->
60 $self->result_source->schema->
61 resultset('Maintainer')->get_maintainer_id($name);
65 @maints{@maint_names} = @maint_ids;
69 =item get_maintainer_id
71 $s->resultset('Maintainer')->get_maintainer_id('Foo Bar <baz@example.com>')
73 Given a maintainer name returns the maintainer id, possibly inserting the
74 maintainer (and correspondent) if either do not exist in the database.
79 sub get_maintainer_id {
80 my ($self,$maint) = @_;
83 search({name => $maint},
84 {result_class => 'DBIx::Class::ResultClass::HashRefInflator',
91 $self->result_source->schema->resultset('Correspondent')->
92 get_correspondent_id($maint);
93 return $self->result_source->schema->storage->
95 my ($s,$dbh,$maint,$ci) = @_;
96 return select_one($dbh,<<'SQL',$maint,$ci,$maint);
98 INSERT INTO maintainer (name,correspondent) VALUES (?,?)
99 ON CONFLICT (name) DO NOTHING RETURNING id
103 SELECT id FROM maintainer WHERE name = ?