\midcom_db_attachment

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

Summary

Methods
Properties
Constants
__construct()
__get()
__set()
new_query_builder()
new_collector()
get_cached()
set_guid()
__isset()
create()
delete()
undelete()
purge()
delete_tree()
get_by_guid()
get_by_id()
get_by_path()
get_metadata()
get_parent()
is_in_parent_tree()
is_in_tree()
has_dependents()
list_children()
parent()
is_object_visible_onsite()
has_attachments()
find_attachments()
delete_attachments()
purge_attachments()
has_parameters()
find_parameters()
delete_parameters()
purge_parameters()
refresh()
update()
is_locked()
lock()
unlock()
is_approved()
approve()
unapprove()
get_properties()
new_reflection_property()
can_do()
can_user_do()
require_do()
require_user_do()
get_class_magic_default_privileges()
_on_created()
_on_creating()
_on_deleted()
_on_deleting()
_on_loaded()
_on_prepare_exec_query_builder()
_on_prepare_new_query_builder()
_on_process_query_result()
_on_prepare_new_collector()
_on_prepare_exec_collector()
_on_process_collector_result()
_on_updated()
_on_updating()
_on_imported()
_on_importing()
disable_rcs()
enable_rcs()
set_rcs_message()
get_rcs_message()
get_parameter()
list_parameters()
set_parameter()
delete_parameter()
get_attachment()
delete_attachment()
create_attachment()
get_attachment_qb()
list_attachments()
get_privileges()
set_privilege()
unset_privilege()
get_privilege()
unset_all_privileges()
create_new_privilege_object()
get_parent_guid_uncached()
get_parent_guid_uncached_static()
open()
read()
close()
safe_filename()
get_cache_path()
get_url()
file_to_cache()
stat()
update_cache()
copy_from_memory()
copy_from_handle()
copy_from_file()
$__midcom_class_name__
$__mgdschema_class_name__
$__object
$_use_rcs
$_use_activitystream
$_activitystream_verb
$allow_name_catenate
$autodelete_dependents
$name
$title
$location
$mimetype
$parentguid
$id
$guid
$metadata
No constants found
No protected methods found
No protected properties found
N/A
_delete_dependents()
list_parameters_domain()
list_parameters_all()
_create_attachment_location()
$__metadata
$_rcs_message
$parameter_cache
$parameter_all
$_open_handle
$_open_write_mode
N/A

Properties

$__midcom_class_name__

$__midcom_class_name__ : string

MidCOM classname

Type

string

$__mgdschema_class_name__

$__mgdschema_class_name__ : string

Midgard classname

Type

string

$__object

$__object : \midgard\portable\api\mgdobject

MgdSchema object

Type

\midgard\portable\api\mgdobject — MgdSchema object

$_use_rcs

$_use_rcs : boolean

Should the revision control system be enabled for object updates

Type

boolean

$_use_activitystream

$_use_activitystream : boolean

Should the Activity Log be enabled for object actions

Type

boolean

$_activitystream_verb

$_activitystream_verb : string

Verb to use for Activity Log. Should be an URL conforming to activitystrea.ms specification.

If left blank then this will come from the DBA action performed (update, create)

Type

string

$allow_name_catenate

$allow_name_catenate : boolean

Should it be allowed to automatically generate unique name in case of clash

Type

boolean

$autodelete_dependents

$autodelete_dependents : array

May contain a list of dbaclass => field entries. When deleting an object, these dependent objects are automatically deleted beforehand

Type

array

$name

$name : string

Filename of the attachment

Type

string

$title

$title : string

Title of the attachment

Type

string

$location

$location : string

Location of the attachment in the blob directory structure

Type

string

$mimetype

$mimetype : string

MIME type of the attachment

Type

string

$parentguid

$parentguid : string

GUID of the object the attachment is attached to

Type

string

$id

$id : integer

Local non-replication-safe database identifier

Type

integer

$guid

$guid : string

Type

string

$metadata

$metadata : \midcom_helper_metadata

the object's metadata

Type

\midcom_helper_metadata

$__metadata

$__metadata : \midcom_helper_metadata

Metadata object

Type

\midcom_helper_metadata — MidCOM metadata object

$_rcs_message

$_rcs_message : string

Change message used for RCS and the Activity Log summary

Type

string

$parameter_cache

$parameter_cache : 

Type

$parameter_all

$parameter_all : 

Type

$_open_handle

$_open_handle : resource

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

Type

resource

$_open_write_mode

$_open_write_mode : 

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

Type

Methods

__construct()

__construct(  $id = null) 

Constructor. Creates an abstraction layer for an MgdSchema object.

Parameters

$id

__get()

__get(string  $property) 

Magic getter for object property mapping

Parameters

string $property

Name of the property

__set()

__set(string  $property, mixed  $value) 

Magic setter for object property mapping

