9 require_once(
"Services/Object/classes/class.ilObject2.php");
10 require_once(
'Modules/File/classes/class.ilFSStorageFile.php');
53 public $mode = self::MODE_OBJECT;
98 public function __construct($a_id = 0, $a_call_by_reference =
true)
101 $this->max_version = 0;
102 $this->raise_upload_error =
true;
108 if ($this->
getId()) {
116 $this->type =
"file";
144 $this->file_storage->create();
156 if ($default_visibility ==
"public") {
161 $this->log->debug(
"ilObjFile::createProperties, ID: " . $this->
getId() .
", Name: " 171 'meta_lifecycle_id' => [
'integer', $DIC->database()->nextId(
'il_meta_lifecycle')],
172 'rbac_id' => [
'integer', $this->
getId()],
173 'obj_id' => [
'integer', $this->
getId()],
174 'obj_type' => [
'text',
"file"],
175 'meta_version' => [
'integer', (int) $this->
getVersion()],
177 $DIC->database()->insert(
'il_meta_lifecycle', $metadata);
180 if ($this->
getMode() != self::MODE_FILELIST) {
191 $this->no_meta_data_creation = (bool) $a_status;
197 return !(bool) $this->no_meta_data_creation;
203 return !(bool) $this->no_meta_data_creation;
214 $technical = $md_obj->addTechnical();
217 $format = $technical->addFormat();
220 $technical->update();
228 include_once
'Services/MetaData/classes/class.ilMD.php';
230 if (!is_object($md_gen = $md->getGeneral())) {
234 $md_gen->setTitle(
$title);
244 include_once
'Services/MetaData/classes/class.ilMD.php';
246 switch ($a_element) {
251 if (!is_object($md_technical = $md->getTechnical())) {
255 foreach ($md_technical->getFormatIds() as
$id) {
256 $md_format = $md_technical->getFormat(
$id);
276 $version_subdir =
"";
280 $version_subdir = sprintf(
"%03d", $a_version);
284 if (!is_object($this->file_storage)) {
288 $str = $this->file_storage->getAbsolutePath() .
'/' . $version_subdir;
302 $this->raise_upload_error = $a_raise;
315 public function getUploadFile($a_upload_file, $a_filename, $a_prevent_preview =
false)
319 $upload = $DIC->upload();
322 if ($upload->hasUploads()) {
323 if (!$upload->hasBeenProcessed()) {
329 $result = $upload->getResults()[$a_upload_file];
331 $metadata =
$result->getMetaData();
347 $relative_path_to_file = LegacyPathHelper::createRelativePath($target_directory);
349 $upload->moveOneFileTo(
$result, $relative_path_to_file, Location::STORAGE);
354 if (!$a_prevent_preview) {
377 if (
$result = $this->getUploadFile($a_upload_file, $a_filename,
true)) {
399 if (
$result = $this->getUploadFile($a_upload_file, $a_filename,
true)) {
414 public function copy($a_source, $a_destination)
437 if ($a_hist_entry_ids == null || count($a_hist_entry_ids) < 1) {
442 self::handleQuotaUpdate($this);
444 $actualVersionDeleted =
false;
450 foreach ($a_hist_entry_ids as $hist_id) {
455 if (
$version[
"hist_entry_id"] == $hist_id) {
465 $actualVersionDeleted =
true;
476 if ($actualVersionDeleted) {
483 self::handleQuotaUpdate($this);
493 $q =
"SELECT * FROM file_data WHERE file_id = %s";
494 $r = $DIC->database()->queryF($q, [
'integer'], [$this->
getId()]);
495 $row = $r->fetchObject();
497 $this->
setFileName($this->secure($row->file_name));
500 $this->
setVersion($row->version ? $row->version : 1);
501 $this->
setMaxVersion($row->max_version ? $row->max_version : 1);
513 if ($this->
getMode() != self::MODE_FILELIST) {
526 $DIC->database()->update(
'file_data', $a_columns, [
534 $meta_version_column = [
'meta_version' => [
'integer', (int) $this->
getVersion()]];
535 $DIC->database()->update(
'il_meta_lifecycle', $meta_version_column, [
542 self::handleQuotaUpdate($this);
555 if (!is_object($technical = $md_obj->getTechnical())) {
556 $technical = $md_obj->addTechnical();
561 $format_ids = $technical->getFormatIds();
562 if (count($format_ids) > 0) {
563 $format = $technical->getFormat($format_ids[0]);
567 $format = $technical->addFormat();
571 $technical->update();
580 $this->filename = $a_name;
616 $this->filesize = $a_size;
628 $this->action = $a_action;
640 $this->rollback_version = $a_rollback_version;
652 $this->rollback_user_id = $a_rollback_user_id;
670 require_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
677 public function getFile($a_hist_entry_id = null)
679 if (is_null($a_hist_entry_id)) {
682 require_once(
"./Services/History/classes/class.ilHistory.php");
685 if ($entry ===
false) {
701 $this->version = $a_version;
713 $this->max_version = $a_max_version;
730 $this->mode = $a_mode;
748 $ilDB = $DIC[
'ilDB'];
750 $q =
"UPDATE file_data SET " .
" file_type = " .
$ilDB->quote($a_format,
'text')
751 .
" WHERE file_id = " .
$ilDB->quote($a_id,
'integer');
765 $ilDB = $DIC[
'ilDB'];
767 $q =
"SELECT * FROM file_data WHERE file_id = " .
$ilDB->quote($a_id,
'integer');
768 $r =
$ilDB->query($q);
773 return $strip_slashes;
780 require_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
791 require_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
802 if (is_null($a_hist_entry_id)) {
805 require_once(
"./Services/History/classes/class.ilHistory.php");
808 if ($entry ===
false) {
815 if (is_file($file)) {
826 public function sendFile($a_hist_entry_id = null)
829 $s->sanitizeIfNeeded();
831 if (is_null($a_hist_entry_id)) {
840 if ($this->file_storage->fileExists($file)) {
842 $ilClientIniFile = $DIC[
'ilClientIniFile'];
850 $ilFileDelivery->setConvertFileNameToAsci((
bool) !$ilClientIniFile->readVariable(
'file_access',
'disable_ascii'));
853 if ($ilClientIniFile->readVariable(
'file_access',
'download_with_uploaded_filename')
855 && is_null($a_hist_entry_id)
864 $parts = explode(DIRECTORY_SEPARATOR, $file);
865 $download_file_name = end($parts);
867 $ilFileDelivery->setDownloadFileName($download_file_name);
869 $ilFileDelivery->deliver();
884 require_once
'Modules/File/classes/class.ilObjFileAccess.php';
897 require_once
'Modules/File/classes/class.ilObjFileAccess.php';
908 require_once
'Modules/File/classes/class.ilObjFileAccess.php';
923 $path = pathinfo($a_file);
924 if ($path[
"extension"] !=
"") {
929 include_once(
"./Services/Utilities/classes/class.ilMimeTypeUtil.php");
949 $ilDB = $DIC[
'ilDB'];
951 $a_new_obj->createDirectory();
958 $query =
"INSERT INTO file_data (file_id,file_name,file_type,file_size,version,rating,f_mode) VALUES (" 959 .
$ilDB->quote($a_new_obj->getId(),
'integer') .
"," 960 .
$ilDB->quote($this->getFileName(),
'text') .
"," 961 .
$ilDB->quote($this->getFileType(),
'text') .
"," 962 .
$ilDB->quote((
int) $this->getFileSize(),
'integer') .
", " 963 .
$ilDB->quote($this->getVersion(),
'integer') .
", " 964 .
$ilDB->quote($this->hasRating(),
'integer') .
", " 965 .
$ilDB->quote($this->getMode(),
'text') .
")";
969 require_once(
"./Services/Preview/classes/class.ilPreview.php");
973 require_once(
"./Services/History/classes/class.ilHistory.php");
977 include_once(
'Services/Tracking/classes/class.ilLPObjSettings.php');
979 $obj_settings->cloneSettings($a_new_obj->getId());
980 unset($obj_settings);
983 $a_new_obj->addNewsNotification(
"file_created");
992 $ilDB = $DIC[
'ilDB'];
996 if (count($usages) == 0) {
1007 $ilDB = $DIC[
'ilDB'];
1010 $q =
"DELETE FROM file_data WHERE file_id = " .
$ilDB->quote($this->
getId(),
'integer');
1011 $this->
ilias->db->query($q);
1014 require_once(
"./Services/History/classes/class.ilHistory.php");
1017 self::handleQuotaUpdate($this);
1025 if ($this->
getMode() != self::MODE_FILELIST) {
1043 $subdir =
"il_" . IL_INST_ID .
"_file_" . $this->
getId();
1048 if (@!is_dir($filedir)) {
1052 ilUtil::rCopy($filedir, $a_target_dir .
"/objects/" . $subdir);
1062 $ilDB = $DIC[
'ilDB'];
1064 $and_hist = ($a_usage_hist_nr !==
false) ?
" AND usage_hist_nr = " 1065 .
$ilDB->quote($a_usage_hist_nr,
"integer") :
"";
1067 $file_ids = array();
1068 $set =
$ilDB->query(
"SELECT id FROM file_usage" .
" WHERE usage_type = " 1070 .
$ilDB->quote($a_id,
"integer") .
" AND usage_lang= " 1071 .
$ilDB->quote($a_usage_lang,
"text") . $and_hist);
1072 while ($row =
$ilDB->fetchAssoc($set)) {
1073 $file_ids[] = $row[
"id"];
1076 $ilDB->manipulate(
"DELETE FROM file_usage WHERE usage_type = " 1078 .
$ilDB->quote((
int) $a_id,
"integer") .
" AND usage_lang= " 1079 .
$ilDB->quote($a_usage_lang,
"text") .
" AND usage_hist_nr = " 1080 .
$ilDB->quote((
int) $a_usage_hist_nr,
"integer"));
1082 foreach ($file_ids as $file_id) {
1083 self::handleQuotaUpdate(
new self($file_id,
false));
1091 public static function _saveUsage($a_file_id,
$a_type, $a_id, $a_usage_hist_nr = 0, $a_usage_lang =
"-")
1094 $ilDB = $DIC[
'ilDB'];
1101 $ilDB->replace(
"file_usage", array(
1102 "id" => array(
"integer", (
int) $a_file_id),
1103 "usage_type" => array(
"text", (
string)
$a_type),
1104 "usage_id" => array(
"integer", (
int) $a_id),
1105 "usage_hist_nr" => array(
"integer", (
int) $a_usage_hist_nr),
1106 "usage_lang" => array(
"text", $a_usage_lang),
1109 self::handleQuotaUpdate(
new self($a_file_id,
false));
1119 $ilDB = $DIC[
'ilDB'];
1122 $q =
"SELECT * FROM file_usage WHERE id = " .
$ilDB->quote($this->
getId(),
"integer");
1123 $us_set =
$ilDB->query($q);
1125 while ($us_rec =
$ilDB->fetchAssoc($us_set)) {
1127 "type" => $us_rec[
"usage_type"],
1128 "id" => $us_rec[
"usage_id"],
1129 "lang" => $us_rec[
"usage_lang"],
1130 "hist_nr" => $us_rec[
"usage_hist_nr"],
1149 $ilDB = $DIC[
'ilDB'];
1152 if ($a_usage_lang !=
"") {
1153 $lstr =
"usage_lang = " .
$ilDB->quote((
string) $a_usage_lang,
"text") .
" AND ";
1157 $q =
"SELECT * FROM file_usage WHERE " .
"usage_id = " .
$ilDB->quote((
int) $a_id,
"integer")
1158 .
" AND " .
"usage_type = " .
$ilDB->quote((
string)
$a_type,
"text") .
" AND " . $lstr
1159 .
"usage_hist_nr = " .
$ilDB->quote((
int) $a_usage_hist_nr,
"integer");
1160 $file_set =
$ilDB->query($q);
1162 while ($file_rec =
$ilDB->fetchAssoc($file_set)) {
1163 $ret[$file_rec[
"id"]] = $file_rec[
"id"];
1174 $ilias = $DIC[
'ilias'];
1197 include_once(
"./Services/News/classes/class.ilNewsItem.php");
1198 include_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
1200 $news_item->setContext($this->
getId(), $this->
getType());
1202 $news_item->setTitle($a_lang_var);
1203 $news_item->setContentIsLangVar(
true);
1205 $news_item->setContent(
"<p>" . $this->
getDescription() .
"</p>");
1207 $news_item->setUserId(
$ilUser->getId());
1209 $news_item->create();
1264 $file_object =
new self($obj_id,
false);
1266 $s->sanitizeIfNeeded();
1268 return $file_object->getFile($a_version);
1279 include_once
'./Modules/File/classes/class.ilObjFileAccess.php';
1282 if ($titleExtension != $fileExtension && strlen($fileExtension) > 0) {
1285 $suffix = $pi[
"extension"];
1286 if ($suffix !=
"") {
1287 if (substr($new_title, strlen($new_title) - strlen($suffix) - 1) ==
"." . $suffix) {
1288 $new_title = substr($new_title, 0, strlen($new_title) - strlen($suffix) - 1);
1291 $new_title .=
'.' . $fileExtension;
1322 if ($version_ids != null && count($version_ids) > 0) {
1324 if (!in_array(
$version[
"hist_entry_id"], $version_ids,
true)) {
1325 unset($versions[
$index]);
1337 usort($versions, array($this,
"compareVersions"));
1352 include_once(
"./Services/History/classes/class.ilHistory.php");
1368 return array_merge(
$version, $params);
1382 $ilDB = $DIC[
'ilDB'];
1387 $this->ilErr->raiseError($this->lng->txt(
"obj_not_found"), $this->ilErr->MESSAGE);
1397 if (@!is_dir($dest_dir)) {
1401 copy($source_path, $dest_dir .
"/" .
$source[
"filename"]);
1404 include_once(
"./Services/History/classes/class.ilHistory.php");
1406 . $new_version_nr .
"," 1408 . $source[
"version"] .
"|" 1413 $newest_entry_id = 0;
1414 foreach ($entries as $entry) {
1415 if ($entry[
"action"] ==
"rollback") {
1416 $newest_entry_id = $entry[
"hist_entry_id"];
1420 $new_version[
'version'] = $new_version_nr;
1421 $new_version[
'max_version'] = $new_version_nr;
1431 return $new_version;
1476 return (
int) $v2[
"version"] - (int) $v1[
"version"];
1490 $data = explode(
",", $entry[
"info_params"]);
1494 if (empty(
$data[1])) {
1498 if (empty(
$data[2])) {
1503 "filename" =>
$data[0],
1504 "version" =>
$data[1],
1505 "max_version" =>
$data[2],
1506 "rollback_version" =>
"",
1507 "rollback_user_id" =>
"",
1511 if ($entry[
"action"] ==
"rollback") {
1512 $tokens = explode(
"|",
$result[
"max_version"]);
1513 if (count($tokens) > 1) {
1514 $result[
"max_version"] = $tokens[0];
1515 $result[
"rollback_version"] = $tokens[1];
1517 if (count($tokens) > 2) {
1518 $result[
"rollback_user_id"] = $tokens[2];
1529 include_once
"Services/MediaObjects/classes/class.ilObjMediaObject.php";
1533 $parent_obj_ids = array($a_file->
getId());
1535 foreach ($a_file->
getUsages() as $item) {
1536 $parent_obj_id = $mob->getParentObjectIdForUsage($item);
1538 && !in_array($parent_obj_id, $parent_obj_ids)
1540 $parent_obj_ids[] = $parent_obj_id;
1544 include_once
"Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
1558 if ($this->
getMode() != self::MODE_OBJECT) {
1562 require_once(
"./Services/Preview/classes/class.ilPreview.php");
1573 if ($this->
getMode() != self::MODE_OBJECT) {
1577 require_once(
"./Services/Preview/classes/class.ilPreview.php");
1587 $this->rating = (bool) $a_value;
1624 'file_id' => [
'integer', $this->
getId()],
1627 'file_size' => [
'integer', (int) $this->
getFileSize()],
1628 'version' => [
'integer', (int) $this->
getVersion()],
1630 'f_mode' => [
'text', $this->
getMode()],
1632 '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)
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
getId()
get object id public
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.
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
__construct(Container $dic, ilPlugin $plugin)
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.