97 public $mode = self::MODE_OBJECT;
116 public function __construct(
int $a_id = 0,
bool $a_call_by_reference =
true)
122 $this->manager = $DIC->resourceStorage()->manage();
124 $this->upload = $DIC->upload();
126 $this->max_version = 0;
134 if ($this->resource_id && (
$id = $this->manager->find($this->resource_id)) !== null) {
135 $resource = $this->manager->getResource(
$id);
141 $this->
setVersion($resource->getMaxRevision());
144 (
int) $this->
getId(),
149 $s->sanitizeIfNeeded();
162 if ($create_previews) {
163 $this->createPreview(
true);
170 $title_info =
new SplFileInfo($title);
171 $filename_info =
new SplFileInfo($filename);
173 $filename = str_replace(
'.' . $title_info->getExtension(),
'', $title_info->getPathname());
174 $extension = $filename_info->getExtension();
176 return $this->secure($filename .
'.' . $extension);
184 if ($this->
getResourceId() &&
$i = $this->manager->find($this->getResourceId())) {
185 $revision = $this->manager->appendNewRevisionFromStream(
$i, $stream, $this->stakeholder, $title);
187 $i = $this->manager->stream($stream, $this->stakeholder, $title);
188 $revision = $this->manager->getCurrentRevision(
$i);
194 return $revision->getVersionNumber();
204 $revision = $this->manager->appendNewRevision(
$i, $result, $this->stakeholder, $title);
206 $i = $this->manager->upload($result, $this->stakeholder, $title);
207 $revision = $this->manager->getCurrentRevision(
$i);
216 return $revision->getVersionNumber();
224 if ($this->
getResourceId() &&
$i = $this->manager->find($this->getResourceId())) {
225 $revision = $this->manager->replaceWithStream(
$i, $stream, $this->stakeholder, $title);
227 throw new LogicException(
'only files with existing resource and revision can be replaced');
231 return $revision->getVersionNumber();
241 $revision = $this->manager->replaceWithUpload(
$i, $result, $this->stakeholder, $title);
243 throw new LogicException(
'only files with existing resource and revision can be replaced');
250 return $revision->getVersionNumber();
258 public function getFile($a_hist_entry_id = null)
260 return $this->implementation->getFile($a_hist_entry_id);
265 return $this->implementation->getDirectory($a_version);
275 $this->version = $a_version;
291 $this->filename = $a_name;
299 $this->rating = (bool) $a_value;
314 return $this->resource_id ??
'-';
319 return $this->implementation->getStorageID();
335 $this->mode = $a_mode;
348 $this->filesize = $a_size;
364 $this->filetype = $a_type;
382 $this->max_version = $a_max_version;
416 $this->action = $a_action;
422 $this->implementation->handleChangedObjectTitle($new_title);
437 protected function doRead()
444 $q =
"SELECT * FROM file_data WHERE file_id = %s";
445 $r = $DIC->database()->queryF($q, [
'integer'], [$this->
getId()]);
446 $row = $r->fetchObject();
448 $this->
setFileName($this->secure($row->file_name ??
''));
451 $this->
setVersion($row->version ? $row->version : 1);
452 $this->
setMaxVersion($row->max_version ? $row->max_version : 1);
462 protected function doCloneObject($new_object, $a_target_id, $a_copy_id = 0)
470 $this->db->manipulateF(
471 "INSERT INTO file_data (file_id, file_name, file_type, file_size, version, rating, f_mode) VALUES (%s, %s, %s, %s, %s, %s, %s)",
482 (
int) $new_object->getId(),
493 if ($this->resource_id
495 $new_resource_identification = $this->manager->clone($identification);
496 $new_current_revision = $this->manager->getCurrentRevision($new_resource_identification);
497 $new_object->setResourceId($new_resource_identification->serialize());
498 $new_object->initImplementation();
499 $new_object->updateObjectFromRevision($new_current_revision,
false);
500 $new_object->setTitle($this->
getTitle());
501 $new_object->update();
506 $DIC->fileSystem()->storage(),
519 $obj_settings->cloneSettings($new_object->getId());
520 unset($obj_settings);
530 $DIC->database()->update(
'file_data', $a_columns, [
538 $meta_version_column = [
'meta_version' => [
'integer', (int) $this->
getVersion()]];
539 $DIC->database()->update(
'il_meta_lifecycle', $meta_version_column, [
554 if ($this->
getMode() != self::MODE_FILELIST) {
564 $usages = $this->getUsages();
565 if (count($usages) == 0) {
577 $DIC->database()->manipulateF(
"DELETE FROM file_data WHERE file_id = %s", [
'integer'], [$this->
getId()]);
583 if ($this->
getMode() != self::MODE_FILELIST) {
588 $this->deletePreview();
592 if ($identification && $identification !=
'-') {
593 $resource = $this->manager->find($identification);
594 if ($resource !== null) {
595 $this->manager->remove($resource, $this->stakeholder);
606 'file_id' => [
'integer', $this->
getId()],
609 'file_size' => [
'integer', (int) $this->
getFileSize()],
610 'version' => [
'integer', (int) $this->
getVersion()],
612 'f_mode' => [
'text', $this->
getMode()],
614 'rating' => [
'integer', $this->
hasRating()],
615 'rid' => [
'text', $this->resource_id ??
''],
621 $this->type =
"file";
642 if (
true !== $this->upload->hasBeenProcessed()) {
643 if (defined(
'PATH_TO_GHOSTSCRIPT') && PATH_TO_GHOSTSCRIPT !==
"") {
647 $this->upload->process();
660 $results = $this->upload->getResults();
683 $this->implementation->clearDataDirectory();
692 $this->implementation->deleteVersions($a_hist_entry_ids);
699 public function sendFile($a_hist_entry_id = null) : void
701 $this->implementation->sendFile($a_hist_entry_id);
717 public function export(
string $target_dir) : void
719 $this->implementation->export($target_dir);
745 $this->createPreview();
754 return $this->implementation->getVersions($version_ids);
763 if ($this->
getResourceId() &&
$i = $this->manager->find($this->getResourceId())) {
764 $this->manager->rollbackRevision(
$i, $version_id);
765 $latest_revision = $this->manager->getCurrentRevision(
$i);
768 throw new LogicException(
'only files with existing resource and revision can be replaced');
782 if ($titleExtension != $fileExtension && strlen($fileExtension) > 0) {
785 $suffix = $pi[
"extension"];
787 if (substr($new_title, strlen($new_title) - strlen($suffix) - 1) ==
"." . $suffix) {
788 $new_title = substr($new_title, 0, strlen($new_title) - strlen($suffix) - 1);
791 $new_title .=
'.' . $fileExtension;
803 return $this->implementation->getFileExtension();
setMigrateToNewObjectId(?int $migrate_to_new_object_id)
Class ilObjFileStakeholder.
Class ilFileObjectToStorageDirectory.
static _isFileInline($a_file_name)
Returns true, if the specified file shall be displayed inline in the browser.
Class ilObjFileImplementationLegacy.
Class ilObjFileImplementationStorage.
Interface ilObjFileImplementationInterface.
replaceWithUpload(UploadResult $result, string $title)
raiseUploadError($raise=false)
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.
getFile($a_hist_entry_id=null)
appendSuffixToTitle(string $title, string $filename)
storeUnzipedFile($a_upload_file, $a_filename)
storeUnzipedFile Stores Files unzipped from uploaded archive in filesystem
rollback(int $version_id)
Makes the specified version the current one.
getDirectory($a_version=0)
updateObjectFromRevision(Revision $r, bool $create_previews=true)
doCreate($a_upload=false)
appendUpload(UploadResult $result, string $title)
checkFileExtension($new_filename, $new_title)
static rename($a_source, $a_target)
Rename a file.
replaceFile($a_upload_file, $a_filename)
doCloneObject($new_obj, $a_target_id, $a_copy_id=null)
appendStream(FileStream $stream, string $title)
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 ...
getId()
get object id public
__construct($a_id=0, $a_reference=true)
Constructor public.
Interface Identification.
sendFile($a_hist_entry_id=null)
export(string $target_dir)
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
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)
trait ilObjFileSecureString
Trait ilObjFileSecureString.
notifyUpdate(int $obj_id, string $additional_message=null)
replaceWithStream(FileStream $stream, string $title)
__construct(Container $dic, ilPlugin $plugin)
notifyCreation(int $obj_id, string $additional_message=null)
setPageCount($page_count)
static _removeEntriesForObject($a_obj_id)
remove all history entries for an object
Class ilCountPDFPagesPreProcessors.
static getLogger($a_component_id)
Get component logger.
setResourceId(?string $resource_id)
handleChangedObjectTitle(string $new_title)
Interface FileStream The base interface for all filesystem streams.
getVersions($version_ids=null)
static getValidFilename($a_filename)
Get valid filename.
trait ilObjFileNews
Trait ilObjFileNews.
cloneMetaData($target_obj)