ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilECSCmsTreeCommandQueueHandler.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once './Services/WebServices/ECS/interfaces/interface.ilECSCommandQueueHandler.php';
6 
13 {
17  protected $log;
18 
19  private $server = null;
20  private $mid = 0;
21 
22 
26  public function __construct(ilECSSetting $server)
27  {
28  $this->log = $GLOBALS['DIC']->logger()->wsrv();
29 
30  $this->server = $server;
31  $this->init();
32  }
33 
38  public function getServer()
39  {
40  return $this->server;
41  }
42 
43 
49  public function handleCreate(ilECSSetting $server, $a_content_id)
50  {
51  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
52  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
53  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSDirectoryTreeConnector.php';
54 
55  $this->log->debug('ECS cms tree create');
56 
57 
58  try {
59  $dir_reader = new ilECSDirectoryTreeConnector($this->getServer());
60  $res = $dir_reader->getDirectoryTree($a_content_id);
61  $nodes = $res->getResult();
62 
63  if ($this->log->isHandling(ilLogLevel::DEBUG)) {
64  $this->log->dump($nodes, ilLogLevel::DEBUG);
65  }
66  } catch (ilECSConnectorException $e) {
67  $this->log->error('Tree creation failed with mesage ' . $e->getMessage());
68  return false;
69  }
70 
71  $cms_tree = $nodes;
72  $data = new ilECSCmsData();
73  $data->setServerId($server->getServerId());
74  $data->setMid($this->mid);
75  $data->setCmsId($cms_tree->rootID);
76  $data->setTreeId($a_content_id);
77  $data->setTitle($cms_tree->directoryTreeTitle);
78  $data->setTerm($cms_tree->term);
79  $data->save();
80 
81  $tree = new ilECSCmsTree($a_content_id);
82  $tree->insertRootNode($a_content_id, $data->getObjId());
83  $tree->setRootId($data->getObjId());
84 
85 
86  foreach ((array) $cms_tree->nodes as $node) {
87  // Add data entry
88  $data = new ilECSCmsData();
89  $data->setServerId($this->getServer()->getServerId());
90  $data->setMid($this->mid);
91  $data->setCmsId($node->id);
92  $data->setTreeId($a_content_id);
93  $data->setTitle($node->title);
94  $data->setTerm($node->term);
95  $data->save();
96 
97  // add to tree
98  if ($node->parent->id) {
99  $parent_id = ilECSCmsData::lookupObjId(
100  $this->getServer()->getServerId(),
101  $this->mid,
102  $a_content_id,
103  $node->parent->id
104  );
105  $tree->insertNode($data->getObjId(), $parent_id);
106  }
107  }
108  return true;
109  }
110 
116  public function handleDelete(ilECSSetting $server, $a_content_id)
117  {
118  $this->log->debug('ECS cms tree delete');
119 
120  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
121  $data = new ilECSCmsData();
122  $data->setServerId($this->getServer()->getServerId());
123  $data->setMid($this->mid);
124  $data->setTreeId($a_content_id);
125  $data->deleteTree();
126 
127  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
128  $tree = new ilECSCmsTree($a_content_id);
129  $tree->deleteTree($tree->getNodeData(ilECSCmsTree::lookupRootId($a_content_id)));
130 
131  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignments.php';
133  $this->getServer()->getServerId(),
134  $this->mid,
135  $a_content_id
136  );
137  return true;
138  }
139 
145  public function handleUpdate(ilECSSetting $server, $a_content_id)
146  {
147  $this->log->debug('ECS cms tree update');
148 
149 
150  // 1) Mark all nodes as deleted
151  // 2a) Delete cms tree
152  // 2) Add cms tree table entries
153  // 2) Replace the cms data table entries
154  // 3) Insert deleted tree nodes in tree
155  // 4) Sync tree
156 
157  try {
158  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSDirectoryTreeConnector.php';
159  $dir_reader = new ilECSDirectoryTreeConnector($this->getServer());
160  $res = $dir_reader->getDirectoryTree($a_content_id);
161  $nodes = $res->getResult();
162  if ($this->log->isHandling(ilLogLevel::DEBUG)) {
163  $this->log->dump($nodes, ilLogLevel::DEBUG);
164  }
165  } catch (ilECSConnectorException $e) {
166  $GLOBALS['ilLog']->write(__METHOD__ . ': Tree creation failed with mesage ' . $e->getMessage());
167  return false;
168  }
169 
170  // read old tree structure
171  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
172  $tree = new ilECSCmsTree($a_content_id);
173 
174  $root_node = $tree->getNodeData(ilECSCmsTree::lookupRootId($a_content_id));
175 
176  $old_nodes = array();
177  if ($root_node['child']) {
178  $old_nodes = $tree->getSubTree($root_node, true);
179  }
180 
181  if ($this->log->isHandling(ilLogLevel::DEBUG)) {
182  $this->log->debug('Old tree data... ');
183  $this->log->dump($old_nodes, ilLogLevel::DEBUG);
184  }
185 
186  // Delete old cms tree
187  ilECSCmsTree::deleteByTreeId($a_content_id);
188 
189  // Mark all nodes in cms data as deleted
190  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
192  $this->getServer()->getServerId(),
193  $this->mid,
194  $a_content_id,
195  true
196  );
197 
198  // Check for update or new entry
199  $cms_tree = $nodes;
200 
201  $data_obj_id = ilECSCmsData::lookupObjId(
202  $this->getServer()->getServerId(),
203  $this->mid,
204  $a_content_id,
205  $cms_tree->rootID
206  );
207 
208  $data = new ilECSCmsData($data_obj_id);
209  $data->setServerId($server->getServerId());
210  $data->setMid($this->mid);
211  $data->setCmsId($cms_tree->rootID);
212  $data->setTreeId($a_content_id);
213  $data->setTitle($cms_tree->directoryTreeTitle);
214  $data->setTerm($cms_tree->term);
215 
216  if ($data_obj_id) {
217  $data->setDeleted(false);
218  $data->update();
219  } else {
220  $data->save();
221  }
222 
223  $tree->insertRootNode($a_content_id, $data->getObjId());
224  $tree->setRootId($data->getObjId());
225 
226 
227  foreach ((array) $cms_tree->nodes as $node) {
228  $data_obj_id = ilECSCmsData::lookupObjId(
229  $this->getServer()->getServerId(),
230  $this->mid,
231  $a_content_id,
232  $node->id
233  );
234 
235  // update data entry
236  $data = new ilECSCmsData($data_obj_id);
237  $data->setTitle($node->title);
238  $data->setTerm($node->term);
239  $data->setDeleted(false);
240 
241  if ($data_obj_id) {
242  $data->update();
243  } else {
244  $data->setCmsId($node->id);
245  $data->setMid($this->mid);
246  $data->setServerId($this->getServer()->getServerId());
247  $data->setTreeId($a_content_id);
248  $data->setDeleted(false);
249  $data->save();
250 
251  $data_obj_id = $data->getObjId();
252  }
253 
254  // add to tree
255  $parent_id = ilECSCmsData::lookupObjId(
256  $this->getServer()->getServerId(),
257  $this->mid,
258  $a_content_id,
259  $node->parent->id
260  );
261  $tree->insertNode($data->getObjId(), $parent_id);
262  }
263 
264  // Insert deleted nodes in tree
266  $this->getServer()->getServerId(),
267  $this->mid,
268  $a_content_id
269  );
270 
271  foreach ((array) $deleted as $obj_id) {
272  $parent = 0;
273  foreach ((array) $old_nodes as $tmp_id => $node) {
274  if ($node['child'] == $obj_id) {
275  $parent = $node['parent'];
276  break;
277  }
278  }
279 
280  if ($tree->isInTree($parent) and $parent) {
281  $tree->insertNode($obj_id, $parent);
282  }
283  }
284 
285  // Sync tree
286  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTreeSynchronizer.php';
288  $this->getServer(),
289  $this->mid,
290  $a_content_id
291  );
292  $sync->sync();
293 
294  return true;
295  }
296 
300  private function init()
301  {
302  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php';
303  $this->mid = ilECSParticipantSettings::loookupCmsMid($this->getServer()->getServerId());
304  }
305 }
static writeAllDeleted($a_server_id, $a_mid, $a_tree_id, $a_deleted_flag)
Write deleted status.
static lookupObjId($a_server_id, $a_mid, $a_tree_id, $cms_id)
getServerId()
Get current server id.
static lookupRootId($a_tree_id)
lookup root id
handleDelete(ilECSSetting $server, $a_content_id)
Handle delete.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static deleteMappings($a_server_id, $a_mid, $a_tree_id)
Delete mappings $ilDB $ilDB.
handleUpdate(ilECSSetting $server, $a_content_id)
Handle update.
Interface for all command queue handler classes.
foreach($_POST as $key=> $value) $res
$sync
handleCreate(ilECSSetting $server, $a_content_id)
Handle create.
Create styles array
The data for the language used.
static loookupCmsMid($a_server_id)
Lookup mid of current cms participant $ilDB.
static findDeletedNodes($a_server_id, $a_mid, $a_tree_id)
Find deleted nodes Uses a left join since this is more robust.
static deleteByTreeId($a_tree_id)
Delete tree by tree_id.
__construct(ilECSSetting $server)
Constructor.