1 package FS::cust_attachment;
4 use base qw( FS::otaker_Mixin 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 (see L<FS::access_user>)
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_textn('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);
157 #false laziness w/otaker_Mixin & cust_main_note
160 if ( scalar(@_) ) { #set
162 my($l,$f) = (split(', ', $otaker));
163 my $access_user = qsearchs('access_user', { 'username'=>$otaker } )
164 || qsearchs('access_user', { 'first'=>$f, 'last'=>$l } )
165 or croak "can't set otaker: $otaker not found!"; #confess?
166 $self->usernum( $access_user->usernum );
167 $otaker; #not sure return is used anywhere, but just in case
169 if ( $self->usernum ) {
170 $self->access_user->username;
171 } elsif ( length($self->get('otaker')) ) {
172 $self->get('otaker');
179 # Used by FS::Upgrade to migrate to a new database.
180 sub _upgrade_data { # class method
181 my ($class, %opts) = @_;
182 $class->_upgrade_otaker(%opts);
189 Doesn't work on non-Postgres systems.
193 L<FS::Record>, schema.html from the base documentation.