MidCOM level replacement for the Midgard Attachment record with framework support.

package midcom.db

 Methods

__construct ($id)

Parameters

$id

_on_created ()

Created callback, triggers watches on the parent(!) object.

_on_creating ()

Simple creation event handler which fills out the location field if it is still empty with a location generated by _create_attachment_location().

Returns

booleanTrue if creation may commence.

_on_deleted ()

Deleted callback, triggers watches on the parent(!) object.

_on_updated ()

Updated callback, triggers watches on the parent(!) object.

close ()

This function closes the open write handle obtained by the open() call again.

It is required to call this function instead of a simple fclose to ensure proper upgrade notifications.

copy_from_file (string $filename)

Updates the contents of the attachments with the contents of the file specified.

This is a wrapper for copy_from_handle.

Parameters

$filename

stringThe file to read.

Returns

booleanIndicating success.

copy_from_handle (resource $source)

Updates the contents of the attachments with the contents of the resource identified by the filehandle passed.

Parameters

$source

resourceThe handle to read from.

Returns

booleanIndicating success.

copy_from_memory (mixed $source)

Updates the contents of the attachments with the contents given.

Parameters

$source

mixedFile contents.

Returns

booleanIndicating success.

file_to_cache ()

get_cache_path ()

Get the path to the document in the static cache

Returns

string

get_parent_guid_uncached ()

get_parent_guid_uncached_static ($guid, $classname)

Returns the Parent of the Attachment, which is identified by the table/id combination in the attachment record.
Static

The table in question is used to identify the object to use. If multiple objects are registered for a given table, the first matching class returned by the dbfactory is used (which is usually rather arbitrary).

Parameters

$guid

$classname

Returns

\MidgardObjectParent object.

get_url ($attachment)

Static

Parameters

$attachment

open ()

Opens the attachment for file IO, the semantics match the original mgd_open_attachment call.

Returns a filehandle that can be used with the usual PHP file functions if successful, the handle has to be closed with the close() method when you no longer need it, don't let it fall over the end of the script.

Important Note: It is important to use the close() member function of this class to close the file handle, not just fclose(). Otherwise, the upgrade notification switches will fail.

Returns

resourceA file handle to the attachment if successful, false on failure.

read ()

This function reads the file and returns its contents

Returns

string

safe_filename (string $filename, boolean $force_single_extension)

Rewrite a filename to URL safe form
Static
todo add possibility to use the file utility to determine extension if missing.

Parameters

$filename

stringfile name to rewrite

$force_single_extension

booleanforce file to single extension (defaults to true)

Returns

stringrewritten filename

stat ()

Simple wrapper for stat() on the blob object.

Returns

mixedEither a stat array as for stat() or false on failure.

update_cache ()

_create_attachment_location ()

Internal helper, computes an MD5 string which is used as an attachment location.

It should be random enough, even if the algorithm used does not match the one Midgard uses. If the location already exists, it will iterate until an unused location is found.

Returns

stringAn unused attachment location.

 Properties

 

mixed $__mgdschema_class_name__

 

mixed $__midcom_class_name__

 

mixed $_open_write_mode

Internal tracking state variable, true if the attachment has a handle opened in write mode
 

resource $_open_handle

Internal tracking state variable, holds the file handle of any open attachment.