This class contains various factory methods to retrieve objects from the database.

The only instance of this class you should ever use is available through $midcom->dbfactory.

package midcom.helper

 Methods

convert_midcom_to_midgard (\MidCOMDBAObject $object)

Helper function, it takes a MidCOM DBA object and converts it into an MgdSchema object.

If the conversion cannot be done for some reason, the function returns null and logs an error.

Parameters

$object

\MidCOMDBAObject&$object MidCOM DBA Object

Returns

\MidgardObjectMgdSchema Object

convert_midgard_to_midcom (\MidgardObject $object)

Helper function, it takes an MgdSchema object and converts it into a MidCOM DBA object.

If the conversion cannot be done for some reason, the function returns null and logs an error.

We also ensure that the corresponding component has been loaded.

Parameters

$object

\MidgardObject&$object MgdSchema Object

Returns

\MidCOMDBAObject

get_cached (string $classname, mixed $src)

Retrieve a reference to an object, uses in-request caching

Parameters

$classname

stringWhich DBA are we dealing with

$src

mixedGUID of object (ids work but are discouraged)

Returns

\midcom_core_dbaobjectreference to object

get_object_by_guid (string $guid)

This is a replacement for the original midgard_object_class::get_object_by_guid method, which takes the MidCOM DBA system into account.
see \http://www.midgard-project.org/documentation/php_midgard_object_class/

Parameters

$guid

stringThe object GUID.

Returns

objectA MidCOM DBA object if the set GUID is known

get_parent (\midcom_core_dbaobject $object)

Returns the the parent object.

Tries to utilize the Memcache data, loading the actual information only if it is not cached.

see \get_parent_data()
todo rethink this, IMO we should trust midgard core's get_parent and then just do the object conversion if neccessary since this can return stale objects and other nastiness

Parameters

$object

\midcom_core_dbaobjectThe DBA object we're working on

Returns

\midcom_core_dbaobjectnullParent if found, otherwise null

get_parent_data (mixed $object, string $class)

This is a helper function which determines the parent GUID for an existing GUID according to the MidCOM content tree rules.

It tries to look up the GUID in the memory cache, only if this fails, the regular content getters are invoked.

Parameters

$object

mixedEither a MidCOM DBA object instance, or a GUID string.

$class

stringclass name of object if known (so we can use get_parent_guid_uncached_static and avoid instantiating full object)

Returns

arrayThe parent GUID and class (value might be null, if this is a top level object).

import (object $unserialized_object, boolean $use_force)

Import object unserialized with midgard_replicator::unserialize()

This method does ACL checks and triggers watchers etc.

todo refactor to smaller methods
todo Add some magic to prevent importing of replication loops (see documentation/TODO for details about the potential problem)
todo Verify support for the special cases of privilege
todo Make sure older version is not imported over newer one (maybe configurable override ?)

Parameters

$unserialized_object

objectobject gotten from midgard_replicator::unserialize()

$use_force

booleanset use of force for the midcom_helper_replicator_import_object() call

Returns

booleanindicating success/failure

import_blob (\midgard_blob $unserialized_object, string $xml, boolean $use_force)

Import midgard_blob unserialized with midgard_replicator::unserialize()

This method does ACL checks and triggers watchers etc.

Parameters

$unserialized_object

\midgard_blobmidgard_blob gotten from midgard_replicator::unserialize()

$xml

stringXML the midgard_blob was unserialized from

$use_force

booleanset use of force for the midcom_helper_replicator_import_from_xml() call

Returns

booleanindicating success/failure

is_a (mixed $object, string $class)

This is a helper for emulating is_a() functionality with MidCOM DBA objects that are decorators.

This method can be used to check whether an object is of a MidCOM DBA or MgdSchema type

Parameters

$object

mixedMgdSchema or MidCOM DBA object

$class

stringClass to check the instance against

Returns

boolean

new_collector (string $classname, string $domain, mixed $value)

This function will determine the correct type of midgard_collector that has to be created.

It will also call the _on_prepare_new_collector event handler.

see \midcom_core_collector

Parameters

$classname

stringThe name of the class for which you want to create a collector.

$domain

stringThe domain property of the collector instance

$value

mixedValue match for the collector instance

Returns

\midcom_core_collectorThe initialized instance of the collector.

new_query_builder (string $classname)

This function will determine the correct type of midgard_query_builder that has to be created.

It will also call the _on_prepare_new_query_builder event handler.

see \midcom_core_querybuilder

Parameters

$classname

stringThe name of the class for which you want to create a query builder.

Returns

\midcom_core_querybuilderThe initialized instance of the query builder.

property_exists (mixed $object, string $property)

This is a helper for emulating property_exists() functionality with MidCOM DBA objects that are decorators.

This method can be used to check whether the original MgdSchema class has a given property.

Parameters

$object

mixedMgdSchema or MidCOM DBA object or class

$property

stringProperty to check for

Returns

boolean

_get_parent_candidates ($classname)

Parameters

$classname

_get_parent_guid_cached ($object_guid, $the_object, $class)

Parameters

$object_guid

$the_object

$class

_get_parent_guid_uncached (\midcom_core_dbaobject $object)

Parameters

$object

_get_parent_guid_uncached_static ($object_guid, $class_name)

Get the GUID of the object's parent.

This is done by reading up or parent property values, which will give us the parent's ID

Parameters

$object_guid

$class_name

_load_guid ($target_class, $target_property, $link_value)

Parameters

$target_class

$target_property

$link_value

 Properties

 

array $_parent_candidates

Cache for possible parent configurations per mgdschema class
 

array $_parent_mapping

ID => GUID cache for parents