\Horde_History_Mock

The Horde_History_Mock class provides a method of tracking changes in Horde objects, stored in memory.

Summary

Methods
Properties
Constants
__construct()
setLogger()
setCache()
log()
getHistory()
_getHistory()
getByTimestamp()
getByModSeq()
_getByTimestamp()
getActionTimestamp()
removeByParent()
removeByNames()
getHighestModSeq()
getActionModSeq()
getLatestEntry()
$getCount
No constants found
_log()
_getByModSeq()
$_auth
$_cache
$_logger
N/A
No private methods found
$_data
$_id
$_modseq
N/A

Properties

$getCount

$getCount : integer

Counts how often _getHistory() is called.

Used for testing caching.

Type

integer

$_auth

$_auth : string

The current user.

Type

string

$_cache

$_cache : \Horde_Cache

Cache driver object.

Type

\Horde_Cache

$_logger

$_logger : \Horde_Log_Logger

Our log handler.

Type

\Horde_Log_Logger

$_data

$_data : array

Our storage location.

Type

array

$_id

$_id : integer

The next id.

Type

integer

$_modseq

$_modseq : integer

The next modseq

Type

integer

Methods

__construct()

__construct(string  $auth) 

Constructor.

Parameters

string $auth

The current user.

setLogger()

setLogger(\Horde_Log_Logger  $logger) : NULL

Set the log handler.

Parameters

\Horde_Log_Logger $logger

The log handler.

Returns

NULL

setCache()

setCache(\Horde_Cache  $cache) 

Set Cache object.

Parameters

\Horde_Cache $cache

The cache instance.

log()

log(string  $guid, array  $attributes = array(), boolean  $replaceAction = false) 

Logs an event to an item's history log.

The item must be uniquely identified by $guid. Any other details about the event are passed in $attributes. Standard suggested attributes are:

  • who: The id of the user that performed the action (will be added automatically if not present).
  • ts: Timestamp of the action (this will be added automatically if it is not present).

Parameters

string $guid

The unique identifier of the entry to add to.

array $attributes

The hash of name => value entries that describe this event.

boolean $replaceAction

If $attributes['action'] is already present in the item's history log, update that entry instead of creating a new one.

Throws

\Horde_History_Exception

getHistory()

getHistory(string  $guid) : \Horde_History_Log

Returns a Horde_History_Log corresponding to the named history entry, with the data retrieved appropriately.

Parameters

string $guid

The name of the history entry to retrieve.

Throws

\Horde_History_Exception

Returns

\Horde_History_Log

A Horde_History_Log object.

_getHistory()

_getHistory(string  $guid) : \Horde_History_Log

Returns a Horde_History_Log corresponding to the named history entry, with the data retrieved appropriately.

Parameters

string $guid

The name of the history entry to retrieve.

Returns

\Horde_History_Log

A Horde_History_Log object.

getByTimestamp()

getByTimestamp(string  $cmp, integer  $ts, array  $filters = array(), string  $parent = null) : array

Finds history objects by timestamp, and optionally filter on other fields as well.

Parameters

string $cmp

The comparison operator (<, >, <=, >=, or =) to check the timestamps with.

integer $ts

The timestamp to compare against.

array $filters

An array of additional (ANDed) criteria. Each array value should be an array with 3 entries:

  • field: the history field being compared (i.e. 'action').
  • op: the operator to compare this field with.
  • value: the value to check for (i.e. 'add').
string $parent

The parent history to start searching at. If non-empty, will be searched for with a LIKE '$parent:%' clause.

Throws

\Horde_History_Exception

Returns

array —

An array of history object ids, or an empty array if none matched the criteria.

getByModSeq()

getByModSeq(integer  $start, integer  $end, array  $filters = array(), string  $parent = null) : array

Return history objects with changes during a modseq interval, and optionally filtered on other fields as well.

Parameters

integer $start

The (exclusive) start of the modseq range.

integer $end

The (inclusive) end of the modseq range.

array $filters

An array of additional (ANDed) criteria. Each array value should be an array with 3 entries:

  • field: the history field being compared (i.e. 'action').
  • op: the operator to compare this field with.
  • value: the value to check for (i.e. 'add').
