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 2017 by Don Armstrong <don@donarmstrong.com>.
6 package Debbugs::DB::ResultSet::Correspondent;
10 Debbugs::DB::ResultSet::Correspondent - Correspondent table actions
25 use base 'DBIx::Class::ResultSet';
27 use Debbugs::DB::Util qw(select_one);
29 use Debbugs::Common qw(getparsedaddrs);
30 use Scalar::Util qw(blessed);
32 sub get_correspondent_id {
33 my ($self,$addr) = @_;
36 $full_name = $addr->phrase();
37 $addr = $addr->address();
38 } elsif ($addr =~ /</) {
39 $addr = getparsedaddrs($addr);
40 $full_name = $addr->phrase();
41 $addr = $addr->address();
43 if (defined $full_name) {
44 $full_name =~ s/^\"|\"$//g;
45 $full_name =~ s/^\s+|\s+$//g;
49 search({addr => $addr},
50 {result_class => 'DBIx::Class::ResultClass::HashRefInflator',
57 $self->result_source->schema->
58 select_one(<<'SQL',$addr,$addr);
60 INSERT INTO correspondent (addr) VALUES (?)
61 ON CONFLICT (addr) DO NOTHING RETURNING id
65 SELECT id FROM correspondent WHERE addr = ?
68 if (defined $full_name) {
69 $self->result_source->schema->
70 select_one(<<'SQL',$ci,$full_name);
72 INSERT INTO correspondent_full_name (correspondent,full_name)
73 VALUES (?,?) ON CONFLICT (correspondent,full_name) DO NOTHING RETURNING 1