ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilECSCmsTreeSynchronizer Class Reference
+ Collaboration diagram for ilECSCmsTreeSynchronizer:

Public Member Functions

 __construct (ilECSSetting $server, int $mid, int $tree_id)
 
 getServer ()
 Get server. More...
 
 getECSTree ()
 
 getDefaultSettings ()
 Get default settings. More...
 
 getGlobalSettings ()
 get global settings More...
 
 sync ()
 Synchronize tree. More...
 

Protected Member Functions

 checkTreeUpdates (int $a_root_obj_id)
 Start tree update check. More...
 
 handleTreeUpdate (int $a_parent_ref_id, int $a_tnode_id)
 Handle tree update (recursively) More...
 
 syncNode ($tree_obj_id, $parent_id, $a_mapped=false)
 Sync node. More...
 
 syncCategory (ilECSNodeMappingAssignment $ass, $parent_id)
 Sync category. More...
 

Private Attributes

ilLogger $logger
 
ilLanguage $lng
 
ilTree $tree
 
ilECSSetting $server = null
 
int $mid
 
int $tree_id
 
ilECSCmsTree $ecs_tree = null
 
array $default_settings = array()
 
ilECSNodeMappingSettings $global_settings = null
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilECSCmsTreeSynchronizer::__construct ( ilECSSetting  $server,
int  $mid,
int  $tree_id 
)

Definition at line 40 of file class.ilECSCmsTreeSynchronizer.php.

References $DIC, $mid, $server, $tree_id, ilECSNodeMappingSettings\getInstanceByServerMid(), ILIAS\Repository\lng(), ILIAS\Repository\logger(), and ILIAS\UI\examples\Progress\Bar\server().

41  {
42  global $DIC;
43 
44  $this->logger = $DIC->logger()->wsrv();
45  $this->lng = $DIC->language();
46  $this->tree = $DIC->repositoryTree();
47 
48 
49  $this->server = $server;
50  $this->mid = $mid;
51  $this->ecs_tree = new ilECSCmsTree($tree_id);
52  $this->tree_id = $tree_id;
53 
54  $this->global_settings = ilECSNodeMappingSettings::getInstanceByServerMid($this->server->getServerId(), $this->mid);
55  }
static getInstanceByServerMid(int $a_server_id, int $a_mid)
Get instance.
server()
description: > This example shows how a Progress Bar can be rendered and updated by the server...
Definition: server.php:43
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:

Member Function Documentation

◆ checkTreeUpdates()

ilECSCmsTreeSynchronizer::checkTreeUpdates ( int  $a_root_obj_id)
protected

Start tree update check.

Definition at line 117 of file class.ilECSCmsTreeSynchronizer.php.

References $mid, $tree_id, ilECSNodeMappingAssignment\getRefId(), handleTreeUpdate(), ILIAS\Repository\logger(), and ILIAS\UI\examples\Progress\Bar\server().

Referenced by sync().

117  : void
118  {
119  if ($this->default_settings['tree_update'] === false) {
120  $this->logger->info('Tree update disabled for tree with id ' . $this->ecs_tree->getTreeId());
121  return;
122  }
123 
124  // Start recursion
125  $mapping = new ilECSNodeMappingAssignment(
126  $this->server->getServerId(),
127  $this->mid,
129  $a_root_obj_id
130  );
131  $a_root_ref_id = $mapping->getRefId();
132  if ($a_root_ref_id) {
133  $this->handleTreeUpdate($a_root_ref_id, $a_root_obj_id);
134  }
135  }
server()
description: > This example shows how a Progress Bar can be rendered and updated by the server...
Definition: server.php:43
handleTreeUpdate(int $a_parent_ref_id, int $a_tnode_id)
Handle tree update (recursively)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultSettings()

ilECSCmsTreeSynchronizer::getDefaultSettings ( )

Get default settings.

Definition at line 73 of file class.ilECSCmsTreeSynchronizer.php.

