ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilOrgUnitSimpleImport Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

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

Public Member Functions

 simpleImport (string $file_path)
 
 simpleImportElement (SimpleXMLElement $o)
 
- Public Member Functions inherited from ilOrgUnitImporter
 __construct ()
 
 hasMoreThanOneMatch (string $external_id)
 
 hasErrors ()
 
 hasWarnings ()
 
 addWarning (string $lang_var, string $import_id, ?string $action=null)
 
 addError (string $lang_var, string $import_id, ?string $action=null)
 
 getErrors ()
 
 getWarnings ()
 
 getStats ()
 
 importXmlRepresentation (string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
 
- Public Member Functions inherited from ilXmlImporter
 __construct ()
 
 setImport (ilImport $a_val)
 
 getImport ()
 
 init ()
 
 setInstallId (string $a_val)
 
 getInstallId ()
 
 setInstallUrl (string $a_val)
 
 getInstallUrl ()
 
 setSchemaVersion (string $a_val)
 
 getSchemaVersion ()
 
 setImportDirectory (string $a_val)
 
 getImportDirectory ()
 
 setSkipEntities (array $a_val)
 
 getSkipEntities ()
 
 exportedFromSameInstallation ()
 
 importXmlRepresentation (string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
 
 finalProcessing (ilImportMapping $a_mapping)
 
 afterContainerImportProcessing (ilImportMapping $mapping)
 

Protected Member Functions

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

Additional Inherited Members

- Data Fields inherited from ilOrgUnitImporter
array $errors = []
 
array $warnings = []
 
array $stats
 
- Protected Attributes inherited from ilXmlImporter
array $skip_entities = array()
 
ilImport $imp
 
string $install_id
 
string $install_url
 
string $schema_version
 
string $import_directory
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class ilOrgUnitSimpleImport

Author
: Oskar Truffer ot@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
: Martin Studer ms@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

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

Member Function Documentation

◆ moveObject()

ilOrgUnitSimpleImport::moveObject ( int  $ref_id,
int  $parent_ref_id,
string  $ou_id,
string  $external_id 
)
protected
Parameters
string$ou_idthis is only needed for displaying the warning.
string$external_idthis is only needed for displaying the warning.

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

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

Referenced by simpleImportElement().

160  {
161  global $DIC;
162  $tree = $DIC['tree'];
163  if ($parent_ref_id != $tree->getParentId($ref_id)) {
164  try {
165  $path = $tree->getPathId($parent_ref_id);
166  if (in_array($ref_id, $path)) {
167  $this->addWarning("not_movable_to_subtree", $ou_id ? $ou_id : $external_id, "update");
168  } else {
169  $tree->moveTree($ref_id, $parent_ref_id);
170  }
171  } catch (Exception $e) {
172  global $DIC;
173  $ilLog = $DIC['ilLog'];
174  $this->addWarning("not_movable", $ou_id ? $ou_id : $external_id, "update");
175  $ilLog->write($e->getMessage() . "\\n" . $e->getTraceAsString());
176  error_log($e->getMessage() . "\\n" . $e->getTraceAsString());
177  }
178  }
179  }
$path
Definition: ltiservices.php:30
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:25
addWarning(string $lang_var, string $import_id, ?string $action=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ simpleImport()

ilOrgUnitSimpleImport::simpleImport ( string  $file_path)

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

References Vendor\Package\$a, ilOrgUnitImporter\addError(), and simpleImportElement().

28  {
29  $this->stats = array("created" => 0, "updated" => 0, "deleted" => 0);
30  $a = file_get_contents($file_path, "r");
31  $xml = new SimpleXMLElement($a);
32 
33  if (!count($xml->OrgUnit)) {
34  $this->addError("no_orgunit", $xml->external_id, null);
35  return;
36  }
37 
38  foreach ($xml->OrgUnit as $o) {
39  $this->simpleImportElement($o);
40  }
41  }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
simpleImportElement(SimpleXMLElement $o)
addError(string $lang_var, string $import_id, ?string $action=null)
+ Here is the call graph for this function:

◆ simpleImportElement()

ilOrgUnitSimpleImport::simpleImportElement ( SimpleXMLElement  $o)

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

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

Referenced by simpleImport().

44  {
45  global $DIC;
46  $ilUser = $DIC['ilUser'];
47  $title = (string) $o->title;
48  $description = (string) $o->description;
49  $external_id = (string) $o->external_id;
50  $create_mode = true;
51  $attributes = $o->attributes();
52  $action = (string) $attributes->action;
53  $ou_id = (string) $attributes->ou_id;
54  $ou_id_type = (string) $attributes->ou_id_type;
55  $ou_parent_id = (string) $attributes->ou_parent_id;
56  $ou_parent_id_type = (string) $attributes->ou_parent_id_type;
57 
58  if ($ou_id == ilObjOrgUnit::getRootOrgRefId()) {
59  $this->addWarning("cannot_change_root_node", $ou_id ? $ou_id : $external_id, $action);
60 
61  return;
62  }
63 
64  if ($ou_parent_id == "__ILIAS") {
65  $ou_parent_id = ilObjOrgUnit::getRootOrgRefId();
66  $ou_parent_id_type = "reference_id";
67  }
68 
69  //see mantis 0024601
70  if ($ou_id_type == 'external_id') {
71  if (strlen($external_id) == 0) {
72  $external_id = $ou_id;
73  }
74 
75  if ($this->hasMoreThanOneMatch($external_id)) {
76  $this->addError("ou_more_than_one_match_found", $external_id, $action);
77 
78  return;
79  }
80  }
81 
82  $ref_id = $this->buildRef($ou_id, $ou_id_type);
83  $parent_ref_id = $this->buildRef($ou_parent_id, $ou_parent_id_type);
84 
85  if ($action == "delete") {
86  if (!$parent_ref_id) {
87  $this->addError("ou_parent_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
88 
89  return;
90  }
91  if (!$ref_id) {
92  $this->addError("ou_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
93 
94  return;
95  }
96  $ru = new ilRepUtil($this);
97  try {
98  $ru->deleteObjects($parent_ref_id, array($ref_id)) !== false;
99  $this->stats["deleted"]++;
100  } catch (Exception $e) {
101  $this->addWarning("orgu_already_deleted", $ou_id ? $ou_id : $external_id, $action);
102  }
103 
104  return;
105  } elseif ($action == "update") {
106  if (!$parent_ref_id) {
107  $this->addError("ou_parent_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
108 
109  return;
110  }
111  if (!$ref_id) {
112  $this->addError("ou_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
113 
114  return;
115  }
116  $object = new ilObjOrgUnit($ref_id);
117  $object->setTitle($title);
118 
119  $object->updateTranslation($title, $description, $ilUser->getLanguage(), "");
120 
121  $object->setDescription($description);
122  $object->update();
123  $object->setImportId($external_id);
124  $this->moveObject($ref_id, $parent_ref_id, $ou_id, $external_id);
125 
126  $this->stats["updated"]++;
127  } elseif ($action == "create") {
128  if (!$parent_ref_id) {
129  $this->addError("ou_parent_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
130 
131  return;
132  }
133  if ($external_id) {
134  $obj_id = ilObject::_lookupObjIdByImportId($external_id);
135  if (ilObject::_hasUntrashedReference($obj_id) && ilObject::_lookupType($obj_id) == 'orgu') {
136  $this->addError("ou_external_id_exists", $ou_id ? $ou_id : $external_id, $action);
137 
138  return;
139  }
140  }
141  $object = new ilObjOrgUnit();
142  $object->setTitle($title);
143  $object->setDescription($description);
144  $object->setImportId($external_id);
145  $object->create();
146  $object->createReference();
147  $object->putInTree($parent_ref_id);
148  $object->setPermissions($parent_ref_id);
149  $this->stats["created"]++;
150  } else {
151  $this->addError("no_valid_action_given", $ou_id, $action);
152  }
153  }
static _lookupObjIdByImportId(string $import_id)
Get (latest) object id for an import id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))
static _hasUntrashedReference(int $obj_id)
checks whether an object has at least one reference that is not in trash
hasMoreThanOneMatch(string $external_id)
$ref_id
Definition: ltiauth.php:66
buildRef($id, string $type)
global $DIC
Definition: shib_login.php:25
static getRootOrgRefId()
moveObject(int $ref_id, int $parent_ref_id, string $ou_id, string $external_id)
static _lookupType(int $id, bool $reference=false)
addError(string $lang_var, string $import_id, ?string $action=null)
addWarning(string $lang_var, string $import_id, ?string $action=null)
+ 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: