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);
32 sub get_correspondent_id {
33 my ($self,$addr) = @_;
36 $addr = getparsedaddrs($addr);
37 $full_name = $addr->phrase();
38 $full_name =~ s/^\"|\"$//g;
39 $full_name =~ s/^\s+|\s+$//g;
40 $addr = $addr->address();
44 search({addr => $addr},
45 {result_class => 'DBIx::Class::ResultClass::HashRefInflator',
51 return $self->result_source->schema->storage->
53 my ($s,$dbh,$addr,$full_name) = @_;
54 my $ci = select_one($dbh,<<'SQL',$addr,$addr);
56 INSERT INTO correspondent (addr) VALUES (?)
57 ON CONFLICT (addr) DO NOTHING RETURNING id
61 SELECT id FROM correspondent WHERE addr = ?
64 select_one($dbh,<<'SQL',$ci,$full_name,$ci,$full_name);
66 INSERT INTO correspondent_full_name (correspondent,full_name)
67 VALUES (?,?) ON CONFLICT (correspondent,full_name) DO NOTHING RETURNING id
71 SELECT id FROM correspondent_full_name WHERE correspondent=? AND full_name = ?