ILIAS  release_7 Revision v7.30-3-g800a261c036
ilObjFileImplementationLegacy Class Reference

Class ilObjFileImplementationLegacy. More...

+ Inheritance diagram for ilObjFileImplementationLegacy:
+ Collaboration diagram for ilObjFileImplementationLegacy:

Public Member Functions

 __construct (int $obj_id, int $version, string $file_name)
 ilObjFileImplementationAbstract constructor. More...
 
 getDirectory ($a_version=0)
 
 handleChangedObjectTitle (string $new_title)
 
 createDirectory ()
 
 clearDataDirectory ()
 
 deleteVersions ($a_hist_entry_ids=null)
 
 getFileExtension ()
 
 export (string $target_dir)
 
 getVersions ($version_ids=null)
 array ( 0 => array ( 'date' => '2020-11-05 09:49:18', 'user_id' => '6', 'obj_id' => '297', 'obj_type' => 'file', 'action' => 'create', 'info_params' => 'Version 1.docx,1,1', 'user_comment' => '', 'hist_entry_id' => '1', 'title' => NULL, 'filename' => 'Version 1.docx', 'version' => '1', 'max_version' => '1', 'rollback_version' => '', 'rollback_user_id' => '', ), ) More...
 
 getSpecificVersion ($version_id)
 
 getFile ($a_hist_entry_id=null)
 
 getVersion ()
 
 getFileType ()
 
 getStorageID ()
 
- Public Member Functions inherited from ilObjFileImplementationAbstract
 createDirectory ()
 
 replaceFile ($a_upload_file, $a_filename)
 
 addFileVersion ($a_upload_file, $a_filename)
 
 clearDataDirectory ()
 
 setFileType ($a_type)
 
 setFileSize ($a_size)
 
 getFileSize ()
 
 setVersion ($a_version)
 
 getVersion ()
 
 setMaxVersion ($a_max_version)
 
 getMaxVersion ()
 
 storeUnzipedFile ($a_upload_file, $a_filename)
 
 getSpecificVersion ($version_id)
 
- Public Member Functions inherited from ilObjFileImplementationInterface
 sendFile ($a_hist_entry_id=null)
 

Static Public Member Functions

static parseInfoParams ($entry)
 Parses the info parameters ("info_params") of the specified history entry. More...
 

Protected Member Functions

 compareVersions ($v1, $v2)
 Compares two file versions. More...
 

Protected Attributes

 $obj_id
 
 $version
 
 $file_name
 

Private Member Functions

 getFileName ()
 
 isInline ()
 

Private Attributes

 $file_storage
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilObjFileImplementationLegacy::__construct ( int  $obj_id,
int  $version,
string  $file_name 
)

ilObjFileImplementationAbstract constructor.

Parameters
int$obj_id
int$version
string$file_name

Definition at line 33 of file class.ilObjFileImplementationLegacy.php.

References $file_name, $obj_id, and $version.

34  {
35  $this->obj_id = $obj_id;
36  $this->version = $version;
37  $this->file_name = $file_name;
38  $this->file_storage = new ilFSStorageFile($obj_id);
39  $this->file_storage->create();
40  }
Class ilFSStorageFile.

Member Function Documentation

◆ clearDataDirectory()

ilObjFileImplementationLegacy::clearDataDirectory ( )

Implements ilObjFileImplementationInterface.

Definition at line 72 of file class.ilObjFileImplementationLegacy.php.

References createDirectory(), ilUtil\delDir(), and getDirectory().

Referenced by deleteVersions().

73  {
74  ilUtil::delDir($this->getDirectory());
75  $this->createDirectory();
76  }
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compareVersions()

ilObjFileImplementationLegacy::compareVersions (   $v1,
  $v2 
)
protected

Compares two file versions.

Parameters
array$v1First file version to compare.
array$v2Second file version to compare.
Returns
int Returns an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.

Definition at line 195 of file class.ilObjFileImplementationLegacy.php.

196  {
197  // v2 - v1 because version should be descending
198  return (int) $v2["version"] - (int) $v1["version"];
199  }

◆ createDirectory()

ilObjFileImplementationLegacy::createDirectory ( )

Implements ilObjFileImplementationInterface.

Definition at line 64 of file class.ilObjFileImplementationLegacy.php.

References getDirectory(), and ilUtil\makeDirParents().

Referenced by clearDataDirectory().

65  {
67  }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteVersions()