References $default_settings.

Referenced by sync().

73  : array
74  {
76  }
+ Here is the caller graph for this function:

◆ getECSTree()

ilECSCmsTreeSynchronizer::getECSTree ( )

Definition at line 65 of file class.ilECSCmsTreeSynchronizer.php.

References $ecs_tree.

◆ getGlobalSettings()

ilECSCmsTreeSynchronizer::getGlobalSettings ( )

get global settings

Definition at line 81 of file class.ilECSCmsTreeSynchronizer.php.

References $global_settings.

◆ getServer()

ilECSCmsTreeSynchronizer::getServer ( )

Get server.

Definition at line 60 of file class.ilECSCmsTreeSynchronizer.php.

References $server.

◆ handleTreeUpdate()

ilECSCmsTreeSynchronizer::handleTreeUpdate ( int  $a_parent_ref_id,
int  $a_tnode_id 
)
protected

Handle tree update (recursively)

Definition at line 140 of file class.ilECSCmsTreeSynchronizer.php.

References $mid, ilObject\_getAllReferences(), ilECSImportManager\getInstance(), ILIAS\Repository\int(), ILIAS\Repository\logger(), and ILIAS\UI\examples\Progress\Bar\server().

Referenced by checkTreeUpdates().

140  : bool
141  {
142  // Check if node is already imported at location "parent_ref_id"
143  // If not => move it
144  $cms_data = new ilECSCmsData($a_tnode_id);
145 
146  $import_obj_id = ilECSImportManager::getInstance()->lookupObjIdByContentId(
147  $this->server->getServerId(),
148  $this->mid,
149  //TODO fix this cast
150  (int) $cms_data->getCmsId()
151  );
152  if (!$import_obj_id) {
153  $this->logger->error('cms tree node not imported. tnode_id: ' . $a_tnode_id);
154  return false;
155  }
156 
157  $this->logger->info(' parent ref:' . $a_parent_ref_id . ' tnode:' . $a_tnode_id);
158  $ref_ids = ilObject::_getAllReferences($import_obj_id);
159  $import_ref_id = end($ref_ids);
160  $import_ref_id_parent = $this->tree->getParentId($import_ref_id);
161 
162  if ($a_parent_ref_id !== $import_ref_id_parent) {
163  // move node
164  $this->logger->info('Moving node ' . $a_parent_ref_id . ' to ' . $import_ref_id);
165  $this->tree->moveTree($import_ref_id, $a_parent_ref_id);
166  }
167 
168  // iterate through childs
169  $childs = $this->ecs_tree->getChilds($a_tnode_id);
170  foreach ($childs as $node) {
171  $this->handleTreeUpdate($import_ref_id, $node['child']);
172  }
173  return true;
174  }
static _getAllReferences(int $id)
get all reference ids for object ID
server()
description: > This example shows how a Progress Bar can be rendered and updated by the server...
Definition: server.php:43
static getInstance()
Get the singleton instance of this ilECSImportManager.
handleTreeUpdate(int $a_parent_ref_id, int $a_tnode_id)
Handle tree update (recursively)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sync()

ilECSCmsTreeSynchronizer::sync ( )

Synchronize tree.

Definition at line 89 of file class.ilECSCmsTreeSynchronizer.php.

References $mid, $tree_id, checkTreeUpdates(), getDefaultSettings(), ILIAS\Repository\logger(), ilECSCmsTree\lookupRootId(), ilECSNodeMappingAssignments\lookupSettings(), ILIAS\UI\examples\Progress\Bar\server(), and syncNode().

