/
HistoryPrefix.php
94 lines (84 loc) · 2.82 KB
/
HistoryPrefix.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* History system prefix generator for use with Kolab_Storage.
*
* @author Thomas Jarosch <thomas.jarosch@intra2net.com>
* @author Michael J Rubinsky <mrubinsk@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Kolab_Storage
*/
/**
* @author Thomas Jarosch <thomas.jarosch@intra2net.com>
* @author Michael J Rubinsky <mrubinsk@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Kolab_Storage
*/
class Horde_Core_Kolab_Storage_HistoryPrefix
implements Horde_Kolab_Storage_HistoryPrefix
{
protected static $_mapping;
/**
* Generate a prefix for the History system for the given Kolab data.
*
* @param Horde_Kolab_Storage_Data $data The data object.
*
* @return string The History prefix.
*/
public static function getPrefix(Horde_Kolab_Storage_Data $data)
{
$app = self::_type2app($data->getType());
if (empty($app)) {
Horde::log(sprintf(
'Unsupported app type: %s', $data->getType()), 'WARN');
return false;
}
// Determine share id
$user = $data->getAuth();
$folder = $data->getPath();
$share_id = '';
$all_shares = $GLOBALS['injector']
->getInstance('Horde_Core_Factory_Share')
->create($app)
->listAllShares();
foreach($all_shares as $id => $share) {
if ($folder == $share->get('folder')) {
$share_id = $id;
break;
}
}
// Bail out if we are unable to determine the share id.
if (empty($share_id)) {
Horde::log(
sprintf('HISTORY: share_id not found. Can\'t compute history prefix for user: %s, folder: %s', $user, $folder),
'WARN'
);
return false;
}
return $app . ':' . $share_id . ':';
}
/**
* Map Kolab object type to horde application name.
*
* @param string $type Kolab object type
*
* @return string The horde application name of false if not known.
*/
protected static function _type2app($type)
{
global $registry;
if (!isset(self::$_mapping)) {
self::$_mapping = array(
'contact' => $registry->hasInterface('contacts'),
'distribution-list' => $registry->hasInterface('contacts'),
'event' => $registry->hasInterface('calendar'),
'note' => $registry->hasInterface('notes'),
'task' => $registry->hasInterface('tasks')
);
}
return !empty(self::$_mapping[$type])
? self::$_mapping[$type]
: false;
}
}