ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
ilImport Class Reference

Import class. More...

+ Inheritance diagram for ilImport:
+ Collaboration diagram for ilImport:

Public Member Functions

 __construct ($a_target_id=0)
 Constructor. More...
 
 getMapping ()
 Get mapping object. More...
 
 setEntityTypes ($a_val)
 Set entity types. More...
 
 getEntityTypes ()
 Get entity types. More...
 
 addSkipEntity ($a_component, $a_entity, $skip=true)
 Add skip entity. More...
 
 setCurrentDataset ($a_val)
 Set currrent dataset. More...
 
 getCurrentDataset ()
 Get currrent dataset. More...
 
 afterEntityTypes ()
 After entity types are parsed. More...
 
 importRecord ($a_entity, $a_types, $a_record)
 After entity types are parsed. More...
 
 importEntity ($a_tmp_file, $a_filename, $a_entity, $a_component, $a_copy_file=false)
 Import entity. More...
 
 importObject ($a_new_obj, $a_tmp_file, $a_filename, $a_type, $a_comp="", $a_copy_file=false)
 Import repository object export file. More...
 
 processItemXml ($a_entity, $a_schema_version, $a_id, $a_xml, $a_install_id, $a_install_url)
 Process item xml. More...
 

Protected Member Functions

 doImportObject ($dir, $a_type, $a_component="", $a_tmpdir="")
 Import repository object export file. More...
 

Protected Attributes

 $install_id = ""
 
 $install_url = ""
 
 $entities = ""
 
 $mapping = null
 
 $skip_entity = array()
 

Detailed Description

Import class.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 11 of file class.ilImport.php.

Constructor & Destructor Documentation

◆ __construct()

ilImport::__construct (   $a_target_id = 0)

Constructor.

Parameters
intid of parent container
Returns

Reimplemented in ilImportContainer.

Definition at line 26 of file class.ilImport.php.

27 {
28 include_once("./Services/Export/classes/class.ilImportMapping.php");
29 $this->mapping = new ilImportMapping();
30 $this->mapping->setTagetId($a_target_id);
31 }

Member Function Documentation

◆ addSkipEntity()

ilImport::addSkipEntity (   $a_component,
  $a_entity,
  $skip = true 
)

Add skip entity.

Parameters
string$a_valcomponent
string$a_valentity

Definition at line 68 of file class.ilImport.php.

69 {
70 $this->skip_entity[$a_component][$a_entity] = $skip;
71 }

◆ afterEntityTypes()

ilImport::afterEntityTypes ( )

After entity types are parsed.

Definition at line 97 of file class.ilImport.php.

98 {
99 $this->getCurrentDataset()->setImport($this);
100 }
getCurrentDataset()
Get currrent dataset.

References getCurrentDataset().

+ Here is the call graph for this function:

◆ doImportObject()

ilImport::doImportObject (   $dir,
  $a_type,
  $a_component = "",
  $a_tmpdir = "" 
)
protected

Import repository object export file.

Parameters
stringabsolute filename of temporary upload file

Definition at line 160 of file class.ilImport.php.

161 {
162 global $objDefinition, $tpl;
163
164 if ($a_component == "")
165 {
166 $comp = $objDefinition->getComponentForType($a_type);
167 $class = $objDefinition->getClassName($a_type);
168 }
169 else
170 {
171 $comp = $a_component;
172 $c = explode("/", $comp);
173 $class = $c[count($c) - 1];
174 }
175
176 $this->comp = $comp;
177
178 // get import class
179 $success = true;
180
181 // process manifest file
182 include_once("./Services/Export/classes/class.ilManifestParser.php");
183 if (!is_file($dir."/manifest.xml"))
184 {
185 include_once("./Services/Export/exceptions/class.ilManifestFileNotFoundImportException.php");
186 $e = new ilManifestFileNotFoundImportException('Manifest file not found: "'.$dir."/manifest.xml".'".');
187 $e->setManifestDir($dir);
188 $e->setTmpDir($a_tmpdir);
189 throw $e;
190 }
191 $parser = new ilManifestParser($dir."/manifest.xml");
192 $this->mapping->setInstallUrl($parser->getInstallUrl());
193 $this->mapping->setInstallId($parser->getInstallId());
194
195 // process export files
196 $expfiles = $parser->getExportFiles();
197
198 include_once("./Services/Export/classes/class.ilExportFileParser.php");
199 $all_importers = array();
200 foreach ($expfiles as $expfile)
201 {
202 $comp = $expfile["component"];
203 $comp_arr = explode("/", $comp);
204 $import_class_file = "./".$comp."/classes/class.il".$comp_arr[1]."Importer.php";
205 $class = "il".$comp_arr[1]."Importer";
206 include_once($import_class_file);
207 $this->importer = new $class();
208 $all_importers[] = $this->importer;
209 $this->importer->setImportDirectory($dir);
210 $this->importer->init();
211 $this->current_comp = $comp;
212
213 try {
214 $parser = new ilExportFileParser($dir."/".$expfile["path"],$this, "processItemXml");
215 }
216 catch(Exception $e)
217 {
218 $GLOBALS['ilLog']->write(__METHOD__.': Import failed with message: '.$e->getMessage());
219 #$GLOBALS['ilLog']->write(__METHOD__.': '.file_get_contents($dir.'/'.$expfile['path']));
220 throw $e;
221 }
222 }
223
224 // final processing
225 foreach ($all_importers as $imp)
226 {
227 $imp->finalProcessing($this->mapping);
228 }
229
230 // we should only get on mapping here
231 $top_mapping = $this->mapping->getMappingsOfEntity($this->comp, $a_type);
232 $new_id = (int) current($top_mapping);
233
234 return $new_id;
235 }
global $tpl
Definition: ilias.php:8
$success
Definition: Utf8Test.php:87
manifest.xml file not found-exception for import
Manifest parser for ILIAS standard export files.
$GLOBALS['ct_recipient']

References $GLOBALS, $success, and $tpl.

Referenced by importObject().

+ Here is the caller graph for this function:

◆ getCurrentDataset()

ilImport::getCurrentDataset ( )

Get currrent dataset.

Returns
object currrent dataset

Definition at line 89 of file class.ilImport.php.

90 {
91 return $this->current_dataset;
92 }

Referenced by afterEntityTypes(), and importRecord().

+ Here is the caller graph for this function:

◆ getEntityTypes()

ilImport::getEntityTypes ( )
final

Get entity types.

Returns
array entity types

Definition at line 57 of file class.ilImport.php.

58 {
59 return $this->entity_types;
60 }

◆ getMapping()

ilImport::getMapping ( )

Get mapping object.

Returns
ilImportMapping ilImportMapping

Definition at line 37 of file class.ilImport.php.

38 {
39 return $this->mapping;
40 }

References $mapping.

Referenced by ilImportContainer\createDummy(), and processItemXml().

+ Here is the caller graph for this function:

◆ importEntity()

ilImport::importEntity (   $a_tmp_file,
  $a_filename,
  $a_entity,
  $a_component,
  $a_copy_file = false 
)
final

Import entity.

Definition at line 116 of file class.ilImport.php.

118 {
119 $this->importObject(null, $a_tmp_file, $a_filename, $a_entity, $a_component, $a_copy_file);
120 }
importObject($a_new_obj, $a_tmp_file, $a_filename, $a_type, $a_comp="", $a_copy_file=false)
Import repository object export file.

References importObject().

+ Here is the call graph for this function:

◆ importObject()

ilImport::importObject (   $a_new_obj,
  $a_tmp_file,
  $a_filename,
  $a_type,
  $a_comp = "",
  $a_copy_file = false 
)
final

Import repository object export file.

Parameters
stringabsolute filename of temporary upload file

Definition at line 128 of file class.ilImport.php.

