ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilExportFilesToIRSSMigration Class Reference
+ Inheritance diagram for ilExportFilesToIRSSMigration:
+ Collaboration diagram for ilExportFilesToIRSSMigration:

Public Member Functions

 getLabel ()
 
 getDefaultAmountOfStepsPerRun ()
 Tell the default amount of steps to be executed for one run of the migration. More...
 
 getPreconditions (Environment $environment)
 Objectives the migration depend on. More...
 
 prepare (Environment $environment)
 Prepare the migration by means of some environment. More...
 
 step (Environment $environment)
 Run one step of the migration. More...
 
 getRemainingAmountOfSteps ()
 Count up how many "things" need to be migrated. More...
 
 getLabel ()
 
 getDefaultAmountOfStepsPerRun ()
 Tell the default amount of steps to be executed for one run of the migration. More...
 
 getPreconditions (Environment $environment)
 Objectives the migration depend on. More...
 
 prepare (Environment $environment)
 Prepare the migration by means of some environment. More...
 
 step (Environment $environment)
 Run one step of the migration. More...
 
 getRemainingAmountOfSteps ()
 Count up how many "things" need to be migrated. More...
 

Protected Member Functions

 updateMigrated (int $obj_id, string $export_type, string $filename)
 
 updateMigratedUnsupportedObjectType (int $obj_id, string $export_type, string $filename)
 
 getExportDirectory (string $class_name, bool $is_plugin, string $location, string $component_for_type, int $a_obj_id, string $a_type="xml", string $a_obj_type="", string $a_entity="")
 
 createPathFromId (int $a_container_id, string $a_name)
 
 getExporterClass (string $a_type, bool $is_plugin, string $class_name, string $location, string $component_for_type)
 

Protected Attributes

ilDBInterface $db
 

Additional Inherited Members

- Data Fields inherited from ILIAS\Setup\Migration
const INFINITE = -1
 

Detailed Description

Definition at line 25 of file ilExportFilesToIRSSMigration.php.

Member Function Documentation

◆ createPathFromId()

ilExportFilesToIRSSMigration::createPathFromId ( int  $a_container_id,
string  $a_name 
)
protected

Definition at line 210 of file ilExportFilesToIRSSMigration.php.

210 : string
211 {
212 $max_exponent = 3;
213 $factor = 100;
214 $path = [];
215 $found = false;
216 $num = $a_container_id;
217 $path_string = '';
218 for ($i = $max_exponent; $i > 0; $i--) {
219 $factor = pow($factor, $i);
220 if (($tmp = (int) ($num / $factor)) or $found) {
221 $path[] = $tmp;
222 $num = $num % $factor;
223 $found = true;
224 }
225 }
226 if (count($path)) {
227 $path_string = (implode('/', $path) . '/');
228 }
229 return $path_string . $a_name . '_' . $a_container_id;
230 }
$path
Definition: ltiservices.php:30

References $path.

◆ getDefaultAmountOfStepsPerRun()

ilExportFilesToIRSSMigration::getDefaultAmountOfStepsPerRun ( )

Tell the default amount of steps to be executed for one run of the migration.

Return Migration::INFINITE if all units should be migrated at once.

Implements ILIAS\Setup\Migration.

Definition at line 34 of file ilExportFilesToIRSSMigration.php.

34 : int
35 {
36 return 5;
37 }

◆ getExportDirectory()

ilExportFilesToIRSSMigration::getExportDirectory ( string  $class_name,
bool  $is_plugin,
string  $location,
string  $component_for_type,
int  $a_obj_id,
string  $a_type = "xml",
string  $a_obj_type = "",
string  $a_entity = "" 
)
protected

Definition at line 165 of file ilExportFilesToIRSSMigration.php.

174 : string {
175 $ent = ($a_entity == "")
176 ? ""
177 : "_" . $a_entity;
178 if ($a_obj_type == "") {
179 $a_obj_type = ilObject::_lookupType($a_obj_id);
180 }
181 $new_file_structure = [
182 'cat', 'exc', 'crs', 'sess',
183 'file', 'grp', 'frm', 'usr',
184 'catr', 'crsr', 'grpr'
185 ];
186 if (in_array($a_obj_type, $new_file_structure)) {
187 $dir = ilFileUtils::getDataDir() . DIRECTORY_SEPARATOR;
188 $dir .= 'il' . $class_name . $ent . DIRECTORY_SEPARATOR;
189 $dir .= $this->createPathFromId($a_obj_id, $a_obj_type) . DIRECTORY_SEPARATOR;
190 $dir .= ($a_type == 'xml' ? 'export' : 'export_' . $a_type);
191 return $dir;
192 }
193 $exporter_class = $this->getExporterClass(
194 $a_obj_type,
195 $is_plugin,
196 $class_name,
197 $location,
198 $component_for_type
199 );
200 $export_dir = call_user_func(
201 array($exporter_class, 'lookupExportDirectory'),
202 $a_obj_type,
203 $a_obj_id,
204 $a_type,
205 $a_entity
206 );
207 return $export_dir;
208 }
$location
Definition: buildRTE.php:22
getExporterClass(string $a_type, bool $is_plugin, string $class_name, string $location, string $component_for_type)
createPathFromId(int $a_container_id, string $a_name)
static getDataDir()
get data directory (outside webspace)
static _lookupType(int $id, bool $reference=false)

