\documentclass{article}
\usepackage{ulem}
\usepackage{graphicx}
\usepackage{hyperref}
\pagestyle{headings}
\begin{document}
\part{Horde\_History}
Horde\_History is a library to track and find change events for arbitrary resources. Histories can be saved to SQL or <a href="https://wiki.horde.org/MongoDb">MongoDb</a>, a Composite backend also exists.<br />
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

<pre><code>\$history = new Horde\_History\_Sql(\$username, Horde\_Db\_Adapter \$db);
</code></pre>
Log events related to a \$guid identifying the resource tracked

<pre><code>
\$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'));
</code></pre>
Retrieve the whole history of some guid

<pre><code>
\$log = \$history->getHistory("room1:shelf1:item100"); // returns a Horde\_History\_Log object
</code></pre>
Retrieve the list of history items compared to a certain timestamp

<pre><code>
\$ids = \$history->getByTimestamp('>=', 1287666089); // returns an array of integers
</code></pre>
Or add filters

<pre><code>
\$ids = \$history->getByTimestamp('>=', 1287666089, array(
    array('action', '==', 'delete')
    )
); // returns an array of integers
</code></pre>
Get events between some changesets, allowing filters

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

\$ids = \$history->getByModSeq(1287, 1305, array(array('action', '==', 'create')));
 // returns an array of integers
</code></pre>
Limit to events within a parent resource

<pre><code>
\$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
</code></pre>
Get the last time a certain action happened to a resource

<pre><code>
\$ts = \$history->getActionTimestamp('room1:shelf1', 'createitem');
</code></pre>
Remove all histories for a certain parent guid, for example because a collection gets deleted

<pre><code>
\$history->removeByParent('room12');
</code></pre>
Or remove a list of guids from history (not including child resources)

<pre><code>
\$history->removeByNames(array('room12:shelf1', 'room12:shelf2', 'room12:shelf3'));
</code></pre>
Get the last change to any child guid below a parent guid

<pre><code>
\$modseq = \$history->getHighestModSeq('room1');
</code></pre>
Get the latest entry for a guid by modseq

<pre><code>
\$entry = \$history->getLatestEntry('room1');
</code></pre>
or by timestamp

<pre><code>
\$entry = \$history->getLatestEntry('room1', true);
</code></pre>
\section{Usage inside Horde applications}
Use the Injector to get a configured instance of Horde\_Core\_History.

<pre><code>
\$history = \$GLOBALS['injector']->getInstance('Horde\_History');
</code></pre>
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}
