9require_once(
"Services/Object/classes/class.ilObject2.php");
10require_once(
'Modules/File/classes/class.ilFSStorageFile.php');
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);
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];
329 if (
$result->getStatus()->getCode() === \
ILIAS\FileUpload\DTO\ProcessingStatus::OK) {
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) {
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) {
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, [
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;
767 $q =
"UPDATE file_data SET " .
" file_type = " .
$ilDB->quote($a_format,
'text')
768 .
" WHERE file_id = " .
$ilDB->quote($a_id,
'integer');
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");
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");
1007 if (count($usages) == 0) {
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");
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);
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) {
1102 public static function _saveUsage($a_file_id,
$a_type, $a_id, $a_usage_hist_nr = 0, $a_usage_lang =
"-")
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),
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"],
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");
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 .
"|"
1421 . $this->getMaxVersion());
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()],
$metadata['__DYNAMIC:1__']
An exception for terminatinating execution or to throw for unit testing.
Class FileNotFoundException.
static _write($a_type, $a_setting, $a_value, $a_user=0, $a_block_id=0)
Write setting to database.
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.
Class to report exception.
static getValidFilename($a_filename)
Get valid filename.
static rename($a_source, $a_target)
Rename a file.
static _removeEntryByHistoryID($a_hist_entry_id)
Removes a single entry from the history.
static _changeUserId($a_hist_entry_id, $new_user_id)
Changes the user id of the specified history entry.
static _removeEntriesForObject($a_obj_id)
remove all history entries for an object
static _getEntriesForObject($a_obj_id, $a_obj_type="")
get all history entries for an 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 _copyEntriesForObject($a_src_id, $a_dst_id)
copy all history entries for an object
static _getEntryByHistoryID($a_hist_entry_id)
returns a single history entry
static getLogger($a_component_id)
Get component logger.
static getMimeType($a_file='', $a_filename='', $a_mime='')
static _getDefaultVisibilityForRefId($a_ref_id)
Get default visibility for reference id.
static _lookupFileSize($a_id)
Quickly looks up the file size from the database and returns the number of bytes.
static _lookupVersion($a_id)
lookup version
static _getFileExtension($a_file_name)
Gets the file extension of the specified file name.
static _isFileHidden($a_file_name)
Returns true, if a file with the specified name, is usually hidden from the user.
static _isFileInline($a_file_name)
Returns true, if the specified file shall be displayed inline in the browser.
static _lookupDiskUsage($a_id)
Returns the number of bytes used on the harddisk by the file object with the specified object id.
getArrayForDatabase($file_id=0)
static _lookupFileSize($a_id)
Lookups the file size of the file in bytes.
static _lookupFileName($a_id)
raiseUploadError($a_raise=true)
setMaxVersion($a_max_version)
clearDataDirectory()
clear data directory
static handleQuotaUpdate(ilObjFile $a_file)
updateWithVersion($version)
Updates the file object with the specified file version.
static _getFilesOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_usage_lang="-")
get all files of an object
doCreate($a_upload=false)
create object
addFileVersion($a_upload_file, $a_filename)
createProperties($a_upload=false)
The basic properties of a file object are stored in table object_data.
getFile($a_hist_entry_id=null)
doUpdateMetaData()
update meta data
initFileStorage()
init file storage object
static _saveUsage($a_file_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_usage_lang="-")
save usage
beforeMDUpdateListener($a_element)
copy($a_source, $a_destination)
copy file
createPreview($force=false)
Creates a preview for the file object.
doMDUpdateListener($a_element)
isInline()
Returns true, if this file should be displayed inline in a browser window.
__construct($a_id=0, $a_call_by_reference=true)
ilObjFile constructor.
getSpecificVersion($version_id)
Gets a specific file version.
static _lookupAbsolutePath($obj_id, $a_version=null)
doCreateMetaData()
create file object meta data
getVersions($version_ids=null)
Gets the file versions for this object.
setMode($a_mode)
mode is object or filelist
deleteVersions($a_hist_entry_ids=null)
Deletes the specified history entries or all entries if no ids are specified.
setRollbackUserId($a_rollback_user_id)
replaceFile($a_upload_file, $a_filename)
doCloneObject($a_new_obj, $a_target_id, $a_copy_id=0)
Clone.
export($a_target_dir)
export files of object to target directory note: target directory must be the export target directory...
setNoMetaDataCreation($a_status)
checkFileExtension($new_filename, $new_title)
Check if the file extension does still exist after an update of the title.
static _deleteAllUsages($a_type, $a_id, $a_usage_hist_nr=0, $a_usage_lang="-")
static delete all usages of
getDirectory($a_version=0)
getMode()
mode is object or filelist
deletePreview()
Deletes the preview of the file object.
compareVersions($v1, $v2)
Compares two file versions.
static _writeFileType($a_id, $a_format)
setRollbackVersion($a_rollback_version)
addNewsNotification($a_lang_var)
determineFileSize($a_hist_entry_id=null)
Determine File Size.
setPageCount($page_count)
getUsages()
get all usages of file object
getFileExtension()
Returns the extension of the file name converted to lower-case.
static _lookupVersion($a_id)
lookup version
getDiskUsage()
Gets the disk usage of the object in bytes.
parseInfoParams($entry)
Parses the info parameters ("info_params") of the specified history entry.
guessFileType($a_file="")
Guesses the file type based on the current values returned by getFileType() and getFileExtension().
rollback($version_id)
Makes the specified version the current one and returns theSummary of rollbackVersion.
storeUnzipedFile($a_upload_file, $a_filename)
storeUnzipedFile
isHidden()
Returns true, if this file should be hidden in the repository view.
Class ilObject2 This is an intermediate progress of ilObject class.
setTitle($a_title)
set object title
createMetaData()
create meta data entry
cloneMetaData($target_obj)
Copy meta data.
deleteMetaData()
delete meta data entry
updateMetaData()
update meta data entry
getType()
get object type @access public
getDescription()
get object description
update()
update object in db
getId()
get object id @access public
getTitle()
get object title @access public
static _lookupType($a_id, $a_reference=false)
lookup object type
static copyPreviews($a_src_id, $a_dest_id)
Copies the preview images from one preview to a new preview object.
static deletePreview($a_obj_id)
Deletes the preview for the object with the specified id.
static createPreview($a_obj, $a_force=false)
Creates the preview for the object with the specified id.
static getBytesForString($a_str)
Return string as byte array Note: Use this for debugging purposes only.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static escapeShellArg($a_arg)
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
redirection script todo: (a better solution should control the processing via a xml file)
foreach($_POST as $key=> $value) $res