Skip to content

Commit

Permalink
[FIX] 0042065: (partial) storing meta-data throws exception
Browse files Browse the repository at this point in the history
  • Loading branch information
chfsx committed Oct 21, 2024
1 parent f2c4763 commit 4500de0
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,16 @@
abstract class ilObjFileAbstractProcessor implements ilObjFileProcessorInterface
{
protected ilFileServicesPolicy $policy;
protected ilFileServicesSettings $settings;
protected ilCountPDFPages $page_counter;
protected Services $storage;
protected ResourceStakeholder $stakeholder;
protected ilObjFileGUI $gui_object;
protected array $invalid_file_names = [];

public function __construct(
ResourceStakeholder $stakeholder,
ilObjFileGUI $gui_object,
Services $storage,
ilFileServicesSettings $settings
protected ResourceStakeholder $stakeholder,
protected ilObjFileGUI $gui_object,
protected Services $storage,
protected ilFileServicesSettings $settings
) {
$this->storage = $storage;
$this->stakeholder = $stakeholder;
$this->gui_object = $gui_object;
$this->page_counter = new ilCountPDFPages();
$this->settings = $settings;
$this->policy = new ilFileServicesPolicy($this->settings);
}

Expand All @@ -58,7 +50,7 @@ protected function createFileObj(
int $parent_id,
string $title = null,
string $description = null,
int $copyright_id = null,
string $copyright_id = null,
bool $create_reference = false
): ilObjFile {
$revision = $this->storage->manage()->getCurrentRevision($rid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function process(
ResourceIdentification $rid,
string $title = null,
string $description = null,
int $copyright_id = null
string $copyright_id = null
): void {
$file_obj = $this->createFileObj($rid, $this->gui_object->getParentId(), $title, $description, $copyright_id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function process(
ResourceIdentification $rid,
string $title = null,
string $description = null,
int $copyright_id = null
string $copyright_id = null
): void {
$this->openZip($rid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function process(
ResourceIdentification $rid,
string $title = null,
string $description = null,
int $copyright_id = null
string $copyright_id = null
): void {
$this->openZip($rid);
$base_node = $this->gui_object->getParentId();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

use ILIAS\ResourceStorage\Identification\ResourceIdentification;

/**
Expand All @@ -16,6 +32,6 @@ public function process(
ResourceIdentification $rid,
string $title = null,
string $description = null,
int $copyright_id = null
string $copyright_id = null
): void;
}
31 changes: 12 additions & 19 deletions components/ILIAS/File/classes/class.ilObjFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*
*********************************************************************/

use ILIAS\ResourceStorage\Identification\ResourceIdentification;
use ILIAS\Filesystem\Stream\FileStream;
use ILIAS\FileUpload\DTO\UploadResult;
use ILIAS\FileUpload\FileUpload;
Expand Down Expand Up @@ -53,9 +54,9 @@ class ilObjFile extends ilObject2 implements ilObjFileImplementationInterface
protected string $filename = '';
protected string $filetype = '';
protected int $filesize;
protected int $version = 1;
protected int $max_version = 1;
protected ?int $copyright_id = null;
protected int $version = 0;
protected int $max_version = 0;
protected ?string $copyright_id = null;
protected string $action = '';
protected ?string $resource_id = null;
public string $mode = self::MODE_OBJECT;
Expand All @@ -79,8 +80,6 @@ public function __construct(int $a_id = 0, bool $a_call_by_reference = true)
$this->implementation = new ilObjFileImplementationEmpty();
$this->stakeholder = new ilObjFileStakeholder($DIC->user()->getId());
$this->upload = $DIC->upload();
$this->version = 0;
$this->max_version = 0;
$this->log = ilLoggerFactory::getLogger(self::OBJECT_TYPE);

parent::__construct($a_id, $a_call_by_reference);
Expand All @@ -90,11 +89,7 @@ public function __construct(int $a_id = 0, bool $a_call_by_reference = true)
protected function initFileInfo(int $id, bool $is_ref_id): void
{
$repository = new ilObjFileInfoRepository(true);
if ($is_ref_id) {
$this->file_info = $repository->getByRefId($id);
} else {
$this->file_info = ($repository)->getByObjectId($id);
}
$this->file_info = $is_ref_id ? $repository->getByRefId($id) : ($repository)->getByObjectId($id);
}

public function getPresentationTitle(): string
Expand All @@ -106,7 +101,7 @@ protected function initImplementation(): void
{
if ($this->resource_id && ($id = $this->manager->find(
$this->resource_id
)) instanceof \ILIAS\ResourceStorage\Identification\ResourceIdentification) {
)) instanceof ResourceIdentification) {
$resource = $this->manager->getResource($id);
$this->implementation = new ilObjFileImplementationStorage($resource);
$this->max_version = $resource->getMaxRevision(false);
Expand Down Expand Up @@ -143,9 +138,7 @@ public function appendSuffixToTitle(string $title, string $filename): string
$suffix = $filename_suffix;
}

$title = $this->ensureSuffix($title, $suffix);

return $title;
return $this->ensureSuffix($title, $suffix);
}

/**
Expand Down Expand Up @@ -353,12 +346,12 @@ public function setMaxVersion(int $a_max_version): void
throw new LogicException('cannot change max-version');
}

public function getCopyrightID(): ?int
public function getCopyrightID(): ?string
{
return $this->copyright_id;
}

public function setCopyrightID(?int $copyright_id): void
public function setCopyrightID(?string $copyright_id): void
{
$this->copyright_id = $copyright_id;
}
Expand Down Expand Up @@ -524,7 +517,7 @@ protected function beforeDelete(): bool
{
// check, if file is used somewhere
$usages = $this->getUsages();
return count($usages) === 0;
return $usages === [];
}

protected function doDelete(): void
Expand All @@ -536,13 +529,13 @@ protected function doDelete(): void
ilHistory::_removeEntriesForObject($this->getId());

// delete meta data
if ($this->getMode() != self::MODE_FILELIST) {
if ($this->getMode() !== self::MODE_FILELIST) {
$this->deleteMetaData();
}

// delete resource
$identification = $this->getResourceId();
if ($identification && $identification != '-') {
if ($identification && $identification !== '-') {
$resource = $this->manager->find($identification);
if ($resource !== null) {
$this->manager->remove($resource, $this->stakeholder);
Expand Down
2 changes: 1 addition & 1 deletion components/ILIAS/File/classes/trait.ilObjFileMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected function doCreateMetaData(): void
// add file size and format to LOM
$DIC->learningObjectMetadata()->manipulate($this->getId(), 0, $this->getType())
->prepareCreateOrUpdate($this->getPathToSize(), (string) $this->getFileSize())
->prepareCreateOrUpdate($this->getPathToFirstFormat(), $this->getFileType())
// ->prepareCreateOrUpdate($this->getPathToFirstFormat(), $this->getFileType()) // TIDI thwors exception
->prepareCreateOrUpdate($this->getPathToVersion(), (string) $this->getVersion())
->execute();
}
Expand Down

0 comments on commit 4500de0

Please sign in to comment.