1 package FS::cust_attachment;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
10 FS::cust_attachment - Object methods for cust_attachment records
14 use FS::cust_attachment;
16 $record = new FS::cust_attachment \%hash;
17 $record = new FS::cust_attachment { 'column' => 'value' };
19 $error = $record->insert;
21 $error = $new_record->replace($old_record);
23 $error = $record->delete;
25 $error = $record->check;
29 An FS::cust_attachment object represents a file attached to a L<FS::cust_main>
30 object. FS::cust_attachment inherits from FS::Record. The following fields
31 are currently supported:
37 Primary key (assigned automatically).
41 Customer number (see L<FS::cust_main>).
45 The date the record was last updated.
49 Order taker (assigned automatically; see L<FS::UID>).
57 The Content-Type of the file.
61 The contents of the file.
65 If the attachment was disabled, this contains the date it was disabled.
75 Creates a new attachment object.
79 # the new method can be inherited from FS::Record, if a table method is defined
81 sub table { 'cust_attachment'; }
83 sub nohistory_fields { 'body'; }
87 Adds this record to the database. If there is an error, returns the error,
88 otherwise returns false.
94 Delete this record from the database.
98 =item replace OLD_RECORD
100 Replaces the OLD_RECORD with this one in the database. If there is an error,
101 returns the error, otherwise returns false.
105 # the replace method can be inherited from FS::Record
109 Checks all fields to make sure this is a valid example. If there is
110 an error, returns the error, otherwise returns false. Called by the insert
115 # the check method should currently be supplied - FS::Record contains some
116 # data checking routines
121 my $conf = new FS::Conf;
123 if($conf->config('disable_cust_attachment') ) {
124 $error = 'Attachments disabled (see configuration)';
128 $self->ut_numbern('attachnum')
129 || $self->ut_number('custnum')
130 || $self->ut_numbern('_date')
131 || $self->ut_text('otaker')
132 || $self->ut_text('filename')
133 || $self->ut_text('mime_type')
134 || $self->ut_numbern('disabled')
135 || $self->ut_anything('body')
137 if($conf->config('max_attachment_size')
138 and $self->size > $conf->config('max_attachment_size') ) {
139 $error = 'Attachment too large'
141 return $error if $error;
148 Returns the size of the attachment in bytes.
154 return length($self->body);
161 Doesn't work on non-Postgres systems.
165 L<FS::Record>, schema.html from the base documentation.