string $parent

The parent history to start searching at. If non-empty, will be searched for with a LIKE '$parent:%' clause.

Returns

array —

An array of history object ids, or an empty array if none matched the criteria.

_getByTimestamp()

_getByTimestamp(string  $cmp, integer  $ts, array  $filters = array(), string  $parent = null) : array

Finds history objects by timestamp, and optionally filter on other fields as well.

Parameters

string $cmp

The comparison operator (<, >, <=, >=, or =) to check the timestamps with.

integer $ts

The timestamp to compare against.

array $filters

An array of additional (ANDed) criteria. Each array value should be an array with 3 entries:

  • field: the history field being compared (i.e. 'action').
  • op: the operator to compare this field with.
  • value: the value to check for (i.e. 'add').
string $parent

The parent history to start searching at. If non-empty, will be searched for with a LIKE '$parent:%' clause.

Throws

\Horde_History_Exception

Returns

array —

An array of history object ids, or an empty array if none matched the criteria.

getActionTimestamp()

getActionTimestamp(string  $guid, string  $action) : integer

Gets the timestamp of the most recent change to $guid.

Parameters

string $guid

The name of the history entry to retrieve.

string $action

An action: 'add', 'modify', 'delete', etc.

Throws

\Horde_History_Exception

Returns

integer —

The timestamp, or 0 if no matching entry is found.

removeByParent()

removeByParent(string  $parent) 

Remove one or more history entries by parent.

Parameters

string $parent

The parent name to remove.

Throws

\Horde_History_Exception

removeByNames()

removeByNames(array  $names) 

Removes one or more history entries by name.

Parameters

array $names

The history entries to remove.

Throws

\Horde_History_Exception

getHighestModSeq()

getHighestModSeq(string  $parent = null) : integer|boolean

Return the current value of the modseq. We take the MAX of the horde_histories table instead of the value of the horde_histories_modseq table to ensure we never miss an entry if we query the history system between the time we call nextModSeq() and the time the new entry is written.

Parameters

string $parent

Restrict to entries a specific parent.

Returns

integer|boolean —

The highest used modseq value, false if no history.

getActionModSeq()

getActionModSeq(string  $guid, string  $action) : integer

Gets the modseq of the most recent change to $guid

Parameters

string $guid

The name of the history entry to retrieve.

string $action

An action: 'add', 'modify', 'delete', etc.

Throws

\Horde_History_Exception

Returns

integer —

The modseq, or 0 if no matching entry is found.

getLatestEntry()

getLatestEntry(string  $guid, boolean  $use_ts = false) : array|boolean

Gets the latest entry of $guid

Parameters

string $guid

The name of the history entry to retrieve.

boolean $use_ts

If false we use the 'modseq' field to determine the latest entry. If true we use the timestamp instead of modseq to determine the latest entry. Note: Only 'modseq' can give a definitive answer.

Throws

\Horde_History_Exception

Returns

array|boolean —

The latest history entry, or false if $guid does not exist.

_log()

_log(\Horde_History_Log  $history, array  $attributes, boolean  $replaceAction = false) 

Logs an event to an item's history log. Any other details about the event are passed in $attributes.

Parameters

\Horde_History_Log $history

The history item to add to.

array $attributes

The hash of name => value entries that describe this event.

boolean $replaceAction

If $attributes['action'] is already present in the item's history log, update that entry instead of creating a new one.

Throws

\Horde_History_Exception

_getByModSeq()

_getByModSeq(integer  $start, integer  $end, array  $filters = array(), string  $parent = null) : array

Return history objects with changes during a modseq interval, and optionally filtered on other fields as well.

Parameters

integer $start

The start of the modseq range.

integer $end

The end of the modseq range.

array $filters

An array of additional (ANDed) criteria. Each array value should be an array with 3 entries:

  • field: the history field being compared (i.e. 'action').
  • op: the operator to compare this field with.
  • value: the value to check for (i.e. 'add').
string $parent

The parent history to start searching at. If non-empty, will be searched for with a LIKE '$parent:%' clause.

Returns

array —

An array of history object ids, or an empty array if none matched the criteria.