1: <?php
2: /**
3: * A server delegation that logs server access via Horde_Log_Logger.
4: *
5: * PHP version 5
6: *
7: * @category Kolab
8: * @package Kolab_Server
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
11: * @link http://pear.horde.org/index.php?package=Kolab_Server
12: */
13:
14: /**
15: * A server delegation that logs server access via Horde_Log_Logger.
16: *
17: * Copyright 2008-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you
20: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
21: *
22: * @category Kolab
23: * @package Kolab_Server
24: * @author Gunnar Wrobel <wrobel@pardus.de>
25: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
26: * @link http://pear.horde.org/index.php?package=Kolab_Server
27: */
28: class Horde_Kolab_Server_Decorator_Log
29: implements Horde_Kolab_Server_Interface
30: {
31: /**
32: * The server we delegate to.
33: *
34: * @var Horde_Kolab_Server
35: */
36: private $_server;
37:
38: /**
39: * The log handler.
40: *
41: * @var mixed
42: */
43: private $_logger;
44:
45: /**
46: * Constructor.
47: *
48: * @param Horde_Kolab_Server $server The base server connection.
49: * @param mixed $logger The log handler. The class must at
50: * least provide the info() method.
51: */
52: public function __construct(
53: Horde_Kolab_Server_Interface $server,
54: $logger
55: ) {
56: $this->_server = $server;
57: $this->_logger = $logger;
58: }
59:
60: /**
61: * Connect to the server.
62: *
63: * @param string $guid The global unique id of the user.
64: * @param string $pass The password.
65: *
66: * @return NULL.
67: *
68: * @throws Horde_Kolab_Server_Exception If the connection failed.
69: */
70: public function connectGuid($guid = null, $pass = null)
71: {
72: try {
73: $this->_server->connectGuid($guid, $pass);
74: $this->_logger->info(
75: sprintf(
76: "Successfully connected to the Kolab Server as \"%s\".",
77: $guid
78: )
79: );
80: } catch (Horde_Kolab_Server_Exception $e) {
81: $this->_logger->info(
82: sprintf(
83: "Failed connecting to the Kolab Server as \"%s\"! Error: %s",
84: $guid, $e->getMessage()
85: )
86: );
87: throw $e;
88: }
89: }
90:
91: /**
92: * Get the current GUID
93: *
94: * @return string The GUID of the connected user.
95: */
96: public function getGuid()
97: {
98: return $this->_server->getGuid();
99: }
100:
101: /**
102: * Get the base GUID of this server
103: *
104: * @return string The base GUID of this server.
105: */
106: public function getBaseGuid()
107: {
108: return $this->_server->getBaseGuid();
109: }
110:
111: /**
112: * Low level access to reading object data.
113: *
114: * @param string $guid The object to retrieve.
115: * @param array $attrs Restrict to these attributes.
116: *
117: * @return array An array of attributes.
118: *
119: * @throws Horde_Kolab_Server_Exception If the search operation hit an error
120: * or returned no result.
121: */
122: public function read($guid, array $attrs = array())
123: {
124: return $this->_server->read($guid);
125: }
126:
127: /**
128: * Low level access to reading some object attributes.
129: *
130: * @param string $guid The object to retrieve.
131: * @param string $attrs Restrict to these attributes.
132: *
133: * @return array An array of attributes.
134: *
135: * @throws Horde_Kolab_Server_Exception
136: *
137: * @see Horde_Kolab_Server::read
138: */
139: public function readAttributes($guid, array $attrs)
140: {
141: return $this->_server->readAttributes($guid, $attrs);
142: }
143:
144: /**
145: * Finds object data matching a given set of criteria.
146: *
147: * @param string $query The LDAP search query
148: * @param array $params Additional search parameters.
149: *
150: * @return Horde_Kolab_Server_Result The result object.
151: *
152: * @throws Horde_Kolab_Server_Exception
153: */
154: public function find($query, array $params = array())
155: {
156: $result = $this->_server->find($query, $params);
157: $this->_logger->debug(
158: sprintf(
159: "Query %s identified %s result(s).",
160: $query, $result->count()
161: )
162: );
163: return $result;
164: }
165:
166: /**
167: * Finds all object data below a parent matching a given set of criteria.
168: *
169: * @param string $query The LDAP search query
170: * @param string $parent The parent to search below.
171: * @param array $params Additional search parameters.
172: *
173: * @return Horde_Kolab_Server_Result The result object.
174: *
175: * @throws Horde_Kolab_Server_Exception
176: */
177: public function findBelow($query, $parent, array $params = array())
178: {
179: return $this->_server->findBelow($query, $parent, $params);
180: }
181:
182: /**
183: * Modify existing object data.
184: *
185: * @param Horde_Kolab_Server_Object $object The object to be modified.
186: * @param array $data The attributes of the object
187: * to be stored.
188: *
189: * @return NULL
190: *
191: * @throws Horde_Kolab_Server_Exception
192: */
193: public function save(
194: Horde_Kolab_Server_Object_Interface $object,
195: array $data
196: ) {
197: try {
198: $this->_server->save($object, $data);
199: $this->_logger->info(
200: sprintf(
201: "The object \"%s\" has been successfully saved!",
202: $object->getGuid()
203: )
204: );
205: } catch (Horde_Kolab_Server_Exception $e) {
206: $this->_logger->info(
207: sprintf(
208: "Failed saving object \"%s\"! Error: %s",
209: $object->getGuid(), $e->getMessage()
210: )
211: );
212:
213: }
214: }
215:
216: /**
217: * Add new object data.
218: *
219: * @param Horde_Kolab_Server_Object $object The object to be added.
220: * @param array $data The attributes of the object
221: * to be added.
222: *
223: * @return NULL
224: *
225: * @throws Horde_Kolab_Server_Exception
226: */
227: public function add(
228: Horde_Kolab_Server_Object_Interface $object,
229: array $data
230: ) {
231: try {
232: $this->_server->add($object, $data);
233: $this->_logger->info(
234: sprintf(
235: "The object \"%s\" has been successfully added!",
236: $object->getGuid()
237: )
238: );
239: } catch (Horde_Kolab_Server_Exception $e) {
240: $this->_logger->info(
241: sprintf(
242: "Failed adding object \"%s\"! Error: %s",
243: $object->getGuid(), $e->getMessage()
244: )
245: );
246:
247: }
248: }
249:
250: /**
251: * Delete an object.
252: *
253: * @param string $guid The GUID of the object to be deleted.
254: *
255: * @return NULL
256: *
257: * @throws Horde_Kolab_Server_Exception
258: */
259: public function delete($guid)
260: {
261: try {
262: $this->_server->delete($guid);
263: $this->_logger->info(
264: sprintf("The object \"%s\" has been successfully deleted!", $guid)
265: );
266: } catch (Horde_Kolab_Server_Exception $e) {
267: $this->_logger->info(
268: sprintf(
269: "Failed deleting object \"%s\"! Error: %s",
270: $object->getGuid(), $e->getMessage()
271: )
272: );
273:
274: }
275:
276: }
277:
278: /**
279: * Rename an object.
280: *
281: * @param string $guid The GUID of the object to be renamed.
282: * @param string $new The new GUID of the object.
283: *
284: * @return NULL
285: *
286: * @throws Horde_Kolab_Server_Exception
287: */
288: public function rename($guid, $new)
289: {
290: try {
291: $this->_server->rename($guid, $new);
292: $this->_logger->info(
293: sprintf(
294: "The object \"%s\" has been successfully renamed to \"%s\"!",
295: $guid, $new
296: )
297: );
298: } catch (Horde_Kolab_Server_Exception $e) {
299: $this->_logger->info(
300: sprintf(
301: "Failed saving object \"%s\"! Error: %s",
302: $object->getGuid(), $e->getMessage()
303: )
304: );
305:
306: }
307: }
308:
309: /**
310: * Return the ldap schema.
311: *
312: * @return Horde_Ldap_Schema The LDAP schema.
313: *
314: * @throws Horde_Kolab_Server_Exception If retrieval of the schema failed.
315: */
316: public function getSchema()
317: {
318: return $this->_server->getSchema();
319: }
320:
321: /**
322: * Get the parent GUID of this object.
323: *
324: * @param string $guid The GUID of the child.
325: *
326: * @return string the parent GUID of this object.
327: */
328: public function getParentGuid($guid)
329: {
330: return $this->_server->getParentGuid($guid);
331: }
332: }
333: