29 $this->stats = array(
"created" => 0,
"updated" => 0,
"deleted" => 0);
30 $a = file_get_contents($file_path,
"r");
33 if (!count($xml->OrgUnit)) {
34 $this->
addError(
"no_orgunit", $xml->external_id, null);
38 foreach ($xml->OrgUnit as $o) {
46 $ilUser = $DIC[
'ilUser'];
47 $title = (string) $o->title;
48 $description = (
string) $o->description;
49 $external_id = (string) $o->external_id;
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;
59 $this->
addWarning(
"cannot_change_root_node", $ou_id ? $ou_id : $external_id, $action);
64 if ($ou_parent_id ==
"__ILIAS") {
66 $ou_parent_id_type =
"reference_id";
70 if ($ou_id_type ==
'external_id') {
71 if (strlen($external_id) == 0) {
72 $external_id = $ou_id;
76 $this->
addError(
"ou_more_than_one_match_found", $external_id, $action);
83 $parent_ref_id = $this->
buildRef($ou_parent_id, $ou_parent_id_type);
85 if ($action ==
"delete") {
86 if (!$parent_ref_id) {
87 $this->
addError(
"ou_parent_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
92 $this->
addError(
"ou_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
98 $ru->deleteObjects($parent_ref_id, array(
$ref_id)) !==
false;
99 $this->stats[
"deleted"]++;
101 $this->
addWarning(
"orgu_already_deleted", $ou_id ? $ou_id : $external_id, $action);
105 } elseif ($action ==
"update") {
106 if (!$parent_ref_id) {
107 $this->
addError(
"ou_parent_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
112 $this->
addError(
"ou_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
117 $object->setTitle($title);
119 $object->updateTranslation($title, $description, $ilUser->getLanguage(),
"");
121 $object->setDescription($description);
123 $object->setImportId($external_id);
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);
136 $this->
addError(
"ou_external_id_exists", $ou_id ? $ou_id : $external_id, $action);
142 $object->setTitle($title);
143 $object->setDescription($description);
144 $object->setImportId($external_id);
146 $object->createReference();
147 $object->putInTree($parent_ref_id);
148 $object->setPermissions($parent_ref_id);
149 $this->stats[
"created"]++;
151 $this->
addError(
"no_valid_action_given", $ou_id, $action);
159 protected function moveObject(
int $ref_id,
int $parent_ref_id,
string $ou_id,
string $external_id)
162 $tree = $DIC[
'tree'];
163 if ($parent_ref_id != $tree->getParentId($ref_id)) {
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");
169 $tree->moveTree($ref_id, $parent_ref_id);
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());
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)
buildRef($id, string $type)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
moveObject(int $ref_id, int $parent_ref_id, string $ou_id, string $external_id)
simpleImportElement(SimpleXMLElement $o)
static _lookupType(int $id, bool $reference=false)
simpleImport(string $file_path)
addError(string $lang_var, string $import_id, ?string $action=null)
addWarning(string $lang_var, string $import_id, ?string $action=null)