89  : bool
90  {
91  $this->default_settings = ilECSNodeMappingAssignments::lookupSettings(
92  $this->server->getServerId(),
93  $this->mid,
95  0
96  );
97 
98  // return if setting is false => no configuration done
99  if (!$this->getDefaultSettings()) {
100  $this->logger->info('No directory allocation settings. Aborting');
101  return true;
102  }
103 
104  // lookup obj id of root node
105 
106  $root_obj_id = ilECSCmsTree::lookupRootId($this->tree_id);
107  $this->syncNode($root_obj_id, 0);
108 
109  // Tree structure is up to date, now check node movements
110  $this->checkTreeUpdates($root_obj_id);
111  return true;
112  }
static lookupRootId($a_tree_id)
lookup root id
static lookupSettings(int $a_server_id, int $a_mid, int $a_tree_id, int $a_node_id)
Lookup Settings.
server()
description: > This example shows how a Progress Bar can be rendered and updated by the server...
Definition: server.php:43
getDefaultSettings()
Get default settings.
checkTreeUpdates(int $a_root_obj_id)
Start tree update check.
syncNode($tree_obj_id, $parent_id, $a_mapped=false)
Sync node.
+ Here is the call graph for this function:

◆ syncCategory()

ilECSCmsTreeSynchronizer::syncCategory ( ilECSNodeMappingAssignment  $ass,
  $parent_id 
)
protected

Sync category.

Definition at line 217 of file class.ilECSCmsTreeSynchronizer.php.

References $data, $mid, $ref_id, ilObject\_getAllReferences(), ilECSNodeMappingAssignment\getCSId(), ilECSImportManager\getInstance(), ilObjectFactory\getInstanceByRefId(), ILIAS\Repository\int(), ILIAS\Repository\lng(), ILIAS\Repository\logger(), ILIAS\UI\examples\Progress\Bar\server(), ilECSImport\setMID(), and SYSTEM_USER_ID.

Referenced by syncNode().

218  {
219  $data = new ilECSCmsData($ass->getCSId());
220 
221  // Check if node is imported => create
222  // perform title update
223  // perform position update
224  $obj_id = ilECSImportManager::getInstance()->lookupObjIdByContentId(
225  $this->server->getServerId(),
226  $this->mid,
227  //TODO fix this cast
228  (int) $data->getCmsId()
229  );
230  if ($obj_id) {
231  $refs = ilObject::_getAllReferences($obj_id);
232  $ref_id = end($refs);
233 
234 
236  if (($cat instanceof ilObject) && $this->default_settings['title_update']) {
237  $this->logger->info('Updating cms category ');
238  $this->logger->info('Title is ' . $data->getTitle());
239  $cat->deleteTranslation($this->lng->getDefaultLanguage());
240  $cat->addTranslation(
241  $data->getTitle(),
242  $cat->getLongDescription(),
243  $this->lng->getDefaultLanguage(),
244  $this->lng->getDefaultLanguage()
245  );
246  $cat->setTitle($data->getTitle());
247  $cat->update();
248  } else {
249  $this->logger->info('Updating cms category -> nothing to do');
250  }
251  return $ref_id;
252  }
253 
254  if ($this->global_settings->isEmptyContainerCreationEnabled()) {
255  $this->logger->info('Creating new cms category');
256 
257  // Create category
258  $cat = new ilObjCategory();
259  $cat->setOwner(SYSTEM_USER_ID);
260  $cat->setTitle($data->getTitle());
261  $cat->create(); // true for upload
262  $cat->createReference();
263  $cat->putInTree($parent_id);
264  $cat->setPermissions($parent_id);
265  $cat->deleteTranslation($this->lng->getDEfaultLanguage());
266  $cat->addTranslation(
267  $data->getTitle(),
268  $cat->getLongDescription(),
269  $this->lng->getDefaultLanguage(),
270  $this->lng->getDefaultLanguage()
271  );
272 
273  // set imported
274  $import = new ilECSImport(
275  $this->server->getServerId(),
276  $cat->getId()
277  );
278  $import->setMID($this->mid);
279  $import->setContentId($data->getCmsId());
280  $import->setImported(true);
281  $import->save();
282 
283  return $cat->getRefId();
284  }
285 
286  $this->logger->info('Creation of empty containers is disabled.');
287  return 0;
288  }
const SYSTEM_USER_ID
This file contains constants for PHPStan analyis, see: https://phpstan.org/config-reference#constants...
Definition: constants.php:26
static _getAllReferences(int $id)
get all reference ids for object ID
server()
description: > This example shows how a Progress Bar can be rendered and updated by the server...
Definition: server.php:43
static getInstance()
Get the singleton instance of this ilECSImportManager.
$ref_id
Definition: ltiauth.php:65
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
Storage of ECS imported objects.
Class ilObjCategory.
setMID($a_mid)
set mid
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ syncNode()

