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 Debbugs::DB::Util qw(select_one);
31 use Scalar::Util qw(blessed);
33 sub get_correspondent_id {
34 my ($self,$addr) = @_;
37 $full_name = $addr->phrase();
38 $addr = $addr->address();
39 } elsif ($addr =~ /</) {
40 $addr = getparsedaddrs($addr);
41 $full_name = $addr->phrase();
42 $addr = $addr->address();
44 if (defined $full_name) {
45 $full_name =~ s/^\"|\"$//g;
46 $full_name =~ s/^\s+|\s+$//g;
50 search({addr => $addr},
51 {result_class => 'DBIx::Class::ResultClass::HashRefInflator',
57 return $self->result_source->schema->storage->
59 my ($s,$dbh,$addr,$full_name) = @_;
60 my $ci = select_one($dbh,<<'SQL',$addr,$addr);
62 INSERT INTO correspondent (addr) VALUES (?)
63 ON CONFLICT (addr) DO NOTHING RETURNING id
67 SELECT id FROM correspondent WHERE addr = ?
70 if (defined $full_name) {
71 select_one($dbh,<<'SQL',$ci,$full_name);
73 INSERT INTO correspondent_full_name (correspondent,full_name)
74 VALUES (?,?) ON CONFLICT (correspondent,full_name) DO NOTHING RETURNING 1