ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
60  $dir_reader = new ilECSDirectoryTreeConnector($this->getServer());
61  $res = $dir_reader->getDirectoryTree($a_content_id);
62  $nodes = $res->getResult();
63 
64  if($this->log->isHandling(ilLogLevel::DEBUG))
65  {
66  $this->log->dump($nodes, ilLogLevel::DEBUG);
67  }
68  }
69  catch(ilECSConnectorException $e)
70  {
71  $this->log->error('Tree creation failed with mesage ' . $e->getMessage());
72  return false;
73  }
74 
75  $cms_tree = $nodes;
76  $data = new ilECSCmsData();
77  $data->setServerId($server->getServerId());
78  $data->setMid($this->mid);
79  $data->setCmsId($cms_tree->rootID);
80  $data->setTreeId($a_content_id);
81  $data->setTitle($cms_tree->directoryTreeTitle);
82  $data->setTerm($cms_tree->term);
83  $data->save();
84 
85  $tree = new ilECSCmsTree($a_content_id);
86  $tree->insertRootNode($a_content_id, $data->getObjId());
87  $tree->setRootId($data->getObjId());
88 
89 
90  foreach((array) $cms_tree->nodes as $node)
91  {
92  // Add data entry
93  $data = new ilECSCmsData();
94  $data->setServerId($this->getServer()->getServerId());
95  $data->setMid($this->mid);
96  $data->setCmsId($node->id);
97  $data->setTreeId($a_content_id);
98  $data->setTitle($node->title);
99  $data->setTerm($node->term);
100  $data->save();
101 
102  // add to tree
103  if($node->parent->id)
104  {
105  $parent_id = ilECSCmsData::lookupObjId(
106  $this->getServer()->getServerId(),
107  $this->mid,
108  $a_content_id,
109  $node->parent->id
110  );
111  $tree->insertNode($data->getObjId(), $parent_id);
112  }
113  }
114  return true;
115  }
116 
122  public function handleDelete(ilECSSetting $server, $a_content_id)
123  {
124  $this->log->debug('ECS cms tree delete');
125 
126  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
127  $data = new ilECSCmsData();
128  $data->setServerId($this->getServer()->getServerId());
129  $data->setMid($this->mid);
130  $data->setTreeId($a_content_id);
131  $data->deleteTree();
132 
133  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
134  $tree = new ilECSCmsTree($a_content_id);
135  $tree->deleteTree($tree->getNodeData(ilECSCmsTree::lookupRootId($a_content_id)));
136 
137  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignments.php';
139  $this->getServer()->getServerId(),
140  $this->mid,
141  $a_content_id
142  );
143  return true;
144  }
145 
151  public function handleUpdate(ilECSSetting $server, $a_content_id)
152  {
153  $this->log->debug('ECS cms tree update');
154 
155 
156  // 1) Mark all nodes as deleted
157  // 2a) Delete cms tree
158  // 2) Add cms tree table entries
159  // 2) Replace the cms data table entries
160  // 3) Insert deleted tree nodes in tree
161  // 4) Sync tree
162 
163  try
164  {
165  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSDirectoryTreeConnector.php';
166  $dir_reader = new ilECSDirectoryTreeConnector($this->getServer());
167  $res = $dir_reader->getDirectoryTree($a_content_id);
168  $nodes = $res->getResult();
169  if($this->log->isHandling(ilLogLevel::DEBUG))
170  {
171  $this->log->dump($nodes, ilLogLevel::DEBUG);
172  }
173 
174  }
175  catch(ilECSConnectorException $e)
176  {
177  $GLOBALS['ilLog']->write(__METHOD__.': Tree creation failed with mesage ' . $e->getMessage());
178  return false;
179  }
180 
181  // read old tree structure
182  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
183  $tree = new ilECSCmsTree($a_content_id);
184 
185  $root_node = $tree->getNodeData(ilECSCmsTree::lookupRootId($a_content_id));
186 
187  $old_nodes = array();
188  if($root_node['child'])
189  {
190  $old_nodes = $tree->getSubTree($root_node,true);
191  }
192 
193  if($this->log->isHandling(ilLogLevel::DEBUG))
194  {
195  $this->log->debug('Old tree data... ');
196  $this->log->dump($old_nodes, ilLogLevel::DEBUG);
197  }
198 
199  // Delete old cms tree
200  ilECSCmsTree::deleteByTreeId($a_content_id);
201 
202  // Mark all nodes in cms data as deleted
203  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
205  $this->getServer()->getServerId(),
206  $this->mid,
207  $a_content_id,
208  true
209  );
210 
211  // Check for update or new entry
212  $cms_tree = $nodes;
213 
214  $data_obj_id = ilECSCmsData::lookupObjId(
215  $this->getServer()->getServerId(),
216  $this->mid,
217  $a_content_id,
218  $cms_tree->rootID
219  );
220 
221  $data = new ilECSCmsData($data_obj_id);
222  $data->setServerId($server->getServerId());
223  $data->setMid($this->mid);
224  $data->setCmsId($cms_tree->rootID);
225  $data->setTreeId($a_content_id);
226  $data->setTitle($cms_tree->directoryTreeTitle);
227  $data->setTerm($cms_tree->term);
228 
229  if($data_obj_id)
230  {
231  $data->setDeleted(false);
232  $data->update();
233  }
234  else
235  {
236  $data->save();
237  }
238 
239  $tree->insertRootNode($a_content_id, $data->getObjId());
240  $tree->setRootId($data->getObjId());
241 
242 
243  foreach((array) $cms_tree->nodes as $node)
244  {
245  $data_obj_id = ilECSCmsData::lookupObjId(
246  $this->getServer()->getServerId(),
247  $this->mid,
248  $a_content_id,
249  $node->id
250  );
251 
252  // update data entry
253  $data = new ilECSCmsData($data_obj_id);
254  $data->setTitle($node->title);
255  $data->setTerm($node->term);
256  $data->setDeleted(false);
257 
258  if($data_obj_id)
259  {
260  $data->update();
261  }
262  else
263  {
264  $data->setCmsId($node->id);
265  $data->setMid($this->mid);
266  $data->setServerId($this->getServer()->getServerId());
267  $data->setTreeId($a_content_id);
268  $data->setDeleted(false);
269  $data->save();
270 
271  $data_obj_id = $data->getObjId();
272  }
273 
274  // add to tree
275  $parent_id = ilECSCmsData::lookupObjId(
276  $this->getServer()->getServerId(),
277  $this->mid,
278  $a_content_id,
279  $node->parent->id
280  );
281  $tree->insertNode($data->getObjId(), $parent_id);
282  }
283 
284  // Insert deleted nodes in tree
286  $this->getServer()->getServerId(),
287  $this->mid,
288  $a_content_id
289  );
290 
291  foreach((array) $deleted as $obj_id)
292  {
293  $parent = 0;
294  foreach((array) $old_nodes as $tmp_id => $node)
295  {
296 
297  if($node['child'] == $obj_id)
298  {
299  $parent = $node['parent'];
300  break;
301  }
302  }
303 
304  if($tree->isInTree($parent) and $parent)
305  {
306  $tree->insertNode($obj_id, $parent);
307  }
308  }
309 
310  // Sync tree
311  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTreeSynchronizer.php';
312  $sync = new ilECSCmsTreeSynchronizer(
313  $this->getServer(),
314  $this->mid,
315  $a_content_id
316  );
317  $sync->sync();
318 
319  return true;
320  }
321 
325  private function init()
326  {
327  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php';
328  $this->mid = ilECSParticipantSettings::loookupCmsMid($this->getServer()->getServerId());
329  }
330 }
331 ?>
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.
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.