ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
RecordFilesMigration.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27use ilFileUtils;
28use ILIAS\DI;
34
36{
37 protected const GLOBAL_KEY = "null";
38 protected ilDBInterface $db;
39
40 public function getLabel(): string
41 {
42 return 'RecordFilesMigration';
43 }
44
46 {
47 return 5;
48 }
49
50 public function getPreconditions(
51 Environment $environment
52 ): array {
53 return [
57 ];
58 }
59
60 public function prepare(
61 Environment $environment
62 ): void {
63 $this->db = $environment->getResource(Environment::RESOURCE_DATABASE);
64 }
65
66 public function step(
67 Environment $environment
68 ): void {
69 $files = $this->getFiles();
70 $object_id = array_key_first($files);
71 $file_path = $files[$object_id][0];
72 $stakeholder = (new Stakeholder())->withOwnerId(6);
73 $irss_helper = new ilResourceStorageMigrationHelper($stakeholder, $environment);
74 $rid = $irss_helper->movePathToStorage($file_path, 6, null, null, false);
75 $this->db->manipulate(
76 "INSERT INTO adv_md_record_files VALUES ("
77 . $this->db->quote(($object_id === self::GLOBAL_KEY) ? 0 : $object_id, ilDBConstants::T_INTEGER) . ", "
78 . $this->db->quote($rid->serialize(), ilDBConstants::T_TEXT) . ", "
79 . $this->db->quote((int) ($object_id === self::GLOBAL_KEY), ilDBConstants::T_INTEGER) . ")"
80 );
81 }
82
83 public function getRemainingAmountOfSteps(): int
84 {
85 $steps = 0;
86 foreach ($this->getFiles() as $object_id => $file_paths) {
87 $steps += count($file_paths);
88 }
89 return $steps;
90 }
91
92 protected function getExportDir(): string
93 {
94 return ilFileUtils::getDataDir() . '/ilAdvancedMetaData';
95 }
96
97 protected function getFiles(): array
98 {
99 $files = [];
100 $dirs = [];
101 if (!is_dir($this->getExportDir())) {
102 return $files;
103 }
104 foreach (scandir($this->getExportDir()) as $file) {
105 $matches = [];
106 if (
107 (!preg_match('/^export_([0-9]+)$/', $file, $matches) && $file !== "export") ||
108 in_array($file, ['.', '..', '.DS_Store'])
109 ) {
110 continue;
111 }
112 $object_id = count($matches) == 2
113 ? (int) $matches[1]
114 : self::GLOBAL_KEY;
115 $dirs[$object_id] = $this->getExportDir() . DIRECTORY_SEPARATOR . $file;
116 }
117 foreach ($dirs as $object_id => $dir) {
118 $files_in_dir = [];
119 foreach (ilFileUtils::getDir($dir) as $file_name => $file_data) {
120 if (in_array($file_name, ['.', '..', '.DS_Store'])) {
121 continue;
122 }
123 $files_in_dir[] = $dir . DIRECTORY_SEPARATOR . $file_name;
124 }
125 if (!empty($files_in_dir)) {
126 $files[$object_id] = $files_in_dir;
127 }
128 }
129 return $files;
130 }
131}
getDefaultAmountOfStepsPerRun()
Tell the default amount of steps to be executed for one run of the migration.
getPreconditions(Environment $environment)
Objectives the migration depend on.
prepare(Environment $environment)
Prepare the migration by means of some environment.
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
step(Environment $environment)
Run one step of the migration.
Class ilDBConstants.
Class ilFileUtils.
static getDir(string $a_dir, bool $a_rec=false, ?string $a_sub_dir="")
get directory
static getDataDir()
get data directory (outside webspace)
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
A migration is a potentially long lasting operation that can be broken into discrete steps.
Definition: Migration.php:29
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: class.Agent.php:19
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Container.php:19