62 public string $mode = self::MODE_OBJECT;
75 public function __construct(
int $a_id = 0,
bool $a_call_by_reference =
true)
78 $this->manager = $DIC->resourceStorage()->manage();
79 $this->database = $DIC->database();
82 $this->
upload = $DIC->upload();
92 $this->file_info = $is_ref_id ? $repository->getByRefId($id) : $repository->getByObjectId($id);
98 return $this->file_info->getHeaderTitle();
103 if ($this->resource_id && (
$id = $this->manager->find(
106 $resource = $this->manager->getResource(
$id);
108 $this->max_version = $resource->getMaxRevision(
false);
109 $this->version = $resource->getCurrentRevision()->getVersionNumber();
117 $this->manager->getCurrentRevision($this->manager->find($this->getResourceId()))
136 $suffix = $this->file_info->getSuffix();
138 if (empty($suffix) || $suffix !== $filename_suffix) {
139 $suffix = $filename_suffix;
153 ?? pathinfo($stream->getMetadata(
'uri'))[
'extension']
156 if ($this->
getResourceId() && $i = $this->manager->find($this->getResourceId())) {
157 $revision = $this->manager->appendNewRevisionFromStream($i, $stream, $this->stakeholder, $title);
159 $i = $this->manager->stream($stream, $this->stakeholder, $title);
160 $revision = $this->manager->getCurrentRevision($i);
167 return $revision->getVersionNumber();
177 $revision = $this->manager->appendNewRevision($i, $result, $this->stakeholder, $title);
179 $i = $this->manager->upload($result, $this->stakeholder, $title);
180 $revision = $this->manager->getCurrentRevision($i);
190 return $revision->getVersionNumber();
198 if ($this->
getResourceId() && $i = $this->manager->find($this->getResourceId())) {
199 $revision = $this->manager->replaceWithStream($i, $stream, $this->stakeholder, $title);
201 throw new LogicException(
'only files with existing resource and revision can be replaced');
206 return $revision->getVersionNumber();
216 $revision = $this->manager->replaceWithUpload($i, $result, $this->stakeholder, $title);
218 throw new LogicException(
'only files with existing resource and revision can be replaced');
226 return $revision->getVersionNumber();
235 return $this->implementation->getFile($a_hist_entry_id);
240 return $this->implementation->getDirectory($a_version);
245 return $this->implementation->getDownloadFilename();
255 $this->important_info = empty($a_important_info) ?
null : $a_important_info;
260 return $this->implementation->getVersion($inclduing_drafts);
265 $this->version = $a_version;
270 return $this->implementation->getFileName();
275 $this->filename = $a_name;
280 $this->rating = $a_value;
291 return $this->resource_id ??
'-';
296 return $this->implementation->getStorageID();
309 $this->mode = $a_mode;
314 return $this->implementation->getFileSize();
327 return $this->implementation->getFileType();
386 return $this->on_click_mode === self::CLICK_MODE_DOWNLOAD;
410 $this->amount_of_downloads = $amount;
430 $new_title = $this->
ensureSuffix($new_title, $this->file_info->getSuffix());
432 $this->implementation->handleChangedObjectTitle($new_title);
435 protected function doCreate(
bool $clone_mode =
false): void
445 $q =
"SELECT * FROM file_data WHERE file_id = %s";
446 $r = $this->database->queryF(
$q, [
'integer'], [$this->
getId()]);
447 $row =
$r->fetchObject();
449 $this->filename = $this->secure($row->file_name ??
'');
450 $this->filetype = $row->file_type ??
'';
451 $this->filesize = $row->file_size ?? 0;
452 $this->version = $row->version ?? 1;
453 $this->max_version = $row->max_version ?? 1;
454 $this->mode = $row->f_mode ?? self::MODE_OBJECT;
455 $this->important_info = $row->important_info ??
"";
456 $this->rating = (bool) ($row->rating ??
false);
457 $this->page_count = (
int) ($row->page_count ?? 0);
458 $this->resource_id = $row->rid ??
null;
459 $this->on_click_mode = (
int) ($row->on_click_mode ?? self::CLICK_MODE_DOWNLOAD);
460 $this->amount_of_downloads = (
int) ($row->downloads ?? 0);
468 $identification = $this->manager->find($this->resource_id);
469 if ($identification ===
null) {
470 throw new RuntimeException(
'Cannot clone file since no corresponding resource identification was found');
475 $new_obj->updateFileData();
478 $cloned_title = $new_obj->
getTitle();
479 $new_resource_identification = $this->manager->clone($identification);
480 $new_current_revision = $this->manager->getCurrentRevision($new_resource_identification);
481 $new_obj->setResourceId($new_resource_identification->serialize());
482 $new_obj->initImplementation();
483 $new_obj->updateObjectFromRevision($new_current_revision);
492 $obj_settings->cloneSettings($new_obj->
getId());
493 unset($obj_settings);
499 $this->database->update(
'file_data', $a_columns, [
513 $suffix = $this->file_info->getSuffix();
514 if (empty($suffix)) {
520 if ($this->
getMode() !== self::MODE_FILELIST) {
532 $usages = $this->getUsages();
533 return $usages === [];
539 $this->database->manipulateF(
"DELETE FROM file_data WHERE file_id = %s", [
'integer'], [$this->
getId()]);
545 if ($this->
getMode() !== self::MODE_FILELIST) {
551 if ($identification && $identification !==
'-') {
552 $resource = $this->manager->find($identification);
553 if ($resource !==
null) {
554 $this->manager->remove($resource, $this->stakeholder);
565 'file_id' => [
'integer', $this->
getId()],
567 'f_mode' => [
'text', $this->
getMode()],
570 'rating' => [
'integer', $this->
hasRating()],
571 'rid' => [
'text', $this->resource_id ??
''],
579 $this->type = self::OBJECT_TYPE;
594 if (!$this->
upload->hasBeenProcessed()) {
595 if (defined(
'PATH_TO_GHOSTSCRIPT') && PATH_TO_GHOSTSCRIPT !==
"") {
634 $this->implementation->clearDataDirectory();
643 $this->implementation->deleteVersions($a_hist_entry_ids);
645 if ($this->
getResourceId() && $rid = $this->manager->find($this->getResourceId())) {
646 $latest_revision = $this->manager->getCurrentRevision($rid);
651 public function sendFile(?
int $a_hist_entry_id =
null,
bool $inline =
true): void
657 $this->implementation->sendFile($a_hist_entry_id, $info->shouldDeliverInline());
663 public function export(
string $a_target_dir): void
674 return $this->implementation->getVersions($version_ids);
683 if ($this->
getResourceId() && $i = $this->manager->find($this->getResourceId())) {
684 $this->manager->rollbackRevision($i, $version_id);
685 $latest_revision = $this->manager->getCurrentRevision($i);
688 throw new LogicException(
'only files with existing resource and revision can be replaced');
702 return $this->implementation->getFileExtension();
707 return $this->secure(preg_replace(
'/\.[^.]*$/',
'', $a_title));
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjFileStakeholder.
Class ilObjFileImplementationStorage.
setFileName(string $a_name)
static getLogger(string $a_component_id)
Get component logger.
updateObjectFromRevision(Revision $r)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
cloneMetaData(ilObject $target_obj)
replaceWithUpload(UploadResult $result, string $title)
doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id=0)
appendSuffixToTitle(string $title, string $filename)
rollback(int $version_id)
Makes the specified version the current one.
static _isFileHidden(string $a_file_name)
Returns true, if a file with the specified name, is usually hidden from the user. ...
getDirectory($a_version=0)
updateObjectFromCurrentRevision()
appendUpload(UploadResult $result, string $title)
doCreate(bool $clone_mode=false)
ilObjFileImplementationInterface $implementation
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
replaceFile($a_upload_file, $a_filename)
setAction(string $a_action)
initFileInfo(int $id, bool $is_ref_id)
static _removeEntriesForObject(int $a_obj_id)
remove all history entries for an object
getVersion(bool $inclduing_drafts=false)
appendStream(FileStream $stream, string $title)
stripTitleOfFileExtension(string $a_title)
ilObjFileStakeholder $stakeholder
const CLICK_MODE_DOWNLOAD
getUploadFile($a_upload_file, string $title, bool $a_prevent_preview=false)
This Method is used to append a fileupload by it's POST-name to the current ilObjFile ...
Class ResourceIdentification.
setPageCount(int $page_count)
extractSuffixFromFilename(string $filename)
setVersion(int $a_version)
setMaxVersion(int $a_max_version)
__construct(int $a_id=0, bool $a_call_by_reference=true)
ilObjFile constructor.
setOnclickMode(int $on_click_mode)
deleteVersions($a_hist_entry_ids=null)
trait ilObjFileSecureString
Trait ilObjFileSecureString.
getFileExtension()
Returns the extension of the file name converted to lower-case.
notifyUpdate(int $obj_id, ?string $additional_message=null)
replaceWithStream(FileStream $stream, string $title)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
__construct(Container $dic, ilPlugin $plugin)
setAmountOfDownloads(int $amount)
sendFile(?int $a_hist_entry_id=null, bool $inline=true)
checkFileExtension(string $new_filename, string $new_title)
notifyCreation(int $obj_id, ?string $additional_message=null)
Class ilCountPDFPagesPreProcessors.
setFileType(string $a_type)
setImportantInfo(string $a_important_info)
setResourceId(?string $resource_id)
handleChangedObjectTitle(string $new_title)
static getInstance(int $obj_id)
The base interface for all filesystem streams.
getVersions($version_ids=null)
export(string $a_target_dir)
ensureSuffix(string $title, ?string $suffix=null)
setCopyrightID(?string $copyright_id)
const CLICK_MODE_INFOPAGE
trait ilObjFileNews
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getFile(?int $a_hist_entry_id=null)