9 require_once(
"Services/Object/classes/class.ilObject2.php");
10 require_once(
'Modules/File/classes/class.ilFSStorageFile.php');
52 public $mode = self::MODE_OBJECT;
97 public function __construct($a_id = 0, $a_call_by_reference =
true)
100 $this->max_version = 0;
101 $this->raise_upload_error =
true;
105 parent::__construct($a_id, $a_call_by_reference);
107 if ($this->
getId()) {
115 $this->type =
"file";
143 $this->file_storage->create();
155 if ($default_visibility ==
"public") {
160 $this->log->debug(
"ilObjFile::createProperties, ID: " . $this->
getId() .
", Name: " 170 'meta_lifecycle_id' => [
'integer', $DIC->database()->nextId(
'il_meta_lifecycle')],
171 'rbac_id' => [
'integer', $this->
getId()],
172 'obj_id' => [
'integer', $this->
getId()],
173 'obj_type' => [
'text',
"file"],
174 'meta_version' => [
'integer', (int) $this->
getVersion()],
176 $DIC->database()->insert(
'il_meta_lifecycle',
$metadata);
179 if ($this->
getMode() != self::MODE_FILELIST) {
190 $this->no_meta_data_creation = (bool) $a_status;
196 return !(bool) $this->no_meta_data_creation;
202 return !(bool) $this->no_meta_data_creation;
213 $technical = $md_obj->addTechnical();
216 $format = $technical->addFormat();
219 $technical->update();
227 include_once
'Services/MetaData/classes/class.ilMD.php';
229 if (!is_object($md_gen = $md->getGeneral())) {
233 $md_gen->setTitle(
$title);
243 include_once
'Services/MetaData/classes/class.ilMD.php';
245 switch ($a_element) {
250 if (!is_object($md_technical = $md->getTechnical())) {
254 foreach ($md_technical->getFormatIds() as
$id) {
255 $md_format = $md_technical->getFormat(
$id);
275 $version_subdir =
"";
279 $version_subdir = sprintf(
"%03d", $a_version);
283 if (!is_object($this->file_storage)) {
287 $str = $this->file_storage->getAbsolutePath() .
'/' . $version_subdir;
301 $this->raise_upload_error = $a_raise;
314 public function getUploadFile($a_upload_file, $a_filename, $a_prevent_preview =
false)
318 $upload = $DIC->upload();
321 if ($upload->hasUploads()) {
322 if (!$upload->hasBeenProcessed()) {
328 $result = $upload->getResults()[$a_upload_file];
342 $highest_version = 0;
343 foreach ($file_hist_entries as $file_hist_entry) {
365 $relative_path_to_file = LegacyPathHelper::createRelativePath($target_directory);
367 $upload->moveOneFileTo(
$result, $relative_path_to_file, Location::STORAGE);
372 if (!$a_prevent_preview) {
394 if (
$result = $this->getUploadFile($a_upload_file, $a_filename,
true)) {
416 if (
$result = $this->getUploadFile($a_upload_file, $a_filename,
true)) {
431 public function copy($a_source, $a_destination)
454 if ($a_hist_entry_ids == null || count($a_hist_entry_ids) < 1) {
459 self::handleQuotaUpdate($this);
461 $actualVersionDeleted =
false;
467 foreach ($a_hist_entry_ids as $hist_id) {
472 if (
$version[
"hist_entry_id"] == $hist_id) {
482 $actualVersionDeleted =
true;
493 if ($actualVersionDeleted) {
500 self::handleQuotaUpdate($this);
510 $q =
"SELECT * FROM file_data WHERE file_id = %s";
511 $r = $DIC->database()->queryF($q, [
'integer'], [$this->
getId()]);
530 if ($this->
getMode() != self::MODE_FILELIST) {
543 $DIC->database()->update(
'file_data', $a_columns, [
551 $meta_version_column = [
'meta_version' => [
'integer', (int) $this->
getVersion()]];
552 $DIC->database()->update(
'il_meta_lifecycle', $meta_version_column, [
559 self::handleQuotaUpdate($this);
572 if (!is_object($technical = $md_obj->getTechnical())) {
573 $technical = $md_obj->addTechnical();
578 $format_ids = $technical->getFormatIds();
579 if (count($format_ids) > 0) {
580 $format = $technical->getFormat($format_ids[0]);
584 $format = $technical->addFormat();
588 $technical->update();
597 $this->filename = $a_name;
633 $this->filesize = $a_size;
645 $this->action = $a_action;
657 $this->rollback_version = $a_rollback_version;
669 $this->rollback_user_id = $a_rollback_user_id;
687 require_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
694 public function getFile($a_hist_entry_id = null)
696 if (is_null($a_hist_entry_id)) {
699 require_once(
"./Services/History/classes/class.ilHistory.php");
702 if ($entry ===
false) {
718 $this->version = $a_version;
730 $this->max_version = $a_max_version;
747 $this->mode = $a_mode;
765 $ilDB = $DIC[
'ilDB'];
767 $q =
"UPDATE file_data SET " .
" file_type = " .
$ilDB->quote($a_format,
'text')
768 .
" WHERE file_id = " .
$ilDB->quote($a_id,
'integer');
782 $ilDB = $DIC[
'ilDB'];
784 $q =
"SELECT * FROM file_data WHERE file_id = " .
$ilDB->quote($a_id,
'integer');
790 return $strip_slashes;
797 require_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
808 require_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
819 if (is_null($a_hist_entry_id)) {
822 require_once(
"./Services/History/classes/class.ilHistory.php");
825 if ($entry ===
false) {
832 if (is_file($file)) {
843 public function sendFile($a_hist_entry_id = null)
846 $s->sanitizeIfNeeded();
848 if (is_null($a_hist_entry_id)) {
858 if ($this->file_storage->fileExists($file)) {
860 $ilClientIniFile = $DIC[
'ilClientIniFile'];
868 $ilFileDelivery->setConvertFileNameToAsci((
bool) !$ilClientIniFile->readVariable(
'file_access',
'disable_ascii'));
871 if ($ilClientIniFile->readVariable(
'file_access',
'download_with_uploaded_filename')
873 && is_null($a_hist_entry_id)
882 $parts = explode(DIRECTORY_SEPARATOR, $file);
883 $download_file_name = end($parts);
885 $ilFileDelivery->setDownloadFileName($download_file_name);
887 $ilFileDelivery->deliver();
902 require_once
'Modules/File/classes/class.ilObjFileAccess.php';
915 require_once
'Modules/File/classes/class.ilObjFileAccess.php';
926 require_once
'Modules/File/classes/class.ilObjFileAccess.php';
941 $path = pathinfo($a_file);
942 if (
$path[
"extension"] !=
"") {
947 include_once(
"./Services/Utilities/classes/class.ilMimeTypeUtil.php");
967 $ilDB = $DIC[
'ilDB'];
969 $a_new_obj->createDirectory();
980 require_once(
"./Services/Preview/classes/class.ilPreview.php");
984 require_once(
"./Services/History/classes/class.ilHistory.php");
988 include_once(
'Services/Tracking/classes/class.ilLPObjSettings.php');
990 $obj_settings->cloneSettings($a_new_obj->getId());
991 unset($obj_settings);
994 $a_new_obj->addNewsNotification(
"file_created");
1003 $ilDB = $DIC[
'ilDB'];
1007 if (count($usages) == 0) {
1018 $ilDB = $DIC[
'ilDB'];
1021 $q =
"DELETE FROM file_data WHERE file_id = " .
$ilDB->quote($this->
getId(),
'integer');
1022 $this->
ilias->db->query($q);
1025 require_once(
"./Services/History/classes/class.ilHistory.php");
1028 self::handleQuotaUpdate($this);
1036 if ($this->
getMode() != self::MODE_FILELIST) {
1054 $subdir =
"il_" . IL_INST_ID .
"_file_" . $this->
getId();
1059 if (@!is_dir($filedir)) {
1063 ilUtil::rCopy($filedir, $a_target_dir .
"/objects/" . $subdir);
1073 $ilDB = $DIC[
'ilDB'];
1075 $and_hist = ($a_usage_hist_nr !==
false) ?
" AND usage_hist_nr = " 1076 .
$ilDB->quote($a_usage_hist_nr,
"integer") :
"";
1078 $file_ids = array();
1079 $set =
$ilDB->query(
"SELECT id FROM file_usage" .
" WHERE usage_type = " 1081 .
$ilDB->quote($a_id,
"integer") .
" AND usage_lang= " 1082 .
$ilDB->quote($a_usage_lang,
"text") . $and_hist);
1083 while (
$row =
$ilDB->fetchAssoc($set)) {
1084 $file_ids[] =
$row[
"id"];
1087 $ilDB->manipulate(
"DELETE FROM file_usage WHERE usage_type = " 1089 .
$ilDB->quote((
int) $a_id,
"integer") .
" AND usage_lang= " 1090 .
$ilDB->quote($a_usage_lang,
"text") .
" AND usage_hist_nr = " 1091 .
$ilDB->quote((
int) $a_usage_hist_nr,
"integer"));
1093 foreach ($file_ids as $file_id) {
1094 self::handleQuotaUpdate(
new self($file_id,
false));
1102 public static function _saveUsage($a_file_id,
$a_type, $a_id, $a_usage_hist_nr = 0, $a_usage_lang =
"-")
1105 $ilDB = $DIC[
'ilDB'];
1112 $ilDB->replace(
"file_usage", array(
1113 "id" => array(
"integer", (
int) $a_file_id),
1114 "usage_type" => array(
"text", (
string)
$a_type),
1115 "usage_id" => array(
"integer", (
int) $a_id),
1116 "usage_hist_nr" => array(
"integer", (
int) $a_usage_hist_nr),
1117 "usage_lang" => array(
"text", $a_usage_lang),
1120 self::handleQuotaUpdate(
new self($a_file_id,
false));
1130 $ilDB = $DIC[
'ilDB'];
1133 $q =
"SELECT * FROM file_usage WHERE id = " .
$ilDB->quote($this->
getId(),
"integer");
1134 $us_set =
$ilDB->query($q);
1136 while ($us_rec =
$ilDB->fetchAssoc($us_set)) {
1138 "type" => $us_rec[
"usage_type"],
1139 "id" => $us_rec[
"usage_id"],
1140 "lang" => $us_rec[
"usage_lang"],
1141 "hist_nr" => $us_rec[
"usage_hist_nr"],
1160 $ilDB = $DIC[
'ilDB'];
1163 if ($a_usage_lang !=
"") {
1164 $lstr =
"usage_lang = " .
$ilDB->quote((
string) $a_usage_lang,
"text") .
" AND ";
1168 $q =
"SELECT * FROM file_usage WHERE " .
"usage_id = " .
$ilDB->quote((
int) $a_id,
"integer")
1169 .
" AND " .
"usage_type = " .
$ilDB->quote((
string)
$a_type,
"text") .
" AND " . $lstr
1170 .
"usage_hist_nr = " .
$ilDB->quote((
int) $a_usage_hist_nr,
"integer");
1171 $file_set =
$ilDB->query($q);
1173 while ($file_rec =
$ilDB->fetchAssoc($file_set)) {
1174 $ret[$file_rec[
"id"]] = $file_rec[
"id"];
1185 $ilias = $DIC[
'ilias'];
1208 include_once(
"./Services/News/classes/class.ilNewsItem.php");
1209 include_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
1211 $news_item->setContext($this->
getId(), $this->
getType());
1213 $news_item->setTitle($a_lang_var);
1214 $news_item->setContentIsLangVar(
true);
1216 $news_item->setContent(
"<p>" . $this->
getDescription() .
"</p>");
1218 $news_item->setUserId(
$ilUser->getId());
1220 $news_item->create();
1275 $file_object =
new self($obj_id,
false);
1277 $s->sanitizeIfNeeded();
1279 return $file_object->getFile($a_version);
1290 include_once
'./Modules/File/classes/class.ilObjFileAccess.php';
1293 if ($titleExtension != $fileExtension && strlen($fileExtension) > 0) {
1296 $suffix = $pi[
"extension"];
1297 if ($suffix !=
"") {
1298 if (substr($new_title, strlen($new_title) - strlen($suffix) - 1) ==
"." . $suffix) {
1299 $new_title = substr($new_title, 0, strlen($new_title) - strlen($suffix) - 1);
1302 $new_title .=
'.' . $fileExtension;
1333 if ($version_ids != null && count($version_ids) > 0) {
1335 if (!in_array(
$version[
"hist_entry_id"], $version_ids,
true)) {
1336 unset($versions[
$index]);
1348 usort($versions, array($this,
"compareVersions"));
1363 include_once(
"./Services/History/classes/class.ilHistory.php");
1393 $ilDB = $DIC[
'ilDB'];
1398 $this->ilErr->raiseError($this->lng->txt(
"obj_not_found"), $this->ilErr->MESSAGE);
1408 if (@!is_dir($dest_dir)) {
1412 copy($source_path, $dest_dir .
"/" .
$source[
"filename"]);
1415 include_once(
"./Services/History/classes/class.ilHistory.php");
1418 . $new_version_nr .
"|" 1419 . $source[
"version"] .
"|" 1425 $newest_entry_id = 0;
1426 foreach ($entries as $entry) {
1427 if ($entry[
"action"] ==
"rollback") {
1428 $newest_entry_id = $entry[
"hist_entry_id"];
1432 $new_version[
'version'] = $new_version_nr;
1433 $new_version[
'max_version'] = $new_version_nr;
1443 return $new_version;
1488 return (
int) $v2[
"version"] - (int) $v1[
"version"];
1502 $data = explode(
",", $entry[
"info_params"]);
1506 if (empty(
$data[1])) {
1510 if (empty(
$data[2])) {
1515 if (
sizeof(
$data) > 3)
1517 $last =
sizeof(
$data) - 1;
1518 for (
$n = 1;
$n < $last - 1;
$n++)
1528 "filename" =>
$data[0],
1529 "version" =>
$data[1],
1530 "max_version" =>
$data[2],
1531 "rollback_version" =>
"",
1532 "rollback_user_id" =>
"",
1537 if ($entry[
"action"] ==
"rollback") {
1538 $tokens = explode(
"|",
$result[
"version"]);
1539 if (count($tokens) > 1) {
1540 $result[
"version"] = $tokens[0];
1541 $result[
"rollback_version"] = $tokens[1];
1543 if (count($tokens) > 2) {
1544 $result[
"rollback_user_id"] = $tokens[2];
1555 include_once
"Services/MediaObjects/classes/class.ilObjMediaObject.php";
1559 $parent_obj_ids = array($a_file->
getId());
1561 foreach ($a_file->
getUsages() as $item) {
1562 $parent_obj_id = $mob->getParentObjectIdForUsage($item);
1564 && !in_array($parent_obj_id, $parent_obj_ids)
1566 $parent_obj_ids[] = $parent_obj_id;
1570 include_once
"Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
1584 if ($this->
getMode() != self::MODE_OBJECT) {
1588 require_once(
"./Services/Preview/classes/class.ilPreview.php");
1599 if ($this->
getMode() != self::MODE_OBJECT) {
1603 require_once(
"./Services/Preview/classes/class.ilPreview.php");
1613 $this->rating = (bool) $a_value;
1651 if ($file_id == 0) {
1652 $file_id = $this->
getId();
1655 'file_id' => [
'integer', $file_id],
1658 'file_size' => [
'integer', (int) $this->
getFileSize()],
1659 'version' => [
'integer', (int) $this->
getVersion()],
1661 'f_mode' => [
'text', $this->
getMode()],
1663 'rating' => [
'integer', $this->
hasRating()],
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static _writeFileType($a_id, $a_format)
createProperties($a_upload=false)
The basic properties of a file object are stored in table object_data.
static _lookupDiskUsage($a_id)
Returns the number of bytes used on the harddisk by the file object with the specified object id...
setRollbackVersion($a_rollback_version)
static _removeEntryByHistoryID($a_hist_entry_id)
Removes a single entry from the history.
static _isFileInline($a_file_name)
Returns true, if the specified file shall be displayed inline in the browser.
parseInfoParams($entry)
Parses the info parameters ("info_params") of the specified history entry.
static _write($a_type, $a_setting, $a_value, $a_user=0, $a_block_id=0)
Write setting to database.
static _changeUserId($a_hist_entry_id, $new_user_id)
Changes the user id of the specified history entry.
setMode($a_mode)
mode is object or filelist
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
copy($a_source, $a_destination)
copy file
static _isFileHidden($a_file_name)
Returns true, if a file with the specified name, is usually hidden from the user. ...
static _getFileExtension($a_file_name)
Gets the file extension of the specified file name.
clearDataDirectory()
clear data directory
compareVersions($v1, $v2)
Compares two file versions.
getFile($a_hist_entry_id=null)
getMode()
mode is object or filelist
storeUnzipedFile($a_upload_file, $a_filename)
storeUnzipedFile
static _deleteAllUsages($a_type, $a_id, $a_usage_hist_nr=0, $a_usage_lang="-")
static delete all usages of
doCreateMetaData()
create file object meta data
getDirectory($a_version=0)
$metadata['__DYNAMIC:1__']
setNoMetaDataCreation($a_status)
doCreate($a_upload=false)
create object
static _createEntry( $a_obj_id, $a_action, $a_info_params="", $a_obj_type="", $a_user_comment="", $a_update_last=false)
Creates a new history entry for an object.
static _getEntryByHistoryID($a_hist_entry_id)
returns a single history entry
beforeMDUpdateListener($a_element)
checkFileExtension($new_filename, $new_title)
Check if the file extension does still exist after an update of the title.
static _lookupFileSize($a_id)
Quickly looks up the file size from the database and returns the number of bytes. ...
doUpdateMetaData()
update meta data
static rename($a_source, $a_target)
Rename a file.
replaceFile($a_upload_file, $a_filename)
static getMimeType($a_file='', $a_filename='', $a_mime='')
setRollbackUserId($a_rollback_user_id)
static _copyEntriesForObject($a_src_id, $a_dst_id)
copy all history entries for an object
foreach($_POST as $key=> $value) $res
static _lookupFileName($a_id)
static getBytesForString($a_str)
Return string as byte array Note: Use this for debugging purposes only.
addFileVersion($a_upload_file, $a_filename)
static createPreview($a_obj, $a_force=false)
Creates the preview for the object with the specified id.
deletePreview()
Deletes the preview of the file object.
isHidden()
Returns true, if this file should be hidden in the repository view.
Class to report exception.
getArrayForDatabase($file_id=0)
redirection script todo: (a better solution should control the processing via a xml file) ...
static _saveUsage($a_file_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_usage_lang="-")
save usage
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
isInline()
Returns true, if this file should be displayed inline in a browser window.
createPreview($force=false)
Creates a preview for the file object.
getSpecificVersion($version_id)
Gets a specific file version.
static _getFilesOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_usage_lang="-")
get all files of an object
static _getEntriesForObject($a_obj_id, $a_obj_type="")
get all history entries for an object
addNewsNotification($a_lang_var)
static _lookupType($a_id, $a_reference=false)
lookup object type
getUsages()
get all usages of file object
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
doCloneObject($a_new_obj, $a_target_id, $a_copy_id=0)
Clone.
setMaxVersion($a_max_version)
static copyPreviews($a_src_id, $a_dest_id)
Copies the preview images from one preview to a new preview object.
deleteVersions($a_hist_entry_ids=null)
Deletes the specified history entries or all entries if no ids are specified.
static _lookupFileSize($a_id)
Lookups the file size of the file in bytes.
getFileExtension()
Returns the extension of the file name converted to lower-case.
static handleQuotaUpdate(ilObjFile $a_file)
rollback($version_id)
Makes the specified version the current one and returns theSummary of rollbackVersion.
export($a_target_dir)
export files of object to target directory note: target directory must be the export target directory...
static _lookupVersion($a_id)
lookup version
static escapeShellArg($a_arg)
initFileStorage()
init file storage object
static handleUpdatedSourceObject($a_src_obj_type, $a_src_obj_id, $a_src_filesize, $a_owner_obj_ids=null, $a_is_prtf=false)
Find and update/create all related entries for source object.
setPageCount($page_count)
static deletePreview($a_obj_id)
Deletes the preview for the object with the specified id.
static _lookupAbsolutePath($obj_id, $a_version=null)
static _getDefaultVisibilityForRefId($a_ref_id)
Get default visibility for reference id.
static _removeEntriesForObject($a_obj_id)
remove all history entries for an object
Class FileNotFoundException.
static getLogger($a_component_id)
Get component logger.
raiseUploadError($a_raise=true)
doMDUpdateListener($a_element)
static _lookupVersion($a_id)
lookup version
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
determineFileSize($a_hist_entry_id=null)
Determine File Size.
__construct($a_id=0, $a_call_by_reference=true)
ilObjFile constructor.
getVersions($version_ids=null)
Gets the file versions for this object.
static getValidFilename($a_filename)
Get valid filename.
guessFileType($a_file="")
Guesses the file type based on the current values returned by getFileType() and getFileExtension().
updateWithVersion($version)
Updates the file object with the specified file version.
cloneMetaData($target_obj)
getDiskUsage()
Gets the disk usage of the object in bytes.