130 {
131 // create temporary directory
132 $tmpdir = ilUtil::ilTempnam();
133 ilUtil::makeDir($tmpdir);
134 if ($a_copy_file)
135 {
136 copy($a_tmp_file, $tmpdir."/".$a_filename);
137 }
138 else
139 {
140 ilUtil::moveUploadedFile($a_tmp_file, $a_filename, $tmpdir."/".$a_filename);
141 }
142 ilUtil::unzip($tmpdir."/".$a_filename);
143 $dir = $tmpdir."/".substr($a_filename, 0, strlen($a_filename) - 4);
144
145 $GLOBALS['ilLog']->write(__METHOD__.': do import with dir '.$dir);
146 $new_id = $this->doImportObject($dir, $a_type, $a_comp, $tmpdir);
147
148 // delete temporary directory
149 ilUtil::delDir($tmpdir);
150
151 return $new_id;
152 }
doImportObject($dir, $a_type, $a_component="", $a_tmpdir="")
Import repository object export file.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static ilTempnam()
Create a temporary file in an ILIAS writable directory.
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...

References $GLOBALS, ilUtil\delDir(), doImportObject(), ilUtil\ilTempnam(), ilUtil\makeDir(), ilUtil\moveUploadedFile(), and ilUtil\unzip().

Referenced by importEntity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importRecord()

ilImport::importRecord (   $a_entity,
  $a_types,
  $a_record 
)

After entity types are parsed.

Parameters

Definition at line 107 of file class.ilImport.php.

108 {
109 $this->getCurrentDataset()->importRecord($a_entity, $a_types, $a_record);
110 }

References getCurrentDataset().

+ Here is the call graph for this function:

◆ processItemXml()

ilImport::processItemXml (   $a_entity,
  $a_schema_version,
  $a_id,
  $a_xml,
  $a_install_id,
  $a_install_url 
)

Process item xml.

@global ilObjectDefinition $objDefinition

Definition at line 242 of file class.ilImport.php.

243 {
244 global $objDefinition;
245
246 // skip
247 if ($this->skip_entity[$this->current_comp][$a_entity])
248 {
249 return;
250 }
251
252 if($objDefinition->isRBACObject($a_entity) &&
253 $this->getMapping()->getMapping('Services/Container', 'imported', $a_id))
254 {
255 $GLOBALS['ilLog']->write(__METHOD__.': Ignoring referenced '.$a_entity.' with id '.$a_id);
256 return;
257 }
258 $this->importer->setInstallId($a_install_id);
259 $this->importer->setInstallUrl($a_install_url);
260 $this->importer->setSchemaVersion($a_schema_version);
261 $this->importer->setSkipEntities($this->skip_entity);
262 $new_id = $this->importer->importXmlRepresentation($a_entity, $a_id, $a_xml, $this->mapping);
263
264 // Store information about imported obj_ids in mapping to avoid double imports of references
265 if($objDefinition->isRBACObject($a_entity))
266 {
267 $this->getMapping()->addMapping('Services/Container', 'imported', $a_id, 1);
268 }
269
270 // @TODO new id is not always set
271 if($new_id)
272 {
273 $this->mapping->addMapping($this->comp ,$a_entity, $a_id, $new_id);
274 }
275 }
getMapping()
Get mapping object.

References $GLOBALS, and getMapping().

+ Here is the call graph for this function:

◆ setCurrentDataset()

ilImport::setCurrentDataset (   $a_val)

Set currrent dataset.

Parameters
objectcurrrent dataset

Definition at line 78 of file class.ilImport.php.

79 {
80 $this->current_dataset = $a_val;
81 }

◆ setEntityTypes()

ilImport::setEntityTypes (   $a_val)
final

Set entity types.

Parameters
arrayentity types

Definition at line 47 of file class.ilImport.php.

48 {
49 $this->entity_types = $a_val;
50 }

Field Documentation

◆ $entities

ilImport::$entities = ""
protected

Definition at line 15 of file class.ilImport.php.

◆ $install_id

ilImport::$install_id = ""
protected

Definition at line 13 of file class.ilImport.php.

◆ $install_url

ilImport::$install_url = ""
protected

Definition at line 14 of file class.ilImport.php.

◆ $mapping

ilImport::$mapping = null
protected

Definition at line 17 of file class.ilImport.php.

Referenced by getMapping().

◆ $skip_entity

ilImport::$skip_entity = array()
protected

Definition at line 18 of file class.ilImport.php.


The documentation for this class was generated from the following file: