1: <?php
2: /**
3: * The Horde_SyncMl_Command_Map class provides a SyncML implementation of the
4: * Map command as defined in SyncML Representation Protocol, version 1.1,
5: * section 5.5.8.
6: *
7: * The Map command is used to update identifier maps.
8: *
9: * Copyright 2004-2012 Horde LLC (http://www.horde.org/)
10: *
11: * See the enclosed file COPYING for license information (LGPL). If you
12: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
13: *
14: * @author Karsten Fourmont <karsten@horde.org>
15: * @author Jan Schneider <jan@horde.org>
16: * @package SyncMl
17: */
18: class Horde_SyncMl_Command_Map extends Horde_SyncMl_Command
19: {
20: /**
21: * Name of the command.
22: *
23: * @var string
24: */
25: protected $_cmdName = 'Map';
26:
27: /**
28: * Source database of the Map command.
29: *
30: * @var string
31: */
32: protected $_sourceLocURI;
33:
34: /**
35: * Target database of the Map command.
36: *
37: * @var string
38: */
39: protected $_targetLocURI;
40:
41: /**
42: * Recipient map item specifiers.
43: *
44: * @var array
45: */
46: protected $_mapTargets = array();
47:
48: /**
49: * Originator map item specifiers.
50: *
51: * @var array
52: */
53: protected $_mapSources = array();
54:
55: /**
56: * End element handler for the XML parser, delegated from
57: * Horde_SyncMl_ContentHandler::endElement().
58: *
59: * @param string $uri The namespace URI of the element.
60: * @param string $element The element tag name.
61: */
62: public function endElement($uri, $element)
63: {
64: switch (count($this->_stack)) {
65: case 3:
66: if ($element == 'LocURI') {
67: if ($this->_stack[1] == 'Source') {
68: $this->_sourceLocURI = trim($this->_chars);
69: } elseif ($this->_stack[1] == 'Target') {
70: $this->_targetLocURI = trim($this->_chars);
71: }
72: }
73: break;
74:
75: case 4:
76: if ($element == 'LocURI') {
77: if ($this->_stack[2] == 'Source') {
78: $this->_mapSources[] = trim($this->_chars);
79: } elseif ($this->_stack[2] == 'Target') {
80: $this->_mapTargets[] = trim($this->_chars);
81: }
82: }
83: break;
84: }
85:
86: parent::endElement($uri, $element);
87: }
88:
89: /**
90: * Implements the actual business logic of the Alert command.
91: *
92: * @todo No OK response on error.
93: */
94: public function handleCommand($debug = false)
95: {
96: if (!$debug && $this->_mapSources) {
97: $state = $GLOBALS['backend']->state;
98: $sync = &$state->getSync($this->_targetLocURI);
99: if (!$state->authenticated) {
100: $GLOBALS['backend']->logMessage(
101: 'Not authenticated while processing <Map>', 'ERR');
102: } else {
103: foreach ($this->_mapSources as $key => $source) {
104: $sync->createUidMap($this->_targetLocURI,
105: $source,
106: $this->_mapTargets[$key]);
107: }
108: }
109: }
110:
111: // Create status response.
112: $this->_outputHandler->outputStatus($this->_cmdID, $this->_cmdName,
113: Horde_SyncMl::RESPONSE_OK,
114: $this->_targetLocURI,
115: $this->_sourceLocURI);
116: }
117: }
118: