1 package FS::otaker_Mixin;
4 use Carp qw( croak ); #confess );
5 use FS::Record qw( qsearch qsearchs );
11 if ( scalar(@_) ) { #set
13 my $access_user = qsearchs('access_user', { 'username' => $otaker } );
14 if ( !$access_user && $otaker =~ /^(.+), (.+)$/ ) { #same as below..
15 my($lastname, $firstname) = ($1, $2);
16 $otaker = lc($firstname.$lastname);
18 $access_user = qsearchs('access_user', { 'first' => $firstname,
19 'last' => $lastname } )
20 || qsearchs('access_user', { 'username' => $otaker } );
22 croak "can't set otaker: $otaker not found!" unless $access_user; #confess?
23 $self->usernum( $access_user->usernum );
24 $otaker; #not sure return is used anywhere, but just in case
26 if ( $self->usernum ) {
27 $self->access_user->username;
28 } elsif ( length($self->get('otaker')) ) {
38 qsearchs('access_user', { 'usernum' => $self->usernum } );
43 my $table = $class->table;
45 my $limit = ( $table eq 'cust_attachment' ? 10 : 1000 );
48 my @records = qsearch({
51 'extra_sql' => "WHERE otaker IS NOT NULL LIMIT $limit",
55 foreach my $record (@records) {
56 eval { $record->otaker($record->otaker) };
58 my $username = $record->otaker;
59 my($lastname, $firstname) = ( 'User', 'Legacy' );
60 if ( $username =~ /^(.+), (.+)$/ ) {
61 ($lastname, $firstname) = ($1, $2);
62 $username = lc($firstname.$lastname);
65 my $access_user = new FS::access_user {
66 'username' => $username,
67 '_password' => 'CHANGEME',
68 'first' => $firstname,
72 my $error = $access_user->insert;
74 $record->otaker($record->otaker);
76 $record->set('otaker', '');
77 my $error = $record->replace;
81 if ( $table eq 'cust_attachment' ) {
82 warn " committing (cust_attachment) \n";
83 dbh->commit or die dbh->errstr;