Apache-App-Mercury

 view release on metacpan or  search on metacpan

Mercury/Message/Attachment.pm  view on Meta::CPAN

	$sth2->finish;

	$dbh->disconnect;
    };
    if ($@) {
	$self->log_error;
	return 0;
    }
    return 1;
}

sub stored {
    return exists $_[0]->{'AttachmentID'};
}

sub retrieve {
    my ($self) = @_;

    unless (defined $self->{'AttachmentID'} or defined $self->{'Filename'}) {
	$self->log_error("->retrieve: an AttachmentID or Filename is required for retrieval");
	return undef;
    }

    my ($where_clause, @bind_params);
    if (defined $self->{'AttachmentID'}) {
	$where_clause = 'aid=?';
	push(@bind_params, $self->{'AttachmentID'});
    } else {
	$where_clause = 'filesys=?';
	push(@bind_params, $self->{'Filename'});
    }

    eval {
	my $dbh = DBI->connect(Apache::App::Mercury::Config::DBI_CONNECT_STR(),
			       Apache::App::Mercury::Config::DBI_LOGIN(),
			       Apache::App::Mercury::Config::DBI_PASS(),
			       {'RaiseError' => 1});
	my $sth2 = $dbh->prepare_cached
	  ("SELECT aid,filesys,attachment,msg_ids FROM ".SQL_ATTACHMENT_TABLE." WHERE $where_clause");
	$sth2->execute(@bind_params);

	$self->{'AttachmentID'} = '';
	$self->{'Name'} = '';
	$self->{'Filename'} = '';
	my $msg_ids;
	$sth2->bind_columns(\ ($self->{'AttachmentID'}, $self->{'Filename'},
			       $self->{'Name'}, $msg_ids) );
	$sth2->fetchrow_arrayref;
	$self->{'MessageIDs'} = { map { $_ => 1 } split(/\s+/, $msg_ids) };

	$sth2->finish;
	$dbh->disconnect;
    };
    if ($@) {
	$self->log_error($@);
	return undef;
    }
    return $self;
}

sub update_messages_containing {
    my ($self) = @_;

    unless (defined $self->{'AttachmentID'} and
	    ref $self->{'MessageIDs'} eq "HASH") {
	$self->log_error("->update_messages_containing: an AttachmentID or Filename is required for retrieval");
	return undef;
    }

    eval {
	my $dbh = DBI->connect(Apache::App::Mercury::Config::DBI_CONNECT_STR(),
			       Apache::App::Mercury::Config::DBI_LOGIN(),
			       Apache::App::Mercury::Config::DBI_PASS(),
			       {'RaiseError' => 1});
	my $sth = $dbh->prepare_cached
	  ("UPDATE ".SQL_ATTACHMENT_TABLE." SET msg_ids=? WHERE aid=?");
	$sth->execute(join(' ', sort {$a<=>$b} keys %{$self->{'MessageIDs'}}),
		      $self->{'AttachmentID'});
	$dbh->disconnect;
    };
    if ($@) {
	$self->log_error;
	return undef;
    }
    return 1;
}


1;



( run in 0.487 second using v1.01-cache-2.11-cpan-5a3173703d6 )