ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilOrgUnitSimpleImport Class Reference

Class ilOrgUnitSimpleImport. More...

+ Inheritance diagram for ilOrgUnitSimpleImport:
+ Collaboration diagram for ilOrgUnitSimpleImport:

Public Member Functions

 simpleImport ($file_path)
 
 simpleImportElement (SimpleXMLElement $o)
 
- Public Member Functions inherited from ilOrgUnitImporter
 hasErrors ()
 
 hasWarnings ()
 
 addWarning ($lang_var, $import_id, $action=NULL)
 
 addError ($lang_var, $import_id, $action=NULL)
 
 getErrors ()
 
 getWarnings ()
 
 getStats ()
 
 importXmlRepresentation ($a_entity, $a_id, $a_xml, $a_mapping)
 
- Public Member Functions inherited from ilXmlImporter
 __construct ()
 Constructor. More...
 
 setImport ($a_val)
 Set import. More...
 
 getImport ()
 Get import. More...
 
 init ()
 Init. More...
 
 setInstallId ($a_val)
 Set installation id. More...
 
 getInstallId ()
 Get installation id. More...
 
 setInstallUrl ($a_val)
 Set installation url. More...
 
 getInstallUrl ()
 Get installation url. More...
 
 setSchemaVersion ($a_val)
 Set schema version. More...
 
 getSchemaVersion ()
 Get schema version. More...
 
 setImportDirectory ($a_val)
 Set import directory. More...
 
 getImportDirectory ()
 Get import directory. More...
 
 setSkipEntities ($a_val)
 Set skip entities. More...
 
 getSkipEntities ()
 Get skip entities. More...
 
 exportedFromSameInstallation ()
 Is exporting and importing installation identical? More...
 
 importXmlRepresentation ($a_entity, $a_id, $a_xml, $a_mapping)
 Import xml representation. More...
 
 finalProcessing ($a_mapping)
 Final processing. More...
 
 afterContainerImportProcessing (ilImportMapping $mapping)
 Called after all container objects have been implemented. More...
 

Protected Member Functions

 moveObject ($ref_id, $parent_ref_id, $ou_id, $external_id)
 
- Protected Member Functions inherited from ilOrgUnitImporter
 buildRef ($id, $type)
 

Additional Inherited Members

- Data Fields inherited from ilOrgUnitImporter
 $errors
 
 $warnings
 
 $stats
 
- Protected Attributes inherited from ilXmlImporter
 $skip_entities = array()
 
 $imp
 

Detailed Description

Member Function Documentation

◆ moveObject()

ilOrgUnitSimpleImport::moveObject (   $ref_id,
  $parent_ref_id,
  $ou_id,
  $external_id 
)
protected
Parameters
$ref_idint
$parent_ref_idint
$ou_idmixed This is only needed for displaying the warning.
$external_idmixed This is only needed for displaying the warning.

Definition at line 127 of file class.ilOrgUnitSimpleImport.php.

127 {
128 global $tree;
129 if($parent_ref_id != $tree->getParentId($ref_id)){
130 try{
131 $path = $tree->getPathId($parent_ref_id);
132 if(in_array($ref_id, $path)) {
133 $this->addWarning("not_movable_to_subtree", $ou_id?$ou_id:$external_id, "update");
134 } else {
135 $tree->moveTree($ref_id, $parent_ref_id);
136 }
137 }catch(Exception $e){
138 global $ilLog;
139 $this->addWarning("not_movable", $ou_id?$ou_id:$external_id, "update");
140 $ilLog->write($e->getMessage()."\\n".$e->getTraceAsString());
141 error_log($e->getMessage()."\\n".$e->getTraceAsString());
142 }
143 }
144 }
addWarning($lang_var, $import_id, $action=NULL)
$ref_id
Definition: sahs_server.php:39
$path
Definition: index.php:22

References $ilLog, $path, $ref_id, ilOrgUnitImporter\addWarning(), and Monolog\Handler\error_log().

Referenced by simpleImportElement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ simpleImport()

ilOrgUnitSimpleImport::simpleImport (   $file_path)

Definition at line 13 of file class.ilOrgUnitSimpleImport.php.

13 {
14 global $lng;
15 $this->stats = array("created" => 0, "updated" => 0, "deleted" => 0);
16 $a = file_get_contents($file_path, "r");
17 $xml = new SimpleXMLElement($a);
18
19 if(!count($xml->OrgUnit)) {
20 $this->addError("no_orgunit",null,null);
21 return;
22 }
23
24 foreach($xml->OrgUnit as $o){
25 $this->simpleImportElement($o);
26 }
27 }
addError($lang_var, $import_id, $action=NULL)
simpleImportElement(SimpleXMLElement $o)
global $lng
Definition: privfeed.php:40

References $lng, ilOrgUnitImporter\addError(), and simpleImportElement().

