ILIAS  release_8 Revision v8.23
ilFileObjectToStorageDirectory Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilFileObjectToStorageDirectory:

Public Member Functions

 __construct (int $object_id, string $path)
 ilFileObjectToStorageDirectory constructor. More...
 
 getVersions ()
 
 getObjectId ()
 
 tearDown ()
 

Static Public Member Functions

static parseInfoParams (array $entry)
 

Protected Attributes

int $object_id
 
string $path
 
array $versions = []
 

Private Member Functions

 initVersions ()
 
 getHistoryData ()
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class ilFileObjectToStorageDirectory

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

Definition at line 23 of file class.ilFileObjectToStorageDirectory.php.

Constructor & Destructor Documentation

◆ __construct()

ilFileObjectToStorageDirectory::__construct ( int  $object_id,
string  $path 
)

ilFileObjectToStorageDirectory constructor.

Parameters
int$object_id
string$path

Definition at line 37 of file class.ilFileObjectToStorageDirectory.php.

References $object_id, $path, and initVersions().

+ Here is the call graph for this function:

Member Function Documentation

◆ getHistoryData()

ilFileObjectToStorageDirectory::getHistoryData ( )
private

Definition at line 87 of file class.ilFileObjectToStorageDirectory.php.

References $i, $version, ilHistory\_getEntriesForObject(), and ILIAS\Repository\int().

Referenced by initVersions().

87  : 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  }
static _getEntriesForObject(int $a_obj_id, string $a_obj_type="")
get all history entries for an object
$version
Definition: plugin.php:24
$i
Definition: metadata.php:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getObjectId()

ilFileObjectToStorageDirectory::getObjectId ( )
Returns
int

Definition at line 117 of file class.ilFileObjectToStorageDirectory.php.

References $object_id.

Referenced by ilFileObjectToStorageMigrationRunner\getResource(), and ilFileObjectToStorageMigrationRunner\migrate().

117  : int
118  {
119  return $this->object_id;
120  }
+ Here is the caller graph for this function:

◆ getVersions()

ilFileObjectToStorageDirectory::getVersions ( )
Returns
Generator|ilFileObjectToStorageVersion[]

Definition at line 109 of file class.ilFileObjectToStorageDirectory.php.

References $versions.

Referenced by ilFileObjectToStorageMigrationRunner\migrate().

+ Here is the caller graph for this function:

◆ initVersions()

ilFileObjectToStorageDirectory::initVersions ( )
private

Definition at line 44 of file class.ilFileObjectToStorageDirectory.php.

References $version, getHistoryData(), and ILIAS\Repository\int().

Referenced by __construct().

44  : void
45  {
46  $history_data = $this->getHistoryData();
47 
48  $g = new RegexIterator(
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  }
$version
Definition: plugin.php:24
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseInfoParams()

static ilFileObjectToStorageDirectory::parseInfoParams ( array  $entry)
static

Definition at line 127 of file class.ilFileObjectToStorageDirectory.php.

References $data.

127  : 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  }

◆ tearDown()

ilFileObjectToStorageDirectory::tearDown ( )

Definition at line 122 of file class.ilFileObjectToStorageDirectory.php.

References ilFileObjectToStorageMigrationHelper\MIGRATED.

Referenced by ilFileObjectToStorageMigrationRunner\migrate().

122  : void
123  {
124  touch(rtrim($this->path, "/") . "/" . ilFileObjectToStorageMigrationHelper::MIGRATED);
125  }
+ Here is the caller graph for this function:

Field Documentation

◆ $object_id

int ilFileObjectToStorageDirectory::$object_id
protected

Definition at line 25 of file class.ilFileObjectToStorageDirectory.php.

Referenced by __construct(), and getObjectId().

◆ $path

string ilFileObjectToStorageDirectory::$path
protected

Definition at line 26 of file class.ilFileObjectToStorageDirectory.php.

Referenced by __construct().

◆ $versions

array ilFileObjectToStorageDirectory::$versions = []
protected

Definition at line 30 of file class.ilFileObjectToStorageDirectory.php.

Referenced by getVersions().


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