References ilObject\_lookupType().

Referenced by step().

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

◆ getExporterClass()

ilExportFilesToIRSSMigration::getExporterClass ( string  $a_type,
bool  $is_plugin,
string  $class_name,
string  $location,
string  $component_for_type 
)
protected

Definition at line 232 of file ilExportFilesToIRSSMigration.php.

238 : string {
239 if ($is_plugin) {
240 $classname = 'il' . $class_name . 'Exporter';
241 if (include_once $location . '/class.' . $classname . '.php') {
242 return $classname;
243 }
244 } else {
245 $comp = $component_for_type;
246 $componentParts = explode("/", $comp);
247 $class = array_pop($componentParts);
248 $class = "il" . $class . "Exporter";
249 // page component plugin exporter classes are already included
250 // the component is not registered by ilObjDefinition
251 if (class_exists($class)) {
252 return $class;
253 }
254 // the next line had a "@" in front of the include_once
255 // I removed this because it tages ages to track down errors
256 // if the include class contains parse errors.
257 // Alex, 20 Jul 2012
258 if (include_once "./" . $comp . "/classes/class." . $class . ".php") {
259 return $class;
260 }
261 }
262 throw new InvalidArgumentException('Invalid exporter type given');
263 }

References $location.

◆ getLabel()

ilExportFilesToIRSSMigration::getLabel ( )
Returns
string - a meaningful and concise description for your migration.

Implements ILIAS\Setup\Migration.

Definition at line 29 of file ilExportFilesToIRSSMigration.php.

29 : string
30 {
31 return "ilExportFilesToIRSSMigration";
32 }

◆ getPreconditions()

ilExportFilesToIRSSMigration::getPreconditions ( Environment  $environment)

Objectives the migration depend on.

Exceptions
UnachievableExceptionif the objective is not achievable
Returns
Objective[]

Implements ILIAS\Setup\Migration.

Definition at line 39 of file ilExportFilesToIRSSMigration.php.

References ilResourceStorageMigrationHelper\getPreconditions().

+ Here is the call graph for this function:

◆ getRemainingAmountOfSteps()

ilExportFilesToIRSSMigration::getRemainingAmountOfSteps ( )

Count up how many "things" need to be migrated.

This helps the admin to decide how big he can create the steps and also how long a migration takes

Implements ILIAS\Setup\Migration.

Definition at line 128 of file ilExportFilesToIRSSMigration.php.

128 : int
129 {
130 $query = "SELECT COUNT(*) as count FROM export_file_info where migrated = 0";
131 $res = $this->db->query($query);
132 $row = $res->fetchAssoc();
133 if (is_null($row)) {
134 return 0;
135 }
136 return (int) $row['count'];
137 }
$res
Definition: ltiservices.php:69

References $res.

◆ prepare()

ilExportFilesToIRSSMigration::prepare ( Environment  $environment)

Prepare the migration by means of some environment.

This is not supposed to modify the environment, but will be run to prime the migration object to run step and getRemainingAmountOfSteps afterwards.

Implements ILIAS\Setup\Migration.

Definition at line 51 of file ilExportFilesToIRSSMigration.php.

51 : void
52 {
53 $this->db = $environment->getResource(Environment::RESOURCE_DATABASE);
54 }
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.

References ILIAS\Setup\Environment\getResource().

+ Here is the call graph for this function:

◆ step()

ilExportFilesToIRSSMigration::step ( Environment  $environment)

Run one step of the migration.

Implements ILIAS\Setup\Migration.

Definition at line 56 of file ilExportFilesToIRSSMigration.php.

56 : void
57 {
58 $res_export_file_info = $this->db->query(
59 "SELECT obj_id, export_type, filename, create_date FROM export_file_info WHERE migrated = 0 LIMIT 1"
60 );
61 $row_export_file_info = $res_export_file_info->fetchAssoc();
62 if (is_null($row_export_file_info)) {
63 return;
64 }
65 $obj_id = (int) $row_export_file_info['obj_id'];
66 $export_type = $row_export_file_info['export_type'];
67 $filename = $row_export_file_info['filename'];
68 $res_object_data = $this->db->query(
69 "SELECT type FROM object_data WHERE obj_id = " . $this->db->quote((int) $row_export_file_info['obj_id'], ilDBConstants::T_INTEGER)
70 );
71 $row_object_data = $res_object_data->fetchAssoc();
72 # Export does not exist anymore, mark as migrated
73 if (is_null($row_object_data)) {
74 $this->updateMigrated($obj_id, $export_type, $filename);
75 return;
76 }
77 $res_il_object_def = $this->db->query(
78 "SELECT class_name, component, location, id FROM il_object_def where id = " . $this->db->quote($row_object_data['type'], ilDBConstants::T_TEXT)
79 );
80 $row_il_object_def = $this->db->fetchAssoc($res_il_object_def);
81 # Object type is not defined or plugin and cannot be migrated, mark as such
82 if (is_null($row_il_object_def)) {
83 $this->updateMigratedUnsupportedObjectType($obj_id, $export_type, $filename);
84 return;
85 }
86 $res_il_plugin = $this->db->query("SELECT plugin_id FROM il_plugin");
87 $plugin_ids = [];
88 while ($row_il_plugin = $res_il_plugin->fetchAssoc()) {
89 $plugin_ids[] = $row_il_plugin['plugin_id'];
90 }
91 $classname = $row_il_object_def['class_name'];
92 $create_date = $row_export_file_info['create_date'];
93 $type = $row_object_data['type'];
94 $component_for_type = $row_il_object_def['component'];
95 $is_plugin = in_array($row_il_object_def["id"], $plugin_ids);
96 $location = $row_il_object_def['location'];
97 $export_dir = $this->getExportDirectory(
98 $classname,
99 $is_plugin,
100 $location,
101 $component_for_type,
102 $obj_id,
103 $export_type,
104 $type
105 );
106 $file_path = $export_dir . DIRECTORY_SEPARATOR . $filename;
107 # Export file was deleted, mark as migrated
108 if (!file_exists($file_path)) {
109 $this->updateMigrated($obj_id, $export_type, $filename);
110 return;
111 }
112 $irss_helper = new ilResourceStorageMigrationHelper(new ResourceStakeholder(), $environment);
113 $rid = $irss_helper->movePathToStorage($file_path, 6, null, null, false);
114 if (is_null($rid)) {
115 throw new \Exception('Could not store:' . $file_path);
116 }
117 $this->db->manipulate(
118 "INSERT INTO export_files (object_id, rid, owner_id, timestamp) VALUES ("
119 . $this->db->quote($obj_id, ilDBConstants::T_INTEGER) . ", "
120 . $this->db->quote($rid->serialize(), ilDBConstants::T_TEXT) . ", "
121 . $this->db->quote(6, ilDBConstants::T_INTEGER) . ", "
122 . $this->db->quote($create_date, ilDBConstants::T_DATE) . ")"
123 );
124 # Export file was moved to irss, mark as migrated
125 $this->updateMigrated($obj_id, $export_type, $filename);
126 }
$filename
Definition: buildRTE.php:78
updateMigratedUnsupportedObjectType(int $obj_id, string $export_type, string $filename)
getExportDirectory(string $class_name, bool $is_plugin, string $location, string $component_for_type, int $a_obj_id, string $a_type="xml", string $a_obj_type="", string $a_entity="")
updateMigrated(int $obj_id, string $export_type, string $filename)

References $filename, $location, getExportDirectory(), ILIAS\Repository\int(), ilDBConstants\T_DATE, ilDBConstants\T_INTEGER, ilDBConstants\T_TEXT, updateMigrated(), and updateMigratedUnsupportedObjectType().

+ Here is the call graph for this function:

◆ updateMigrated()

ilExportFilesToIRSSMigration::updateMigrated ( int  $obj_id,
string  $export_type,
string  $filename 
)
protected

Definition at line 139 of file ilExportFilesToIRSSMigration.php.

143 : void {
144 $this->db->manipulate(
145 "UPDATE export_file_info SET migrated = 1 WHERE"
146 . " obj_id = " . $this->db->quote($obj_id, ilDBConstants::T_INTEGER)
147 . " AND export_type = " . $this->db->quote($export_type, ilDBConstants::T_TEXT)
148 . " AND filename = " . $this->db->quote($filename, ilDBConstants::T_TEXT)
149 );
150 }

Referenced by step().

+ Here is the caller graph for this function:

◆ updateMigratedUnsupportedObjectType()

ilExportFilesToIRSSMigration::updateMigratedUnsupportedObjectType ( int  $obj_id,
string  $export_type,
string  $filename 
)
protected

Definition at line 152 of file ilExportFilesToIRSSMigration.php.

156 : void {
157 $this->db->manipulate(
158 "UPDATE export_file_info SET migrated = 2 WHERE"
159 . " obj_id = " . $this->db->quote($obj_id, ilDBConstants::T_INTEGER)
160 . " AND export_type = " . $this->db->quote($export_type, ilDBConstants::T_TEXT)
161 . " AND filename = " . $this->db->quote($filename, ilDBConstants::T_TEXT)
162 );
163 }

Referenced by step().

+ Here is the caller graph for this function:

Field Documentation

◆ $db

ilDBInterface ilExportFilesToIRSSMigration::$db
protected

Definition at line 27 of file ilExportFilesToIRSSMigration.php.


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