+ Here is the call graph for this function:

◆ simpleImportElement()

ilOrgUnitSimpleImport::simpleImportElement ( SimpleXMLElement  $o)

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

29 {
30 global $tree, $tpl, $ilUser;
31 $title = $o->title;
32 $description = $o->description;
33 $external_id = $o->external_id;
34 $create_mode = true;
35 $attributes = $o->attributes();
36 $action = (string)$attributes->action;
37 $ou_id = (string)$attributes->ou_id;
38 $ou_id_type = (string)$attributes->ou_id_type;
39 $ou_parent_id = (string)$attributes->ou_parent_id;
40 $ou_parent_id_type = (string)$attributes->ou_parent_id_type;
41
42 if($ou_id == ilObjOrgUnit::getRootOrgRefId()){
43 $this->addWarning("cannot_change_root_node", $ou_id?$ou_id:$external_id, $action);
44 return;
45 }
46
47 if($ou_parent_id == "__ILIAS"){
48 $ou_parent_id = ilObjOrgUnit::getRootOrgRefId();
49 $ou_parent_id_type = "reference_id";
50 }
51
52 $ref_id = $this->buildRef($ou_id, $ou_id_type);
53 $parent_ref_id = $this->buildRef($ou_parent_id, $ou_parent_id_type);
54
55 if($action == "delete"){
56 if(!$parent_ref_id){
57 $this->addError("ou_parent_id_not_valid", $ou_id?$ou_id:$external_id, $action);
58 return;
59 }
60 if(!$ref_id){
61 $this->addError("ou_id_not_valid", $ou_id?$ou_id:$external_id, $action);
62 return;
63 }
64 include_once("./Services/Repository/classes/class.ilRepUtil.php");
65 $ru = new ilRepUtil($this);
66 try{
67 $ru->deleteObjects($parent_ref_id, array($ref_id)) !== false;
68 $this->stats["deleted"]++;
69 }catch(Exception $e){
70 $this->addWarning("orgu_already_deleted", $ou_id?$ou_id:$external_id, $action);
71 }
72 return;
73 }elseif($action == "update"){
74 if(!$parent_ref_id){
75 $this->addError("ou_parent_id_not_valid", $ou_id?$ou_id:$external_id, $action);
76 return;
77 }
78 if(!$ref_id){
79 $this->addError("ou_id_not_valid", $ou_id?$ou_id:$external_id, $action);
80 return;
81 }
82 $object = new ilObjOrgUnit($ref_id);
83 $object->setTitle($title);
84
85 $arrTranslations = $object->getTranslations();
86 $object->updateTranslation($title,$description,$ilUser->getLanguage(),"");
87
88 $object->setDescription($description);
89 $object->update();
90 $object->setImportId($external_id);
91 $this->moveObject($ref_id, $parent_ref_id, $ou_id, $external_id);
92
93 $this->stats["updated"]++;
94 }elseif($action == "create"){
95 if(!$parent_ref_id){
96 $this->addError("ou_parent_id_not_valid", $ou_id?$ou_id:$external_id, $action);
97 return;
98 }
99 if($external_id){
100 $obj_id = ilObject::_lookupObjIdByImportId($external_id);
101 if(ilObject::_hasUntrashedReference($obj_id) && ilObject::_lookupType($obj_id) == 'orgu')
102 {
103 $this->addError("ou_external_id_exists", $ou_id?$ou_id:$external_id, $action);
104 return;
105 }
106 }
107 $object = new ilObjOrgUnit();
108 $object->setTitle($title);
109 $object->setDescription($description);
110 $object->setImportId($external_id);
111 $object->create();
112 $object->createReference();
113 $object->putInTree($parent_ref_id);
114 $object->setPermissions($ou_parent_id);
115 $this->stats["created"]++;
116 }else{
117 $this->addError("no_valid_action_given", $ou_id, $action);
118 }
119 }
global $tpl
Definition: ilias.php:8
Class ilObjOrgUnit.
static getRootOrgRefId()
_hasUntrashedReference($a_obj_id)
checks wether an object has at least one reference that is not in trash
static _lookupObjIdByImportId($a_import_id)
static _lookupType($a_id, $a_reference=false)
lookup object type
moveObject($ref_id, $parent_ref_id, $ou_id, $external_id)
Repository Utilities (application layer, put GUI related stuff into ilRepUtilGUI)
global $ilUser
Definition: imgupload.php:15

References $ilUser, $ref_id, $tpl, ilObject\_hasUntrashedReference(), ilObject\_lookupObjIdByImportId(), ilObject\_lookupType(), ilOrgUnitImporter\addError(), ilOrgUnitImporter\addWarning(), ilOrgUnitImporter\buildRef(), ilObjOrgUnit\getRootOrgRefId(), and moveObject().

Referenced by simpleImport().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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