ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
 hasMoreThanOneMatch ($external_id)
 
 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 143 of file class.ilOrgUnitSimpleImport.php.

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

Referenced by simpleImportElement().

144  {
145  global $DIC;
146  $tree = $DIC['tree'];
147  if ($parent_ref_id != $tree->getParentId($ref_id)) {
148  try {
149  $path = $tree->getPathId($parent_ref_id);
150  if (in_array($ref_id, $path)) {
151  $this->addWarning("not_movable_to_subtree", $ou_id?$ou_id:$external_id, "update");
152  } else {
153  $tree->moveTree($ref_id, $parent_ref_id);
154  }
155  } catch (Exception $e) {
156  global $DIC;
157  $ilLog = $DIC['ilLog'];
158  $this->addWarning("not_movable", $ou_id?$ou_id:$external_id, "update");
159  $ilLog->write($e->getMessage() . "\\n" . $e->getTraceAsString());
160  error_log($e->getMessage() . "\\n" . $e->getTraceAsString());
161  }
162  }
163  }
$path
Definition: aliased.php:25
global $DIC
Definition: saml.php:7
addWarning($lang_var, $import_id, $action=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ simpleImport()

ilOrgUnitSimpleImport::simpleImport (   $file_path)

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

References $DIC, $lng, $xml, ilOrgUnitImporter\addError(), 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  }
global $DIC
Definition: saml.php:7
addError($lang_var, $import_id, $action=null)
$lng
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 $action, $attributes, $description, $DIC, $ilUser, $title, $tpl, $tree, ilObject\_hasUntrashedReference(), ilObject\_lookupObjIdByImportId(), ilObject\_lookupType(), ilOrgUnitImporter\addError(), ilOrgUnitImporter\addWarning(), ilOrgUnitImporter\buildRef(), ilObjOrgUnit\getRootOrgRefId(), ilOrgUnitImporter\hasMoreThanOneMatch(), if, and moveObject().

Referenced by simpleImport().

31  {
32  global $DIC;
33  $tree = $DIC['tree'];
34  $tpl = $DIC['tpl'];
35  $ilUser = $DIC['ilUser'];
36  $title = (string) $o->title;
37  $description = (string) $o->description;
38  $external_id = (string) $o->external_id;
39  $create_mode = true;
40  $attributes = $o->attributes();
41  $action = (string) $attributes->action;
42  $ou_id = (string) $attributes->ou_id;
43  $ou_id_type = (string) $attributes->ou_id_type;
44  $ou_parent_id = (string) $attributes->ou_parent_id;
45  $ou_parent_id_type = (string) $attributes->ou_parent_id_type;
46 
47  if ($ou_id == ilObjOrgUnit::getRootOrgRefId()) {
48  $this->addWarning("cannot_change_root_node", $ou_id?$ou_id:$external_id, $action);
49  return;
50  }
51 
52  if ($ou_parent_id == "__ILIAS") {
53  $ou_parent_id = ilObjOrgUnit::getRootOrgRefId();
54  $ou_parent_id_type = "reference_id";
55  }
56 
57  //see mantis 0024601
58  if ($ou_id_type == 'external_id') {
59 
60  if(strlen($external_id) == 0) {
61  $external_id = $ou_id;
62  }
63 
64  if ($this->hasMoreThanOneMatch($external_id)) {
65  $this->addError("ou_more_than_one_match_found", $external_id, $action);
66  return;
67  }
68  }
69 
70  $ref_id = $this->buildRef($ou_id, $ou_id_type);
71  $parent_ref_id = $this->buildRef($ou_parent_id, $ou_parent_id_type);
72 
73  if ($action == "delete") {
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  $ru = new ilRepUtil($this);
83  try {
84  $ru->deleteObjects($parent_ref_id, array($ref_id)) !== false;
85  $this->stats["deleted"]++;
86  } catch (Exception $e) {
87  $this->addWarning("orgu_already_deleted", $ou_id?$ou_id:$external_id, $action);
88  }
89  return;
90  } elseif ($action == "update") {
91  if (!$parent_ref_id) {
92  $this->addError("ou_parent_id_not_valid", $ou_id?$ou_id:$external_id, $action);
93  return;
94  }
95  if (!$ref_id) {
96  $this->addError("ou_id_not_valid", $ou_id?$ou_id:$external_id, $action);
97  return;
98  }
99  $object = new ilObjOrgUnit($ref_id);
100  $object->setTitle($title);
101 
102  $arrTranslations = $object->getTranslations();
103  $object->updateTranslation($title, $description, $ilUser->getLanguage(), "");
104 
105  $object->setDescription($description);
106  $object->update();
107  $object->setImportId($external_id);
108  $this->moveObject($ref_id, $parent_ref_id, $ou_id, $external_id);
109 
110  $this->stats["updated"]++;
111  } elseif ($action == "create") {
112  if (!$parent_ref_id) {
113  $this->addError("ou_parent_id_not_valid", $ou_id?$ou_id:$external_id, $action);
114  return;
115  }
116  if ($external_id) {
117  $obj_id = ilObject::_lookupObjIdByImportId($external_id);
118  if (ilObject::_hasUntrashedReference($obj_id) && ilObject::_lookupType($obj_id) == 'orgu') {
119  $this->addError("ou_external_id_exists", $ou_id?$ou_id:$external_id, $action);
120  return;
121  }
122  }
123  $object = new ilObjOrgUnit();
124  $object->setTitle($title);
125  $object->setDescription($description);
126  $object->setImportId($external_id);
127  $object->create();
128  $object->createReference();
129  $object->putInTree($parent_ref_id);
130  $object->setPermissions($ou_parent_id);
131  $this->stats["created"]++;
132  } else {
133  $this->addError("no_valid_action_given", $ou_id, $action);
134  }
135  }
hasMoreThanOneMatch($external_id)
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) ...
$action
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
moveObject($ref_id, $parent_ref_id, $ou_id, $external_id)
addWarning($lang_var, $import_id, $action=null)
addError($lang_var, $import_id, $action=null)
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
Definition: confirmReg.php:12
Class ilObjOrgUnit.
$ilUser
Definition: imgupload.php:18
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
static _lookupType($a_id, $a_reference=false)
lookup object type
static getRootOrgRefId()
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: