ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 155 of file class.ilOrgUnitSimpleImport.php.

References $DIC, Vendor\Package\$e, $ilLog, and ilOrgUnitImporter\addWarning().

Referenced by simpleImportElement().

156  {
157  global $DIC;
158  $tree = $DIC['tree'];
159  if ($parent_ref_id != $tree->getParentId($ref_id)) {
160  try {
161  $path = $tree->getPathId($parent_ref_id);
162  if (in_array($ref_id, $path)) {
163  $this->addWarning("not_movable_to_subtree", $ou_id ? $ou_id : $external_id, "update");
164  } else {
165  $tree->moveTree($ref_id, $parent_ref_id);
166  }
167  } catch (Exception $e) {
168  global $DIC;
169  $ilLog = $DIC['ilLog'];
170  $this->addWarning("not_movable", $ou_id ? $ou_id : $external_id, "update");
171  $ilLog->write($e->getMessage() . "\\n" . $e->getTraceAsString());
172  error_log($e->getMessage() . "\\n" . $e->getTraceAsString());
173  }
174  }
175  }
addWarning($lang_var, $import_id, $action=null)
$DIC
Definition: xapitoken.php:46
+ 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 Vendor\Package\$a, $DIC, $lng, $xml, ilOrgUnitImporter\addError(), and simpleImportElement().

14  {
15  global $DIC;
16  $lng = $DIC['lng'];
17  $this->stats = array("created" => 0, "updated" => 0, "deleted" => 0);
18  $a = file_get_contents($file_path, "r");
19  $xml = new SimpleXMLElement($a);
20 
21  if (!count($xml->OrgUnit)) {
22  $this->addError("no_orgunit", null, null);
23 
24  return;
25  }
26 
27  foreach ($xml->OrgUnit as $o) {
28  $this->simpleImportElement($o);
29  }
30  }
addError($lang_var, $import_id, $action=null)
$lng
$xml
Definition: metadata.php:332
$DIC
Definition: xapitoken.php:46
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
simpleImportElement(SimpleXMLElement $o)
+ Here is the call graph for this function:

◆ simpleImportElement()

ilOrgUnitSimpleImport::simpleImportElement ( SimpleXMLElement  $o)

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

References $attributes, $DIC, Vendor\Package\$e, $ilUser, $tpl, ilObject\_hasUntrashedReference(), ilObject\_lookupObjIdByImportId(), ilObject\_lookupType(), ilOrgUnitImporter\addError(), ilOrgUnitImporter\addWarning(), ilOrgUnitImporter\buildRef(), ilObjOrgUnit\getRootOrgRefId(), ilOrgUnitImporter\hasMoreThanOneMatch(), if, and moveObject().

Referenced by simpleImport().

34  {
35  global $DIC;
36  $tree = $DIC['tree'];
37  $tpl = $DIC['tpl'];
38  $ilUser = $DIC['ilUser'];
39  $title = (string) $o->title;
40  $description = (string) $o->description;
41  $external_id = (string) $o->external_id;
42  $create_mode = true;
43  $attributes = $o->attributes();
44  $action = (string) $attributes->action;
45  $ou_id = (string) $attributes->ou_id;
46  $ou_id_type = (string) $attributes->ou_id_type;
47  $ou_parent_id = (string) $attributes->ou_parent_id;
48  $ou_parent_id_type = (string) $attributes->ou_parent_id_type;
49 
50  if ($ou_id == ilObjOrgUnit::getRootOrgRefId()) {
51  $this->addWarning("cannot_change_root_node", $ou_id ? $ou_id : $external_id, $action);
52 
53  return;
54  }
55 
56  if ($ou_parent_id == "__ILIAS") {
57  $ou_parent_id = ilObjOrgUnit::getRootOrgRefId();
58  $ou_parent_id_type = "reference_id";
59  }
60 
61  //see mantis 0024601
62  if ($ou_id_type == 'external_id') {
63 
64  if(strlen($external_id) == 0) {
65  $external_id = $ou_id;
66  }
67 
68  if ($this->hasMoreThanOneMatch($external_id)) {
69  $this->addError("ou_more_than_one_match_found", $external_id, $action);
70 
71  return;
72  }
73  }
74 
75  $ref_id = $this->buildRef($ou_id, $ou_id_type);
76  $parent_ref_id = $this->buildRef($ou_parent_id, $ou_parent_id_type);
77 
78  if ($action == "delete") {
79  if (!$parent_ref_id) {
80  $this->addError("ou_parent_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
81 
82  return;
83  }
84  if (!$ref_id) {
85  $this->addError("ou_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
86 
87  return;
88  }
89  $ru = new ilRepUtil($this);
90  try {
91  $ru->deleteObjects($parent_ref_id, array($ref_id)) !== false;
92  $this->stats["deleted"]++;
93  } catch (Exception $e) {
94  $this->addWarning("orgu_already_deleted", $ou_id ? $ou_id : $external_id, $action);
95  }
96 
97  return;
98  } elseif ($action == "update") {
99  if (!$parent_ref_id) {
100  $this->addError("ou_parent_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
101 
102  return;
103  }
104  if (!$ref_id) {
105  $this->addError("ou_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
106 
107  return;
108  }
109  $object = new ilObjOrgUnit($ref_id);
110  $object->setTitle($title);
111 
112  $object->updateTranslation($title, $description, $ilUser->getLanguage(), "");
113 
114  $object->setDescription($description);
115  $object->update();
116  $object->setImportId($external_id);
117  $this->moveObject($ref_id, $parent_ref_id, $ou_id, $external_id);
118 
119  $this->stats["updated"]++;
120  } elseif ($action == "create") {
121  if (!$parent_ref_id) {
122  $this->addError("ou_parent_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
123 
124  return;
125  }
126  if ($external_id) {
127  $obj_id = ilObject::_lookupObjIdByImportId($external_id);
128  if (ilObject::_hasUntrashedReference($obj_id) && ilObject::_lookupType($obj_id) == 'orgu') {
129  $this->addError("ou_external_id_exists", $ou_id ? $ou_id : $external_id, $action);
130 
131  return;
132  }
133  }
134  $object = new ilObjOrgUnit();
135  $object->setTitle($title);
136  $object->setDescription($description);
137  $object->setImportId($external_id);
138  $object->create();
139  $object->createReference();
140  $object->putInTree($parent_ref_id);
141  $object->setPermissions($ou_parent_id);
142  $this->stats["created"]++;
143  } else {
144  $this->addError("no_valid_action_given", $ou_id, $action);
145  }
146  }
hasMoreThanOneMatch($external_id)
$attributes
Definition: metadata.php:231
static _hasUntrashedReference($a_obj_id)
checks wether an object has at least one reference that is not in trash
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
Repository Utilities (application layer, put GUI related stuff into ilRepUtilGUI) ...
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
$ilUser
Definition: imgupload.php:18
static _lookupType($a_id, $a_reference=false)
lookup object type
static getRootOrgRefId()
$DIC
Definition: xapitoken.php:46
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: