19declare(strict_types=1);
31 return "ilExportFilesToIRSSMigration";
53 $this->db = $environment->
getResource(Environment::RESOURCE_DATABASE);
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"
61 $row_export_file_info = $res_export_file_info->fetchAssoc();
62 if (is_null($row_export_file_info)) {
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)
71 $row_object_data = $res_object_data->fetchAssoc();
72 # Export does not exist anymore, mark as migrated
73 if (is_null($row_object_data)) {
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)
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)) {
86 $res_il_plugin = $this->db->query(
"SELECT plugin_id FROM il_plugin");
88 while ($row_il_plugin = $res_il_plugin->fetchAssoc()) {
89 $plugin_ids[] = $row_il_plugin[
'plugin_id'];
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'];
106 $file_path = $export_dir . DIRECTORY_SEPARATOR .
$filename;
107 # Export file was deleted, mark as migrated
108 if (!file_exists($file_path)) {
113 $rid = $irss_helper->movePathToStorage($file_path, 6,
null,
null,
false);
115 throw new \Exception(
'Could not store:' . $file_path);
117 $this->db->manipulate(
118 "INSERT INTO export_files (object_id, rid, owner_id, timestamp) VALUES ("
124 # Export file was moved to irss, mark as migrated
130 $query =
"SELECT COUNT(*) as count FROM export_file_info where migrated = 0";
131 $res = $this->db->query($query);
132 $row =
$res->fetchAssoc();
136 return (
int) $row[
'count'];
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)
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)
169 string $component_for_type,
171 string $a_type =
"xml",
172 string $a_obj_type =
"",
173 string $a_entity =
""
175 $ent = ($a_entity ==
"")
178 if ($a_obj_type ==
"") {
181 $new_file_structure = [
182 'cat',
'exc',
'crs',
'sess',
183 'file',
'grp',
'frm',
'usr',
184 'catr',
'crsr',
'grpr'
186 if (in_array($a_obj_type, $new_file_structure)) {
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);
193 $exporter_class = $this->getExporterClass(
200 $export_dir = call_user_func(
201 array($exporter_class,
'lookupExportDirectory'),
216 $num = $a_container_id;
218 for ($i = $max_exponent; $i > 0; $i--) {
219 $factor = pow($factor, $i);
220 if (($tmp = (
int) ($num / $factor)) or $found) {
222 $num = $num % $factor;
227 $path_string = (implode(
'/',
$path) .
'/');
229 return $path_string . $a_name .
'_' . $a_container_id;
237 string $component_for_type
240 $classname =
'il' . $class_name .
'Exporter';
241 if (include_once
$location .
'/class.' . $classname .
'.php') {
245 $comp = $component_for_type;
246 $componentParts = explode(
"/", $comp);
247 $class = array_pop($componentParts);
248 $class =
"il" . $class .
"Exporter";
251 if (class_exists($class)) {
258 if (include_once
"./" . $comp .
"/classes/class." . $class .
".php") {
262 throw new InvalidArgumentException(
'Invalid exporter type given');
static getDataDir()
get data directory (outside webspace)
static _lookupType(int $id, bool $reference=false)
Class ilResourceStorageMigrationHelper.
static getPreconditions()
An environment holds resources to be used in the setup process.
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
A migration is a potentially long lasting operation that can be broken into discrete steps.
if(!file_exists('../ilias.ini.php'))