Parameters

string $property

Name of the property

mixed $value

Property value

new_query_builder()

new_query_builder() : \midcom_core_querybuilder

Shortcut for accessing MidCOM Query Builder

Returns

\midcom_core_querybuilder

The initialized instance of the query builder.

new_collector()

new_collector(string  $domain = null, mixed  $value = null) : \midcom_core_collector

Shortcut for accessing MidCOM Collector

Parameters

string $domain

The domain property of the collector instance

mixed $value

Value match for the collector instance

Returns

\midcom_core_collector

The initialized instance of the collector.

get_cached()

get_cached(mixed  $src) : static

Shortcut for accessing MidCOM object cache.

Parameters

mixed $src

GUID of object (ids work but are discouraged)

Returns

static —

Reference to the object

set_guid()

set_guid(  $guid) 

Parameters

$guid

__isset()

__isset(string  $property) 

Magic isset test for object property mapping

Parameters

string $property

Name of the property

create()

create() : boolean

API for creating a new object

Returns

boolean —

Indicating success

delete()

delete() : boolean

Delete the current object

Returns

boolean —

Indicating success

undelete()

undelete(  $guid) : boolean

Undelete object defined by a GUID

Parameters

$guid

Returns

boolean —

Indicating success

purge()

purge() : boolean

Purge the current object from database

Returns

boolean —

Indicating success

delete_tree()

delete_tree() : boolean

Delete the current object tree, starting from this object

Returns

boolean —

Indicating success

get_by_guid()

get_by_guid(string  $guid) : boolean

Parameters

string $guid

Returns

boolean —

Indicating success

get_by_id()

get_by_id(integer  $id) : boolean

Parameters

integer $id

Returns

boolean —

Indicating success

get_by_path()

get_by_path(string  $path) : boolean

Parameters

string $path

Returns

boolean —

Indicating success

get_parent()

get_parent() 

is_in_parent_tree()

is_in_parent_tree(  $root,   $id) 

Parameters

$root
$id

is_in_tree()

is_in_tree(  $root,   $id) 

Parameters

$root
$id

has_dependents()

has_dependents() 

list_children()

list_children(  $class_name) 

Parameters

$class_name

parent()

parent() 

is_object_visible_onsite()

is_object_visible_onsite() 

has_attachments()

has_attachments() 

find_attachments()

find_attachments(  $constraints) 

Parameters

$constraints

delete_attachments()

delete_attachments(  $constraints) 

Parameters

$constraints

purge_attachments()

purge_attachments(  $constraints) 

Parameters

$constraints

has_parameters()

has_parameters() 

find_parameters()

find_parameters(  $constraints) 

Parameters

$constraints

delete_parameters()

delete_parameters(  $constraints) 

Parameters

$constraints

purge_parameters()

purge_parameters(  $constraints) 

Parameters

$constraints

refresh()

refresh() 

update()

update() 

is_locked()

is_locked() 

lock()

lock() 

unlock()

unlock() 

is_approved()

is_approved() 

approve()

approve() 

unapprove()

unapprove() 

get_properties()

get_properties() 

new_reflection_property()

new_reflection_property() 

can_do()

can_do(  $privilege,   $user = null) 

Parameters

$privilege
$user

can_user_do()

can_user_do(  $privilege,   $user = null) 

Parameters

$privilege
$user

require_do()

require_do(  $privilege,   $message = null) 

Parameters

$privilege
$message

require_user_do()

require_user_do(  $privilege,   $message = null) 

Parameters

$privilege
$message

get_class_magic_default_privileges()

get_class_magic_default_privileges() 

_on_created()

_on_created() 

_on_creating()

_on_creating() : boolean

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

Returns

boolean —

True if creation may commence.

_on_deleted()

_on_deleted() 

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

_on_deleting()

_on_deleting() 

_on_loaded()

_on_loaded() 

_on_prepare_exec_query_builder()

_on_prepare_exec_query_builder(  $qb) 

Parameters

$qb

_on_prepare_new_query_builder()

_on_prepare_new_query_builder(  $qb) 

Parameters

$qb

_on_process_query_result()

_on_process_query_result(  $result) 

Parameters

$result

_on_prepare_new_collector()

_on_prepare_new_collector(  $mc) 

Parameters

$mc

_on_prepare_exec_collector()

_on_prepare_exec_collector(  $mc) 

Parameters

$mc

_on_process_collector_result()

_on_process_collector_result(  $result) 

Parameters

$result

_on_updated()

_on_updated() 

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

_on_updating()

_on_updating() 

_on_imported()

_on_imported() 

_on_importing()

_on_importing() 

disable_rcs()

disable_rcs() 

enable_rcs()

enable_rcs() 

set_rcs_message()

set_rcs_message(  $msg) 

Parameters

$msg

get_rcs_message()