ilObjFileImplementationLegacy::deleteVersions (   $a_hist_entry_ids = null)

Implements ilObjFileImplementationInterface.

Definition at line 81 of file class.ilObjFileImplementationLegacy.php.

References $data, $DIC, $index, $version, ilHistory\_getEntryByHistoryID(), ilHistory\_removeEntriesForObject(), ilHistory\_removeEntryByHistoryID(), clearDataDirectory(), ilUtil\delDir(), ilFileDelivery\DISP_ATTACHMENT, ilFileDelivery\DISP_INLINE, getDirectory(), getFile(), getFileName(), ilObjFileImplementationAbstract\getMaxVersion(), ilFileUtils\getValidFilename(), getVersion(), getVersions(), isInline(), parseInfoParams(), and ilObjFileImplementationInterface\sendFile().

82  {
83  if ($a_hist_entry_ids == null || count($a_hist_entry_ids) < 1) {
84  $this->clearDataDirectory();
85 
87  } else {
88  $actualVersionDeleted = false;
89 
90  // get all versions
91  $versions = $this->getVersions();
92 
93  // delete each version
94  foreach ($a_hist_entry_ids as $hist_id) {
95  $entry = null;
96 
97  // get version
98  foreach ($versions as $index => $version) {
99  if ($version["hist_entry_id"] == $hist_id) {
100  // remove each history entry
102 
103  // delete directory
104  $version_dir = $this->getDirectory($version["version"]);
105  ilUtil::delDir($version_dir);
106 
107  // is actual version?
108  if ($version["version"] == $this->getVersion()) {
109  $actualVersionDeleted = true;
110  }
111 
112  // remove from array
113  unset($versions[$index]);
114  break;
115  }
116  }
117  }
118 
119  // update actual version if it was deleted before
120  if ($actualVersionDeleted) {
121  // get newest version (already sorted by getVersions)
122  $version = reset($versions);
123  $version['max_version'] = $this->getMaxVersion();
124  $this->updateWithVersion($version);
125  }
126  }
127  }
static _removeEntryByHistoryID($a_hist_entry_id)
Removes a single entry from the history.
$index
Definition: metadata.php:128
getVersions($version_ids=null)
array ( 0 => array ( &#39;date&#39; => &#39;2020-11-05 09:49:18&#39;, &#39;user_id&#39; => &#39;6&#39;, &#39;obj_id&#39; => &#39;297&#39;...
static _removeEntriesForObject($a_obj_id)
remove all history entries for an object
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
+ Here is the call graph for this function:

◆ export()

ilObjFileImplementationLegacy::export ( string  $target_dir)

Implements ilObjFileImplementationInterface.

Definition at line 201 of file class.ilObjFileImplementationLegacy.php.

References getDirectory(), getVersion(), IL_INST_ID, ilUtil\makeDir(), and ilUtil\rCopy().

201  : void
202  {
203  $subdir = "il_" . IL_INST_ID . "_file_" . $this->getId();
204  ilUtil::makeDir($target_dir . "/objects/" . $subdir);
205 
206  $filedir = $this->getDirectory($this->getVersion()); // FSX
207 
208  if (@!is_dir($filedir)) {
209  $filedir = $this->getDirectory();
210  }
211 
212  ilUtil::rCopy($filedir, $target_dir . "/objects/" . $subdir);
213  }
const IL_INST_ID
Definition: constants.php:38
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
+ Here is the call graph for this function:

◆ getDirectory()

ilObjFileImplementationLegacy::getDirectory (   $a_version = 0)

Implements ilObjFileImplementationInterface.

Definition at line 45 of file class.ilObjFileImplementationLegacy.php.

Referenced by clearDataDirectory(), createDirectory(), deleteVersions(), export(), getFile(), and getVersions().

46  {
47  $version_subdir = "";
48 
49  if ($a_version) {
50  $version_subdir = sprintf("%03d", $a_version);
51  }
52 
53  return $this->file_storage->getAbsolutePath() . '/' . $version_subdir;
54  }
+ Here is the caller graph for this function:

◆ getFile()

ilObjFileImplementationLegacy::getFile (   $a_hist_entry_id = null)

Implements ilObjFileImplementationInterface.

Definition at line 361 of file class.ilObjFileImplementationLegacy.php.

References $data, ilHistory\_getEntryByHistoryID(), getDirectory(), getFileName(), getVersion(), and parseInfoParams().

Referenced by deleteVersions().

362  {
363  if (is_null($a_hist_entry_id)) {
364  $file = $this->getDirectory($this->getVersion()) . "/" . $this->getFileName(); // FSX
365  } else {
366  require_once("./Services/History/classes/class.ilHistory.php");
367  $entry = ilHistory::_getEntryByHistoryID($a_hist_entry_id);
368 
369  if ($entry === false) {
370  return false;
371  }
372 
374  $file = $this->getDirectory($data["version"]) . "/" . $data["filename"];
375  }
376 
377  return $file;
378  }
$data
Definition: storeScorm.php:23
static _getEntryByHistoryID($a_hist_entry_id)
returns a single history entry
static parseInfoParams($entry)
Parses the info parameters ("info_params") of the specified history entry.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFileExtension()

ilObjFileImplementationLegacy::getFileExtension ( )

Implements ilObjFileImplementationInterface.

Definition at line 182 of file class.ilObjFileImplementationLegacy.php.

References ilObjFileAccess\_getFileExtension().

183  {
184  return ilObjFileAccess::_getFileExtension($this->getTitle());
185  }
static _getFileExtension($a_file_name)
Gets the file extension of the specified file name.
+ Here is the call graph for this function:

◆ getFileName()

ilObjFileImplementationLegacy::getFileName ( )
private

Definition at line 385 of file class.ilObjFileImplementationLegacy.php.

References $file_name.

Referenced by deleteVersions(), getFile(), and isInline().

+ Here is the caller graph for this function:

◆ getFileType()

ilObjFileImplementationLegacy::getFileType ( )

Implements ilObjFileImplementationInterface.

Definition at line 402 of file class.ilObjFileImplementationLegacy.php.

403  {
404  return '';
405  }

◆ getSpecificVersion()

ilObjFileImplementationLegacy::getSpecificVersion (   $version_id)

Definition at line 337 of file class.ilObjFileImplementationLegacy.php.

References $version, ilHistory\_getEntryByHistoryID(), and parseInfoParams().

338  {
339  include_once("./Services/History/classes/class.ilHistory.php");
341  if ($version === false) {
342  return false;
343  }
344 
345  // ilHistory returns different keys in _getEntryByHistoryID and _getEntriesForObject
346  // so this makes it the same
347  $version["hist_entry_id"] = $version["id"];
348  $version["user_id"] = $version["usr_id"];
349  $version["date"] = $version["hdate"];
350  unset($version["id"], $version["usr_id"], $version["hdate"]);
351 
352  // parse params
354 
355  return array_merge($version, $params);
356  }
static _getEntryByHistoryID($a_hist_entry_id)
returns a single history entry
static parseInfoParams($entry)
Parses the info parameters ("info_params") of the specified history entry.
+ Here is the call graph for this function:

◆ getStorageID()

ilObjFileImplementationLegacy::getStorageID ( )

Implements ilObjFileImplementationInterface.

Definition at line 407 of file class.ilObjFileImplementationLegacy.php.

407  : ?string
408  {
409  return '-';
410  }

◆ getVersion()

ilObjFileImplementationLegacy::getVersion ( )

Implements ilObjFileImplementationInterface.

Definition at line 380 of file class.ilObjFileImplementationLegacy.php.

References $version.

Referenced by deleteVersions(), export(), and getFile().

+ Here is the caller graph for this function:

◆ getVersions()

ilObjFileImplementationLegacy::getVersions (   $version_ids = null)

array ( 0 => array ( 'date' => '2020-11-05 09:49:18', 'user_id' => '6', 'obj_id' => '297', 'obj_type' => 'file', 'action' => 'create', 'info_params' => 'Version 1.docx,1,1', 'user_comment' => '', 'hist_entry_id' => '1', 'title' => NULL, 'filename' => 'Version 1.docx', 'version' => '1', 'max_version' => '1', 'rollback_version' => '', 'rollback_user_id' => '', ), )

Implements ilObjFileImplementationInterface.

Definition at line 237 of file class.ilObjFileImplementationLegacy.php.

References $index, $version, ilHistory\_getEntriesForObject(), getDirectory(), and parseInfoParams().

Referenced by deleteVersions().

237  : array
238  {
239  $versions = (array) ilHistory::_getEntriesForObject($this->obj_id, 'file');
240 
241  if ($version_ids != null && count($version_ids) > 0) {
242  foreach ($versions as $index => $version) {
243  if (!in_array($version["hist_entry_id"], $version_ids, true)) {
244  unset($versions[$index]);
245  }
246  }
247  }
248 
249  // add custom entries
250  foreach ($versions as $index => $version) {
252  $versions[$index] = array_merge($version, $params);
253  }
254 
255  // sort by version number (hist_entry_id will do for that)
256  usort($versions, array($this, "compareVersions"));
257 
258  $version_objects = [];
259  foreach ($versions as $version) {
260  $file = $this->getDirectory($version["version"]) . "/" . $version["filename"];
261  $filesize = @filesize($file);
262  $version['size'] = $filesize;
263  $version_objects[] = new ilObjFileVersion($version);
264  }
265 
266  return $version_objects;
267  }
Class ilObjFileVersion.
$index
Definition: metadata.php:128
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.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleChangedObjectTitle()

ilObjFileImplementationLegacy::handleChangedObjectTitle ( string  $new_title)

Implements ilObjFileImplementationInterface.

Definition at line 56 of file class.ilObjFileImplementationLegacy.php.

57  {
58  // noting to do here
59  }

◆ isInline()

ilObjFileImplementationLegacy::isInline ( )
private
Returns
bool
Deprecated:

Definition at line 394 of file class.ilObjFileImplementationLegacy.php.

References ilObjFileAccess\_isFileInline(), and getFileName().

Referenced by deleteVersions().

395  {
397  }
static _isFileInline($a_file_name)
Returns true, if the specified file shall be displayed inline in the browser.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseInfoParams()

static ilObjFileImplementationLegacy::parseInfoParams (   $entry)
static

Parses the info parameters ("info_params") of the specified history entry.

Parameters
array$entryThe history entry.
Returns
array Returns an array containing the "filename" and "version" contained within the "info_params".

Definition at line 275 of file class.ilObjFileImplementationLegacy.php.

References $data, $n, and $result.

Referenced by deleteVersions(), getFile(), ilFileObjectToStorageDirectory\getHistoryData(), getSpecificVersion(), and getVersions().

275  : array
276  {
277  $data = explode(",", $entry["info_params"]);
278 
279  // bugfix: first created file had no version number
280  // this is a workaround for all files created before the bug was fixed
281  if (empty($data[1])) {
282  $data[1] = "1";
283  }
284 
285  if (empty($data[2])) {
286  $data[2] = "1";
287  }
288 
289  // BEGIN bugfix #31730
290  // if more than 2 commas are detected, the need for reassembling the filename is: possible to necessary
291  if (sizeof($data) > 2) {
292  $last = sizeof($data) - 1;
293  for ($n = 1; $n < $last - 1; $n++) {
294  $data[0] .= "," . $data[$n];
295  }
296 
297  // trying to distinguish the next-to-last being a 'last part of the filename'
298  // or a 'version information', based on having a dot included or not
299  if (strpos($data[$last - 1], ".") !== false) {
300  $data[0] .= "," . $data[$last - 1];
301  $data[1] = $data[$last];
302  $data[2] = $data[$last];
303  } else {
304  $data[1] = $data[$last - 1];
305  $data[2] = $data[$last];
306  }
307  }
308  // END bugfix #31730
309 
310  $result = array(
311  "filename" => $data[0],
312  "version" => $data[1],
313  "max_version" => $data[2],
314  "rollback_version" => "",
315  "rollback_user_id" => "",
316  );
317 
318  // if rollback, the version contains the rollback version as well
319  if ($entry["action"] == "rollback") {
320  $tokens = explode("|", $result["max_version"]);
321  if (count($tokens) > 1) {
322  $result["max_version"] = $tokens[0];
323  $result["rollback_version"] = $tokens[1];
324 
325  if (count($tokens) > 2) {
326  $result["rollback_user_id"] = $tokens[2];
327  }
328  }
329  }
330 
331  return $result;
332  }
$data
Definition: storeScorm.php:23
$result
$n
Definition: RandomTest.php:85
+ Here is the caller graph for this function:

Field Documentation

◆ $file_name

ilObjFileImplementationLegacy::$file_name
protected

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

Referenced by __construct(), and getFileName().

◆ $file_storage

ilObjFileImplementationLegacy::$file_storage
private

Definition at line 21 of file class.ilObjFileImplementationLegacy.php.

◆ $obj_id

ilObjFileImplementationLegacy::$obj_id
protected

Definition at line 15 of file class.ilObjFileImplementationLegacy.php.

Referenced by __construct().

◆ $version

ilObjFileImplementationLegacy::$version
protected

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