ilECSCmsTreeSynchronizer::syncNode (   $tree_obj_id,
  $parent_id,
  $a_mapped = false 
)
protected

Sync node.

Definition at line 179 of file class.ilECSCmsTreeSynchronizer.php.

References $mid, $tree_id, ilECSNodeMappingAssignment\getRefId(), ILIAS\UI\examples\Progress\Bar\server(), and syncCategory().

Referenced by sync().

179  : bool
180  {
181  $childs = $this->ecs_tree->getChilds($tree_obj_id);
182 
183  $assignment = new ilECSNodeMappingAssignment(
184  $this->server->getServerId(),
185  $this->mid,
187  $tree_obj_id
188  );
189 
190  if ($assignment->getRefId()) {
191  $parent_id = $assignment->getRefId();
192  }
193 
194  // information for deeper levels
195  if ($assignment->isMapped()) {
196  $a_mapped = true;
197  }
198 
199  if ($a_mapped) {
200  $parent_id = $this->syncCategory($assignment, $parent_id);
201  }
202 
203  // this is not necessary
204  #if($parent_id)
205  {
206  // iterate through childs
207  foreach ($childs as $node) {
208  $this->syncNode($node['child'], $parent_id, $a_mapped);
209  }
210  }
211  return true;
212  }
syncCategory(ilECSNodeMappingAssignment $ass, $parent_id)
Sync category.
server()
description: > This example shows how a Progress Bar can be rendered and updated by the server...
Definition: server.php:43
syncNode($tree_obj_id, $parent_id, $a_mapped=false)
Sync node.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $default_settings

array ilECSCmsTreeSynchronizer::$default_settings = array()
private

Definition at line 37 of file class.ilECSCmsTreeSynchronizer.php.

Referenced by getDefaultSettings().

◆ $ecs_tree

ilECSCmsTree ilECSCmsTreeSynchronizer::$ecs_tree = null
private

Definition at line 35 of file class.ilECSCmsTreeSynchronizer.php.

Referenced by getECSTree().

◆ $global_settings

ilECSNodeMappingSettings ilECSCmsTreeSynchronizer::$global_settings = null
private

Definition at line 38 of file class.ilECSCmsTreeSynchronizer.php.

Referenced by getGlobalSettings().

◆ $lng

ilLanguage ilECSCmsTreeSynchronizer::$lng
private

Definition at line 29 of file class.ilECSCmsTreeSynchronizer.php.

◆ $logger

ilLogger ilECSCmsTreeSynchronizer::$logger
private

Definition at line 28 of file class.ilECSCmsTreeSynchronizer.php.

◆ $mid

int ilECSCmsTreeSynchronizer::$mid
private

◆ $server

ilECSSetting ilECSCmsTreeSynchronizer::$server = null
private

Definition at line 32 of file class.ilECSCmsTreeSynchronizer.php.

Referenced by __construct(), and getServer().

◆ $tree

ilTree ilECSCmsTreeSynchronizer::$tree
private

Definition at line 30 of file class.ilECSCmsTreeSynchronizer.php.

◆ $tree_id

int ilECSCmsTreeSynchronizer::$tree_id
private

Definition at line 34 of file class.ilECSCmsTreeSynchronizer.php.

Referenced by __construct(), checkTreeUpdates(), sync(), and syncNode().


The documentation for this class was generated from the following file: