\Horde_History_Sql

The Horde_History_Sql class provides a method of tracking changes in Horde objects, stored in a SQL table.

Summary

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

Properties

$_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

$_db

$_db : \Horde_Db_Adapter

Horde_Db_Adapter instance to manage the history.

Type

\Horde_Db_Adapter

Methods

__construct()

__construct(string  $auth, \Horde_Db_Adapter  $db) 

Constructor.

Parameters

string $auth

The current user.

\Horde_Db_Adapter $db

The database connection.

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.

Throws

\Horde_History_Exception

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 filtered on other fields as well.

Note: For BC reasons, the results are returned keyed by the object UID, with a (fairly useless) history_id as the value. @todo This should be changed for Horde 6.

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 that have had at least one match for the given $filters. Will return empty array if none matched the criteria. If the same GUID has multiple matches withing the range requested, there is no guarantee which entry will be returned.

getActionTimestamp()

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

Returns 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

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

Throws

\Horde_History_Exception

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

Returns 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

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

Note: For BC reasons, the results are returned keyed by the object UID, with a (fairly useless) history_id as the value. @todo This should be changed for Horde 6.

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 that have had at least one match for the given $filters. Will return empty array if none matched the criteria. If the same GUID has multiple matches withing the range requested, there is no guarantee which entry will be returned.

_nextModSeq()

_nextModSeq() : integer

Increments, and returns, the modseq value.

Throws

\Horde_History_Exception

Returns

integer —

The new modseq value.