\documentclass{article}
\usepackage{ulem}
\pagestyle{headings}
\begin{document}
\tableofcontents

Horde\_HistoryGeneral UsageUsage inside Horde applications

\part{Horde\_History}
Horde\_History is a library to track and find change events for arbitrary resources. Histories can be saved to SQL or MongoDb\footnote{http://example.com/index.php?page=MongoDb}, a Composite backend also exists.\newline
Possible use cases are sync protocols, undo/rewind features or human consumable history information. The Horde\_Activesync implementation uses Horde\_Histories to track create/delete/update events of syncable items.

\section{General Usage}
Create an implementation of the Horde\_History class and fulfill its dependencies\newline
\begin{verbatim}
$history = new Horde_History_Sql($username, Horde_Db_Adapter $db);
\end{verbatim}

Log events related to a \$guid identifying the resource tracked

\begin{verbatim}

$history->log('room1:shelf1:item100', array(
        'who' => 'someuser', // defaults to the user provided at construction of the object
        'action' => 'create',
   ));

$history->log('room1:shelf1:item100', array(
        'who' => 'someotheruser', // defaults to the user provided at construction of the object
        'action' => 'modify',
        'ts' => 1287666089, // Defaults to now,
        'desc' => 'Human Readble Description'
   ));

$history->log('room1:shelf1:item100', array('action' => 'delete'));
\end{verbatim}

Retrieve the whole history of some guid\newline
\begin{verbatim}

$log = $history->getHistory("room1:shelf1:item100"); // returns a Horde_History_Log object
\end{verbatim}

Retrieve the list of history items compared to a certain timestamp

\begin{verbatim}

$ids = $history->getByTimestamp('>=', 1287666089); // returns an array of integers
\end{verbatim}

Or add filters\newline
\begin{verbatim}

$ids = $history->getByTimestamp('>=', 1287666089, array(
    array('action', '==', 'delete')
    )
); // returns an array of integers
\end{verbatim}

Get events between some changesets, allowing filters

\begin{verbatim}

$ids = $history->getByModSeq(1287, 1305);
 // returns an array of integers

$ids = $history->getByModSeq(1287, 1305, array(array('action', '==', 'create')));
 // returns an array of integers
\end{verbatim}

Limit to events within a parent resource\newline
\begin{verbatim}

$ids = $history->getByModSeq(12876, 1305, array(), 'room1:shelf1');
 // returns an array of integers

$ids = $history->getByModSeq(12876, 1305, array(array('action', '==', 'create')), 'room1:shelf1');
 // returns an array of integers
\end{verbatim}

Get the last time a certain action happened to a resource

\begin{verbatim}

$ts = $history->getActionTimestamp('room1:shelf1', 'createitem');
\end{verbatim}

Remove all histories for a certain parent guid, for example because a collection gets deleted

\begin{verbatim}

$history->removeByParent('room12');
\end{verbatim}

Or remove a list of guids from history (not including child resources)

\begin{verbatim}

$history->removeByNames(array('room12:shelf1', 'room12:shelf2', 'room12:shelf3'));
\end{verbatim}

Get the last change to any child guid below a parent guid\newline
\begin{verbatim}

$modseq = $history->getHighestModSeq('room1');
\end{verbatim}

Get the latest entry for a guid by modseq\newline
\begin{verbatim}

$entry = $history->getLatestEntry('room1');
\end{verbatim}

or by timestamp\newline
\begin{verbatim}

$entry = $history->getLatestEntry('room1', true);
\end{verbatim}

\section{Usage inside Horde applications}
Use the Injector to get a configured instance of Horde\_Core\_History.

\begin{verbatim}

$history = $GLOBALS['injector']->getInstance('Horde_History');
\end{verbatim}

Horde\_Core\_History wraps Horde\_History instances. It defaults to the logged in user and delegates most calls to the actual backends.


\noindent\rule{\textwidth}{1pt}
Back to the ((Project|Project List)

\end{document}
