ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 131 of file class.ilOrgUnitSimpleImport.php.

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

Referenced by simpleImportElement().

131  {
132  global $DIC;
133  $tree = $DIC['tree'];
134  if($parent_ref_id != $tree->getParentId($ref_id)){
135  try{
136  $path = $tree->getPathId($parent_ref_id);
137  if(in_array($ref_id, $path)) {
138  $this->addWarning("not_movable_to_subtree", $ou_id?$ou_id:$external_id, "update");
139  } else {
140  $tree->moveTree($ref_id, $parent_ref_id);
141  }
142  }catch(Exception $e){
143  global $DIC;
144  $ilLog = $DIC['ilLog'];
145  $this->addWarning("not_movable", $ou_id?$ou_id:$external_id, "update");
146  $ilLog->write($e->getMessage()."\\n".$e->getTraceAsString());
147  error_log($e->getMessage()."\\n".$e->getTraceAsString());
148  }
149  }
150  }
$path
Definition: aliased.php:25
addWarning($lang_var, $import_id, $action=NULL)
$ref_id
Definition: sahs_server.php:39
global $DIC
+ 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.

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

13  {
14  global $DIC;
15  $lng = $DIC['lng'];
16  $this->stats = array("created" => 0, "updated" => 0, "deleted" => 0);
17  $a = file_get_contents($file_path, "r");
18  $xml = new SimpleXMLElement($a);
19 
20  if(!count($xml->OrgUnit)) {
21  $this->addError("no_orgunit",null,null);
22  return;
23  }
24 
25  foreach($xml->OrgUnit as $o){
26  $this->simpleImportElement($o);
27  }
28  }
Create styles array
The data for the language used.
addError($lang_var, $import_id, $action=NULL)
global $lng
Definition: privfeed.php:17
global $DIC
simpleImportElement(SimpleXMLElement $o)
+ Here is the call graph for this function:

◆ simpleImportElement()

ilOrgUnitSimpleImport::simpleImportElement ( SimpleXMLElement  $o)

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

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

Referenced by simpleImport().

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