76 public function __construct(
int $a_id = 0,
bool $a_call_by_reference =
true)
79 $this->manager =
$DIC->resourceStorage()->manage();
83 $this->
upload = $DIC->upload();
93 $this->file_info = $is_ref_id ? $repository->getByRefId(
$id) : $repository->getByObjectId(
$id);
99 return $this->file_info->getHeaderTitle();
104 if ($this->resource_id && (
$id = $this->manager->find(
107 $resource = $this->manager->getResource(
$id);
109 $this->max_version = $resource->getMaxRevision(
false);
110 $this->version = $resource->getCurrentRevision()->getVersionNumber();
118 $this->manager->getCurrentRevision($this->manager->find($this->getResourceId()))
128 $this->extractSuffixFromFilename($r->
getInformation()->getTitle())
137 $suffix = $this->file_info->getSuffix();
139 if (empty($suffix) || $suffix !== $filename_suffix) {
140 $suffix = $filename_suffix;
154 ?? pathinfo($stream->getMetadata(
'uri'))[
'extension']
157 if ($this->
getResourceId() && $i = $this->manager->find($this->getResourceId())) {
158 $revision = $this->manager->appendNewRevisionFromStream($i, $stream, $this->stakeholder,
$title);
160 $i = $this->manager->stream($stream, $this->stakeholder,
$title);
161 $revision = $this->manager->getCurrentRevision($i);
168 return $revision->getVersionNumber();
177 if ($this->
getResourceId() && $i = $this->manager->find($this->getResourceId())) {
178 $revision = $this->manager->appendNewRevision($i, $result, $this->stakeholder,
$title);
180 $i = $this->manager->upload($result, $this->stakeholder,
$title);
181 $revision = $this->manager->getCurrentRevision($i);
191 return $revision->getVersionNumber();
199 if ($this->
getResourceId() && $i = $this->manager->find($this->getResourceId())) {
200 $revision = $this->manager->replaceWithStream($i, $stream, $this->stakeholder,
$title);
202 throw new LogicException(
'only files with existing resource and revision can be replaced');
207 return $revision->getVersionNumber();
216 if ($this->
getResourceId() && $i = $this->manager->find($this->getResourceId())) {
217 $revision = $this->manager->replaceWithUpload($i, $result, $this->stakeholder,
$title);
219 throw new LogicException(
'only files with existing resource and revision can be replaced');
227 return $revision->getVersionNumber();
233 public function getFile(?
int $a_hist_entry_id =
null): string
236 return $this->implementation->getFile($a_hist_entry_id);
241 return $this->implementation->getDirectory($a_version);
246 return $this->implementation->getDownloadFilename();
256 $this->important_info = empty($a_important_info) ? null : $a_important_info;
261 return $this->implementation->getVersion($inclduing_drafts);
266 $this->version = $a_version;
271 return $this->implementation->getFileName();
276 $this->filename = $a_name;
281 $this->rating = $a_value;
292 return $this->resource_id ??
'-';
297 return $this->implementation->getStorageID();
310 $this->mode = $a_mode;
315 return $this->implementation->getFileSize();
323 throw new LogicException(
'cannot change filesize');
328 return $this->implementation->getFileType();
336 throw new LogicException(
'cannot change filetype');
354 throw new LogicException(
'cannot change max-version');
408 throw new LogicException(
"Amount cannot be a negative number.");
411 $this->amount_of_downloads = $amount;
426 throw new LogicException(
'cannot change action');
431 $new_title = $this->
ensureSuffix($new_title, $this->file_info->getSuffix());
433 $this->implementation->handleChangedObjectTitle($new_title);
436 protected function doCreate(
bool $clone_mode =
false): void
446 $q =
"SELECT * FROM file_data WHERE file_id = %s";
448 $row = $r->fetchObject();
450 $this->filename = $this->secure($row->file_name ??
'');
451 $this->filetype = $row->file_type ??
'';
452 $this->filesize = $row->file_size ?? 0;
453 $this->version = $row->version ?? 1;
454 $this->max_version = $row->max_version ?? 1;
456 $this->important_info = $row->important_info ??
"";
457 $this->rating = (bool) ($row->rating ??
false);
458 $this->page_count = (
int) ($row->page_count ?? 0);
459 $this->resource_id = $row->rid ??
null;
460 $this->on_click_mode = (
int) ($row->on_click_mode ?? self::CLICK_MODE_DOWNLOAD);
461 $this->amount_of_downloads = (
int) ($row->downloads ?? 0);
469 $identification = $this->manager->find($this->resource_id);
470 if ($identification ===
null) {
471 throw new RuntimeException(
'Cannot clone file since no corresponding resource identification was found');
476 $new_obj->updateFileData();
479 $cloned_title = $new_obj->
getTitle();
480 $new_resource_identification = $this->manager->clone($identification);
481 $new_current_revision = $this->manager->getCurrentRevision($new_resource_identification);
482 $new_obj->setResourceId($new_resource_identification->serialize());
483 $new_obj->initImplementation();
484 $new_obj->updateObjectFromRevision($new_current_revision);
496 $obj_settings->cloneSettings($new_obj->
getId());
497 unset($obj_settings);
503 $this->
database->update(
'file_data', $a_columns, [
517 $suffix = $this->file_info->getSuffix();
518 if (empty($suffix)) {
524 if ($this->
getMode() !== self::MODE_FILELIST) {
536 $usages = $this->getUsages();
537 return $usages === [];
543 $this->
database->manipulateF(
"DELETE FROM file_data WHERE file_id = %s", [
'integer'], [$this->
getId()]);
549 if ($this->
getMode() !== self::MODE_FILELIST) {
555 if ($identification && $identification !==
'-') {
556 $resource = $this->manager->find($identification);
557 if ($resource !==
null) {
558 $this->manager->remove($resource, $this->stakeholder);
569 'file_id' => [
'integer', $this->
getId()],
571 'f_mode' => [
'text', $this->
getMode()],
574 'rating' => [
'integer', $this->
hasRating()],
575 'rid' => [
'text', $this->resource_id ??
''],
598 if (!$this->
upload->hasBeenProcessed()) {
599 if (defined(
'PATH_TO_GHOSTSCRIPT') && PATH_TO_GHOSTSCRIPT !==
"") {
638 $this->implementation->clearDataDirectory();
647 $this->implementation->deleteVersions($a_hist_entry_ids);
649 if ($this->
getResourceId() && $rid = $this->manager->find($this->getResourceId())) {
650 $latest_revision = $this->manager->getCurrentRevision($rid);
655 public function sendFile(?
int $a_hist_entry_id =
null,
bool $inline =
true): void
661 $this->implementation->sendFile($a_hist_entry_id,
$info->shouldDeliverInline());
667 public function export(
string $a_target_dir): void
678 return $this->implementation->getVersions($version_ids);
687 if ($this->
getResourceId() && $i = $this->manager->find($this->getResourceId())) {
688 $this->manager->rollbackRevision($i, $version_id);
689 $latest_revision = $this->manager->getCurrentRevision($i);
692 throw new LogicException(
'only files with existing resource and revision can be replaced');
706 return $this->implementation->getFileExtension();
711 return $this->secure(preg_replace(
'/\.[^.]*$/',
'', $a_title));
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Class ResourceIdentification.
Class FileNamePolicyException.
Class ilCountPDFPagesPreProcessors.
static _removeEntriesForObject(int $a_obj_id)
remove all history entries for an object
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
static _isFileHidden(string $a_file_name)
Returns true, if a file with the specified name, is usually hidden from the user.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjFileImplementationStorage.
Class ilObjFileStakeholder.
updateObjectFromCurrentRevision()
handleChangedObjectTitle(string $new_title)
__construct(int $a_id=0, bool $a_call_by_reference=true)
ilObjFile constructor.
setAmountOfDownloads(int $amount)
clearDataDirectory()
@ineritdoc
appendStream(FileStream $stream, string $title)
ilObjFileImplementationInterface $implementation
sendFile(?int $a_hist_entry_id=null, bool $inline=true)
setCopyrightID(?string $copyright_id)
setAction(string $a_action)
appendSuffixToTitle(string $title, string $filename)
setMaxVersion(int $a_max_version)
replaceWithUpload(UploadResult $result, string $title)
checkFileExtension(string $new_filename, string $new_title)
getVersion(bool $inclduing_drafts=false)
setFileType(string $a_type)
stripTitleOfFileExtension(string $a_title)
replaceWithStream(FileStream $stream, string $title)
getVersions($version_ids=null)
getPresentationTitle()
get presentation title Normally same as title Overwritten for sessions
deleteVersions($a_hist_entry_ids=null)
@ineritdoc
setImportantInfo(string $a_important_info)
replaceFile($a_upload_file, $a_filename)
rollback(int $version_id)
Makes the specified version the current one.
setResourceId(?string $resource_id)
appendUpload(UploadResult $result, string $title)
setVersion(int $a_version)
updateObjectFromRevision(Revision $r)
getDirectory($a_version=0)
setPageCount(int $page_count)
const CLICK_MODE_DOWNLOAD
export(string $a_target_dir)
const CLICK_MODE_INFOPAGE
initFileInfo(int $id, bool $is_ref_id)
getFile(?int $a_hist_entry_id=null)
getUploadFile($a_upload_file, string $title, bool $a_prevent_preview=false)
@description This Method is used to append a fileupload by it's POST-name to the current ilObjFile
setOnclickMode(int $on_click_mode)
setFileName(string $a_name)
getFileExtension()
Returns the extension of the file name converted to lower-case.
doCreate(bool $clone_mode=false)
ilObjFileStakeholder $stakeholder
doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
cloneMetaData(ilObject $target_obj)
Copy meta data.
static getInstance(int $obj_id)
The base interface for all filesystem streams.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
trait ilObjFileNews
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
notifyCreation(int $obj_id, ?string $additional_message=null)
notifyUpdate(int $obj_id, ?string $additional_message=null)
trait ilObjFileSecureString
Trait ilObjFileSecureString.
ensureSuffix(string $title, ?string $suffix=null)
extractSuffixFromFilename(string $filename)