1 package FS::cust_attachment;
4 use base qw( FS::otaker_Mixin FS::Record );
6 use FS::Record qw( qsearch qsearchs );
11 FS::cust_attachment - Object methods for cust_attachment records
15 use FS::cust_attachment;
17 $record = new FS::cust_attachment \%hash;
18 $record = new FS::cust_attachment { 'column' => 'value' };
20 $error = $record->insert;
22 $error = $new_record->replace($old_record);
24 $error = $record->delete;
26 $error = $record->check;
30 An FS::cust_attachment object represents a file attached to a L<FS::cust_main>
31 object. FS::cust_attachment inherits from FS::Record. The following fields
32 are currently supported:
38 Primary key (assigned automatically).
42 Customer number (see L<FS::cust_main>).
46 The date the record was last updated.
50 Order taker (see L<FS::access_user>)
58 The Content-Type of the file.
62 The contents of the file.
66 If the attachment was disabled, this contains the date it was disabled.
76 Creates a new attachment object.
80 # the new method can be inherited from FS::Record, if a table method is defined
82 sub table { 'cust_attachment'; }
84 sub nohistory_fields { 'body'; }
88 Adds this record to the database. If there is an error, returns the error,
89 otherwise returns false.
95 Delete this record from the database.
99 =item replace OLD_RECORD
101 Replaces the OLD_RECORD with this one in the database. If there is an error,
102 returns the error, otherwise returns false.
106 # the replace method can be inherited from FS::Record
110 Checks all fields to make sure this is a valid example. If there is
111 an error, returns the error, otherwise returns false. Called by the insert
116 # the check method should currently be supplied - FS::Record contains some
117 # data checking routines
122 my $conf = new FS::Conf;
124 if($conf->config('disable_cust_attachment') ) {
125 $error = 'Attachments disabled (see configuration)';
129 $self->ut_numbern('attachnum')
130 || $self->ut_number('custnum')
131 || $self->ut_numbern('_date')
132 || $self->ut_textn('otaker')
133 || $self->ut_text('filename')
134 || $self->ut_text('mime_type')
135 || $self->ut_numbern('disabled')
136 || $self->ut_anything('body')
138 if($conf->config('max_attachment_size')
139 and $self->size > $conf->config('max_attachment_size') ) {
140 $error = 'Attachment too large'
142 return $error if $error;
149 Returns the size of the attachment in bytes.
155 return length($self->body);
158 #false laziness w/otaker_Mixin & cust_main_note
161 if ( scalar(@_) ) { #set
163 my($l,$f) = (split(', ', $otaker));
164 my $access_user = qsearchs('access_user', { 'username'=>$otaker } )
165 || qsearchs('access_user', { 'first'=>$f, 'last'=>$l } )
166 or croak "can't set otaker: $otaker not found!"; #confess?
167 $self->usernum( $access_user->usernum );
168 $otaker; #not sure return is used anywhere, but just in case
170 if ( $self->usernum ) {
171 $self->access_user->username;
172 } elsif ( length($self->get('otaker')) ) {
173 $self->get('otaker');
180 # Used by FS::Upgrade to migrate to a new database.
181 sub _upgrade_data { # class method
182 my ($class, %opts) = @_;
183 $class->_upgrade_otaker(%opts);
190 Doesn't work on non-Postgres systems.
194 L<FS::Record>, schema.html from the base documentation.