get_rcs_message() 

get_parameter()

get_parameter(string  $domain, string  $name) : string

Return a parameter from the database.

No event handlers are called here yet.

Parameters

string $domain

The parameter domain.

string $name

The parameter name.

Returns

string —

The parameter value or false otherwise (remember typesafe comparisons to protect against '' strings).

list_parameters()

list_parameters(string  $domain = null) : array

List the parameters of an object. This will either list the parameters of a single domain or the complete set of parameters, depending on the value of $domain.

It delegates the actual execution to two separate helper functions.

No event handlers are called here yet.

In case of a complete query, the result will be an associative array indexed by the domain name and containing another array with parameter name/value pairs. For example:

Array
(
    [Asgard] => Array
    (
        [lang] => en_US
        [act] => view
        [actloc] => tree
    )
    [AsgardTreeHost] => Array
    (
        [selected] => host0
    )
)

If you query only a single domain, the result will be a single associative array containing the parameter name/value pairs. For example:

Array
(
    [lang] => en_US
    [act] => view
    [actloc] => tree
)

In both cases an empty Array will indicate that no parameter was found, while false will indicate a failure while querying the database.

Parameters

string $domain

The parameter domain to query, this may be null to indicate a full listing.

Returns

array —

Parameter list (see above for details) or false on failure.

set_parameter()

set_parameter(string  $domain, string  $name, string  $value) : boolean

Set a parameter to the value specified.

This is either a create or an update operation depending on whether there was already a parameter of that domain/name present, or not.

The user needs both update and parameter manipulation permission on the parent object for updates.

Parameters

string $domain

The Parameter Domain.

string $name

The Parameter name.

string $value

The Parameter value. If this is empty, the corresponding parameter is deleted.

Returns

boolean —

Indicating success.

delete_parameter()

delete_parameter(string  $domain, string  $name) : boolean

Delete a parameter.

Current implementation note: Deletion is not yet implemented in MgdSchema. Therefore we set the parameters to an empty string for now, which should have almost the same effect for most cases and thus is good enough for now. Note, that empty string parameters are filtered in the getter methods until this matter is resolved.

The user needs both update and parameter manipulation permission on the parent object for updates.

Parameters

string $domain

The Parameter Domain.

string $name

The Parameter name.

Returns

boolean —

Indicating success.

get_attachment()

get_attachment(string  $name) : \midcom_db_attachment

Retrieves an attachment by its name.

If multiple attachments match the name (should not happen in reality), the first match will be returned.

Parameters

string $name

The name of the attachment to look up.

Returns

\midcom_db_attachment

The attachment found, or false on failure.

delete_attachment()

delete_attachment(string  $name) : boolean

Delete an attachment by its name.

If multiple attachments match the name (should not happen in reality), the first match will be deleted.

Parameters

string $name

The name of the attachment to delete.

Returns

boolean —

Indicating success.

create_attachment()

create_attachment(string  $name, string  $title, string  $mimetype) : \midcom_db_attachment

Creates a new attachment at the current object and returns it for usage.

Parameters

string $name

The name of the attachment.

string $title

The title of the attachment.

string $mimetype

The MIME-Type of the attachment.

Returns

\midcom_db_attachment

The created attachment or false on failure.

get_attachment_qb()

get_attachment_qb() : \midcom_core_querybuilder

Returns a prepared query builder that is already limited to the attachments of the given object.

Returns

\midcom_core_querybuilder

The initialized instance of the query builder or false on failure.

list_attachments()

list_attachments() : array<mixed,\midcom_db_attachment>

Returns a complete list of attachments for the current object. If there are no attachments, an empty array is returned.

Returns

array<mixed,\midcom_db_attachment> —

A list of attachments

get_privileges()

get_privileges() : array<mixed,\midcom_core_privilege>

Read all privilege records and return them accordingly.

You need privilege access to get this information (midgard:read (tested during construction) and midgard:privileges) otherwise, the call will fail.

Returns

array<mixed,\midcom_core_privilege> —

A list of privilege objects or false on failure.

set_privilege()

set_privilege(mixed  $privilege, mixed  $assignee = null, integer  $value = MIDCOM_PRIVILEGE_ALLOW, string  $classname = '') : boolean

Set a privilege on an object.

This requires both midgard:update and midgard:privileges.

You can either pass a ready made privilege record or a privilege/assignee/value combination suitable for usage with create_new_privilege_object() (see there).

Parameters

mixed $privilege

Either the full privilege object (midcom_core_privilege) to set or the name of the privilege (string). If the name was specified, the other parameters must be specified as well.

mixed $assignee

A valid assignee suitable for midcom_core_privilege::set_privilege(). This defaults to the currently active user if authenticated or to 'EVERYONE' otherwise (invalid if $privilege is a midcom_core_privilege).

integer $value

