<<

NAME

Koha::Misc::Files - module for managing miscellaneous files associated with records from arbitrary tables

SYNOPSIS

use Koha::Misc::Files;

my $mf = Koha::Misc::Files->new( tabletag => $tablename, recordid => $recordnumber );

FUNCTIONS

new()

my $mf = Koha::Misc::Files->new( tabletag => $tablename, recordid => $recordnumber );

Creates new Koha::Misc::Files object. Such object is essentially a pair: in typical usage scenario, 'tabletag' parameter will be a database table name, and 'recordid' an unique record ID number from this table. However, this method does accept an arbitrary string as 'tabletag', and an arbitrary integer as 'recordid'.

Particular Koha::Misc::Files object can have one or more file records (actuall file contents + various file metadata) associated with it.

In case of an error (wrong parameter format) it returns undef.

GetFilesInfo()

my $files_descriptions = $mf->GetFilesInfo();

This method returns a reference to an array of hashes containing files metadata (file_id, file_name, file_type, file_description, file_size, date_uploaded) for all file records associated with given $mf object, or an empty arrayref if there are no such records yet.

In case of an error it returns undef.

AddFile()

$mf->AddFile( name => $filename, type => $mimetype, description => $description, content => $content );

Adds a new file (we want to store for / associate with a given object) to the database. Parameters 'name' and 'content' are mandatory. Note: this method would (silently) fail if there is no 'name' given or if the 'content' provided is empty.

GetFile()

my $file = $mf->GetFile( id => $file_id );

For an individual, specific file ID this method returns a hashref containing all metadata (file_id, table_tag, record_id, file_name, file_type, file_description, file_content, date_uploaded), plus an actuall contents of a file (in 'file_content'). In typical usage scenarios, for a given $mf object, specific file IDs have to be obtained first by GetFilesInfo() call.

Returns undef in case when file ID specified as 'id' parameter was not found in the database.

DelFile()

$mf->DelFile( id => $file_id );

Deletes specific, individual file record (file contents and metadata) from the database.

DelAllFiles()

$mf->DelAllFiles();

Deletes all file records associated with (stored for) a given $mf object.

MergeFileRecIds()

$mf->MergeFileRecIds(@ids_to_be_merged);

This method re-associates all individuall file records associated with some "parent" records IDs (provided in @ids_to_be_merged) with the given single $mf object (which would be treated as a "parent" destination).

This a helper method; typically it needs to be called only in cases when some "parent" records are being merged in the (external) 'tablename' table.

SEE ALSO

Koha::Borrower::Files

AUTHOR

Kyle M Hall <kyle.m.hall@gmail.com>, Jacek Ablewicz <ablewicz@gmail.com>

<<