ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilFileObjectToStorageDirectory.php
Go to the documentation of this file.
1<?php
2
8{
12 protected $object_id;
16 protected $path;
20 protected $versions = [];
21
27 public function __construct(int $object_id, string $path)
28 {
29 $this->object_id = $object_id;
30 $this->path = $path;
31 $this->initVersions();
32 }
33
34 private function initVersions() : void
35 {
36 $history_data = $this->getHistoryData();
37 try {
38 $g = new RegexIterator(
39 new RecursiveIteratorIterator(
40 new RecursiveDirectoryIterator(
41 $this->path,
42 FilesystemIterator::KEY_AS_PATHNAME
43 |FilesystemIterator::CURRENT_AS_FILEINFO
44 |FilesystemIterator::SKIP_DOTS
45 ),
46 RecursiveIteratorIterator::LEAVES_ONLY
47 ),
48 '/.*\/file_[\d]*\/([\d]*)\/(.*)/',
49 RegexIterator::GET_MATCH
50 );
51 } catch (Throwable $t) {
52 // there was an error reading the directory, there will be no versions
53 $g = [];
54 }
55
56
57 $this->versions = [];
58
59 foreach ($g as $item) {
60 $version = (int) $item[1];
61 $title = $history_data[$version]['filename'] ?? $item[2];
62 $action = $history_data[$version]['action'] ?? 'create';
63 $owner = $history_data[$version]['owner_id'] ?? 13;
64 $creation_date_timestamp = strtotime($history_data[$version]['date'] ?? '0');
65 if ($creation_date_timestamp === false) {
66 $creation_date_timestamp = 0;
67 }
68 $this->versions[$version] = new ilFileObjectToStorageVersion(
69 $version,
70 $item[0],
71 $title,
72 $title,
73 $action,
74 $creation_date_timestamp,
75 $owner
76 );
77 }
78 ksort($this->versions);
79 }
80
84 private function getHistoryData() : array
85 {
86 $info = ilHistory::_getEntriesForObject($this->object_id, 'file');
87 $history_data = [];
88 foreach ($info as $i) {
90 $version = (int) $parsed_info['version'];
91 $history_data[$version] = $parsed_info;
92 $history_data[$version]['owner_id'] = (int) $i['user_id'];
93 $history_data[$version]['date'] = (string) $i['date'];
94 $history_data[$version]['action'] = (string) $i['action'];
95 }
96
97 uasort($history_data, static function ($v1, $v2) {
98 return (int) $v2["version"] - (int) $v1["version"];
99 });
100 return $history_data;
101 }
102
106 public function getVersions() : Generator
107 {
108 yield from $this->versions;
109 }
110
114 public function getObjectId() : int
115 {
116 return $this->object_id;
117 }
118
119 public function tearDown() : void
120 {
121 if (is_writable($this->path)) {
122 touch(rtrim($this->path, "/") . "/" . ilFileObjectToStorageMigrationHelper::MIGRATED);
123 }
124 }
125}
An exception for terminatinating execution or to throw for unit testing.
Class ilFileObjectToStorageDirectory.
__construct(int $object_id, string $path)
ilFileObjectToStorageDirectory constructor.
Class ilFileObjectToStorageVersion.
static _getEntriesForObject($a_obj_id, $a_obj_type="")
get all history entries for an object
static parseInfoParams($entry)
Parses the info parameters ("info_params") of the specified history entry.
$i
Definition: metadata.php:24