The privilege value, this defaults to MIDCOM_PRIVILEGE_ALLOW (invalid if $privilege is a midcom_core_privilege).

string $classname

An optional class name to which a SELF privilege gets restricted to. Only valid for SELF privileges (invalid if $privilege is a midcom_core_privilege).

Returns

boolean —

Indicating success.

unset_privilege()

unset_privilege(mixed  $privilege, mixed  $assignee = null, string  $classname = '') : boolean

Unset a privilege on an object (e.g. set it to INHERIT).

Parameters

mixed $privilege

Either the full privilege object (midcom_core_privilege) to set or the name of the privilege (string). If the name was specified, the other parameters must be specified as well.

mixed $assignee

A valid assignee suitable for midcom_core_privilege::set_privilege(). This defaults to the currently active user if authenticated or to 'EVERYONE' otherwise (invalid if $privilege is a midcom_core_privilege).

string $classname

An optional class name to which a SELF privilege gets restricted to. Only valid for SELF privileges (invalid if $privilege is a midcom_core_privilege).

Returns

boolean —

Indicating Success.

get_privilege()

get_privilege(string  $privilege, mixed  $assignee, string  $classname = '') : \midcom_core_privilege

Looks up a privilege by its parameters.

Parameters

string $privilege

The name of the privilege.

mixed $assignee

Either a valid magic assignee (SELF, EVERYONE, USERS, ANONYMOUS), a midcom_core_user or a midcom_core_group object or subtype thereof.

string $classname

An optional class name to which a SELF privilege is restricted to.

Returns

\midcom_core_privilege

The privilege record from the database.

unset_all_privileges()

unset_all_privileges() : boolean

Unsets all privileges

Returns

boolean —

Indicating success.

create_new_privilege_object()

create_new_privilege_object(string  $name, mixed  $assignee = null, integer  $value = MIDCOM_PRIVILEGE_ALLOW, string  $classname = '') : \midcom_core_privilege

Create a new privilege object. The privilege will be initialized with the values given in the arguments, as outlined below.

This call requires the midgard:privileges privilege.

Parameters

string $name

The name of the privilege to add.

mixed $assignee

A valid assignee suitable for midcom_core_privilege::set_privilege(). This defaults to the currently active user if authenticated or to 'EVERYONE' otherwise.

integer $value

The privilege value, this defaults to MIDCOM_PRIVILEGE_ALLOW.

string $classname

An optional class name to which a SELF privilege gets restricted to. Only valid for SELF privileges.

Returns

\midcom_core_privilege

The newly created privilege record or false on failure.

get_parent_guid_uncached()

get_parent_guid_uncached() 

get_parent_guid_uncached_static()

get_parent_guid_uncached_static(  $guid,   $classname = __CLASS__) : string

Parameters

$guid
$classname

Returns

string —

Parent GUID

open()

open(string  $mode = 'w') : resource

Opens the attachment for file IO.

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.

Parameters

string $mode

The mode which should be used to open the attachment, same as the mode parameter of the PHP fopen call. This defaults to write access.

Returns

resource —

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

read()

read() : string

Read the file and return its contents

Returns

string

close()

close() 

Close 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.

safe_filename()

safe_filename(string  $filename, boolean  $force_single_extension = true) : string

Rewrite a filename to URL safe form

Parameters

string $filename

file name to rewrite

boolean $force_single_extension

force file to single extension (defaults to true)

Returns

string —

rewritten filename

get_cache_path()

get_cache_path() : string

Get the path to the document in the static cache

Returns

string

get_url()

get_url(  $attachment,   $name = null) 

Parameters

$attachment
$name

file_to_cache()

file_to_cache() 

stat()

stat() : mixed

Simple wrapper for stat() on the blob object.

Returns

mixed —

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

update_cache()

update_cache() 

copy_from_memory()

copy_from_memory(mixed  $source) : boolean

Updates the contents of the attachments with the contents given.

Parameters

mixed $source

File contents.

Returns

boolean —

Indicating success.

copy_from_handle()

copy_from_handle(resource  $source) : boolean

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

Parameters

resource $source

The handle to read from.

Returns

boolean —

Indicating success.

copy_from_file()

copy_from_file(string  $filename) : boolean

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

This is a wrapper for copy_from_handle.

Parameters

string $filename

The file to read.

Returns

boolean —

Indicating success.

_delete_dependents()

_delete_dependents() 

list_parameters_domain()

list_parameters_domain(string  $domain) : array

List the parameters of a single domain of an object.

No event handlers are called here yet.

Parameters

string $domain

The parameter domain to query.

Returns

array —

Parameter listing.

list_parameters_all()

list_parameters_all() : array

List all parameters of an object.

No event handlers are called here yet.

Returns

array —

Parameter listing

_create_attachment_location()

_create_attachment_location() : string

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

string —

An unused attachment location.