ILIAS
release_8 Revision v8.19
◀ ilDoc Overview
Main Page
Related Pages
Modules
+
Namespaces
Namespace List
+
Namespace Members
+
All
$
_
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
r
s
t
u
v
w
x
+
Functions
_
a
b
c
d
e
f
g
h
i
l
m
n
o
p
r
s
t
u
v
w
x
+
Variables
$
a
b
c
d
e
f
g
h
j
l
m
p
s
t
u
+
Data Structures
Data Structures
Data Structure Index
Class Hierarchy
+
Data Fields
+
All
$
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Ö
+
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
+
Variables
$
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Ö
+
Files
File List
+
Globals
+
All
$
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
z
+
Functions
_
a
b
c
d
e
g
h
i
m
n
p
r
s
t
u
v
x
+
Variables
$
a
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
z
Examples
•
All
Data Structures
Namespaces
Files
Functions
Variables
Modules
Pages
class.ilFileObjectToStorageDirectory.php
Go to the documentation of this file.
1
<?php
2
23
class
ilFileObjectToStorageDirectory
24
{
25
protected
int
$object_id
;
26
protected
string
$path
;
30
protected
array
$versions
= [];
31
37
public
function
__construct
(
int
$object_id,
string
$path)
38
{
39
$this->object_id =
$object_id
;
40
$this->path =
$path
;
41
$this->
initVersions
();
42
}
43
44
private
function
initVersions
(): void
45
{
46
$history_data = $this->
getHistoryData
();
47
48
$g =
new
RegexIterator(
49
new
RecursiveIteratorIterator
(
50
new
RecursiveDirectoryIterator
(
51
$this->path,
52
FilesystemIterator::KEY_AS_PATHNAME
53
| FilesystemIterator::CURRENT_AS_FILEINFO
54
| FilesystemIterator::SKIP_DOTS
55
),
56
RecursiveIteratorIterator::LEAVES_ONLY
57
),
58
'/.*\/file_[\d]*\/([\d]*)\/(.*)/'
,
59
RegexIterator::GET_MATCH
60
);
61
62
$this->versions = [];
63
64
foreach
($g as $item) {
65
$version
= (
int
) $item[1];
66
$title = $history_data[
$version
][
'filename'
] ?? $item[2];
67
$action = $history_data[
$version
][
'action'
] ??
'create'
;
68
$owner = $history_data[
$version
][
'owner_id'
] ?? 13;
69
$creation_date_timestamp = strtotime($history_data[
$version
][
'date'
] ??
'0'
);
70
if
($creation_date_timestamp ===
false
) {
71
$creation_date_timestamp = 0;
72
}
73
$this->versions[
$version
] =
new
ilFileObjectToStorageVersion
(
74
$version,
75
$item[0],
76
$title,
77
$title,
78
$action,
79
$creation_date_timestamp,
80
$owner
81
);
82
}
83
ksort($this->versions);
84
}
85
86
87
private
function
getHistoryData
(): array
88
{
89
$info =
ilHistory::_getEntriesForObject
($this->object_id,
'file'
);
90
$history_data = [];
91
foreach
($info as
$i
) {
92
$parsed_info = self::parseInfoParams($i);
93
$version
= (
int
) $parsed_info[
'version'
];
94
$history_data[
$version
] = $parsed_info;
95
$history_data[
$version
][
'owner_id'
] = (
int
) $i[
'user_id'
];
96
$history_data[
$version
][
'date'
] = (string) $i[
'date'
];
97
$history_data[
$version
][
'action'
] = (string) $i[
'action'
];
98
}
99
100
uasort($history_data,
static
function
($v1, $v2) {
101
return
(
int
) $v2[
"version"
] - (
int
) $v1[
"version"
];
102
});
103
return
$history_data;
104
}
105
109
public
function
getVersions
():
Generator
110
{
111
yield from
$this->versions
;
112
}
113
117
public
function
getObjectId
():
int
118
{
119
return
$this->object_id
;
120
}
121
122
public
function
tearDown
(): void
123
{
124
touch(rtrim($this->path,
"/"
) .
"/"
.
ilFileObjectToStorageMigrationHelper::MIGRATED
);
125
}
126
127
public
static
function
parseInfoParams
(array $entry): array
128
{
129
$data
= explode(
","
, $entry[
"info_params"
]);
130
131
// bugfix: first created file had no version number
132
// this is a workaround for all files created before the bug was fixed
133
if
(empty(
$data
[1])) {
134
$data
[1] =
"1"
;
135
}
136
137
if
(empty(
$data
[2])) {
138
$data
[2] =
"1"
;
139
}
140
141
// BEGIN bugfix #31730
142
// if more than 2 commas are detected, the need for reassembling the filename is: possible to necessary
143
if
(
sizeof
(
$data
) > 2) {
144
$last =
sizeof
(
$data
) - 1;
145
for
($n = 1; $n < $last - 1; $n++) {
146
$data
[0] .=
","
.
$data
[$n];
147
}
148
149
// trying to distinguish the next-to-last being a 'last part of the filename'
150
// or a 'version information', based on having a dot included or not
151
if
(strpos(
$data
[$last - 1],
"."
) !==
false
) {
152
$data
[0] .=
","
.
$data
[$last - 1];
153
$data
[1] =
$data
[$last];
154
$data
[2] =
$data
[$last];
155
}
else
{
156
$data
[1] =
$data
[$last - 1];
157
$data
[2] =
$data
[$last];
158
}
159
}
160
// END bugfix #31730
161
162
$result = array(
163
"filename"
=>
$data
[0],
164
"version"
=>
$data
[1],
165
"max_version"
=>
$data
[2],
166
"rollback_version"
=>
""
,
167
"rollback_user_id"
=>
""
,
168
);
169
170
// if rollback, the version contains the rollback version as well
171
if
($entry[
"action"
] ==
"rollback"
) {
172
$tokens = explode(
"|"
, $result[
"max_version"
]);
173
if
(count($tokens) > 1) {
174
$result[
"max_version"
] = $tokens[0];
175
$result[
"rollback_version"
] = $tokens[1];
176
177
if
(count($tokens) > 2) {
178
$result[
"rollback_user_id"
] = $tokens[2];
179
}
180
}
181
}
182
183
return
$result;
184
}
185
}
$data
$data
Definition:
ltiregistration.php:31
ilFileObjectToStorageDirectory\parseInfoParams
static parseInfoParams(array $entry)
Definition:
class.ilFileObjectToStorageDirectory.php:127
ilFileObjectToStorageDirectory
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition:
class.ilFileObjectToStorageDirectory.php:23
ilHistory\_getEntriesForObject
static _getEntriesForObject(int $a_obj_id, string $a_obj_type="")
get all history entries for an object
Definition:
class.ilHistory.php:111
ilFileObjectToStorageDirectory\$object_id
int $object_id
Definition:
class.ilFileObjectToStorageDirectory.php:25
RecursiveDirectoryIterator
ilFileObjectToStorageDirectory\initVersions
initVersions()
Definition:
class.ilFileObjectToStorageDirectory.php:44
RecursiveIteratorIterator
ilFileObjectToStorageDirectory\__construct
__construct(int $object_id, string $path)
ilFileObjectToStorageDirectory constructor.
Definition:
class.ilFileObjectToStorageDirectory.php:37
Generator
ilFileObjectToStorageDirectory\getObjectId
getObjectId()
Definition:
class.ilFileObjectToStorageDirectory.php:117
ilFileObjectToStorageDirectory\getHistoryData
getHistoryData()
Definition:
class.ilFileObjectToStorageDirectory.php:87
ilFileObjectToStorageDirectory\$path
string $path
Definition:
class.ilFileObjectToStorageDirectory.php:26
ilFileObjectToStorageMigrationHelper\MIGRATED
const MIGRATED
Definition:
class.ilFileObjectToStorageMigrationHelper.php:22
ILIAS\Repository\int
int(string $key)
Definition:
trait.BaseGUIRequest.php:61
ilFileObjectToStorageDirectory\$versions
array $versions
Definition:
class.ilFileObjectToStorageDirectory.php:30
$version
$version
Definition:
plugin.php:24
ilFileObjectToStorageDirectory\getVersions
getVersions()
Definition:
class.ilFileObjectToStorageDirectory.php:109
ilFileObjectToStorageVersion
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition:
class.ilFileObjectToStorageVersion.php:23
ilFileObjectToStorageDirectory\tearDown
tearDown()
Definition:
class.ilFileObjectToStorageDirectory.php:122
$i
$i
Definition:
metadata.php:41
Modules
File
classes
Setup
class.ilFileObjectToStorageDirectory.php
Generated on Sun Apr 6 2025 22:01:37 for ILIAS by
1.8.13 (using
Doxyfile
)