Skip to content

Commit

Permalink
43079: Creating a MediaObject Through Creates Legacy Files
Browse files Browse the repository at this point in the history
  • Loading branch information
alex40724 committed Jan 18, 2025
1 parent 67d7a58 commit 3148266
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public function addFileFromUpload(
$this->repo->addFileFromUpload($mob_id, $result, $path);
}

public function addFileFromLocal(int $mob_id, string $tmp_name, string $path): void
{
$this->repo->addFileFromLocal($mob_id, $tmp_name, $path);
}

public function removeLocation(
int $mob_id,
string $location
Expand Down
40 changes: 25 additions & 15 deletions components/ILIAS/MediaObjects/MediaObject/MediaObjectRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function create(
int $id,
string $title,
\ilMobStakeholder $stakeholder
): void {
) : void {
$rid = $this->irss->createContainer(
$stakeholder
);
Expand All @@ -50,7 +50,7 @@ public function create(
]);
}

public function getById(int $id): ?array
public function getById(int $id) : ?array
{
$set = $this->db->queryF(
'SELECT * FROM mob_data WHERE id = %s',
Expand All @@ -69,7 +69,7 @@ public function getById(int $id): ?array
return null;
}

public function delete(int $id): void
public function delete(int $id) : void
{
$this->db->manipulateF(
'DELETE FROM mob_data WHERE id = %s',
Expand All @@ -78,7 +78,7 @@ public function delete(int $id): void
);
}

protected function getRidForMobId(int $mob_id): string
protected function getRidForMobId(int $mob_id) : string
{
$set = $this->db->queryF(
"SELECT * FROM mob_data " .
Expand All @@ -92,7 +92,7 @@ protected function getRidForMobId(int $mob_id): string
return "";
}

public function addFileFromLegacyUpload(int $mob_id, string $tmp_name): void
public function addFileFromLegacyUpload(int $mob_id, string $tmp_name) : void
{
if ($rid = $this->getRidForMobId($mob_id)) {
$this->irss->importFileFromLegacyUploadToContainer(
Expand All @@ -107,8 +107,7 @@ public function addFileFromUpload(
int $mob_id,
UploadResult $result,
string $path = "/"
): void
{
) : void {
if ($rid = $this->getRidForMobId($mob_id)) {
$this->irss->importFileFromUploadResultToContainer(
$rid,
Expand All @@ -118,15 +117,26 @@ public function addFileFromUpload(
}
}

public function getLocalSrc(int $mob_id, string $location): string
public function addFileFromLocal(int $mob_id, string $tmp_name, string $path) : void
{
if ($rid = $this->getRidForMobId($mob_id)) {
$this->irss->addLocalFileToContainer(
$rid,
$tmp_name,
$path
);
}
}

public function getLocalSrc(int $mob_id, string $location) : string
{
return $this->irss->getContainerUri($this->getRidForMobId($mob_id), $location);
}

public function getLocationStream(
int $mob_id,
string $location
): ZIPStream {
) : ZIPStream {
return $this->irss->getStreamOfContainerEntry(
$this->getRidForMobId($mob_id),
$location
Expand All @@ -135,15 +145,15 @@ public function getLocationStream(

public function getContainerPath(
int $mob_id
): string {
) : string {
return $this->irss->getResourcePath($this->getRidForMobId($mob_id));
}

public function addStream(
int $mob_id,
string $location,
FileStream $stream
): void {
) : void {
$this->irss->addStreamToContainer(
$this->getRidForMobId($mob_id),
$stream,
Expand All @@ -153,27 +163,27 @@ public function addStream(

public function getContainerResource(
int $mob_id
): ?StorableResource {
) : ?StorableResource {
return $this->irss->getResource($this->getRidForMobId($mob_id));
}

public function getContainerResourceId(
int $mob_id
): ?ResourceIdentification {
) : ?ResourceIdentification {
return $this->irss->getResourceIdForIdString($this->getRidForMobId($mob_id));
}

public function removeLocation(
int $mob_id,
string $location
): void {
) : void {
$this->irss->removePathFromContainer($this->getRidForMobId($mob_id), $location);
}

public function getFilesOfPath(
int $mob_id,
string $dir_path
): array {
) : array {
return $this->irss->getContainerEntriesOfPath(
$this->getRidForMobId($mob_id),
$dir_path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,9 @@ public function getDataDirectory(): string
}

/**
* Create new media object and update page in db and return new media object
* @deprecated
* - for upload cases use $media_object->addMediaItemFrom(Legacy)Upload
* - imports must use the dependency mechanism
*/
public static function _saveTempFileAsMediaObject(
string $name,
Expand Down Expand Up @@ -1371,6 +1373,12 @@ public static function _saveTempFileAsMediaObject(
true
);
} else {
$media_item = $media_object->addMediaItemFromLocalFile(
"Standard",
$tmp_name,
$name
);
/*
$media_item = new ilMediaItem();
$media_object->addMediaItem($media_item);
$media_item->setPurpose("Standard");
Expand All @@ -1381,7 +1389,7 @@ public static function _saveTempFileAsMediaObject(
$media_item->setFormat($format);
$location = $name;
$media_item->setLocation($location);
$media_item->setLocationType("LocalFile");
$media_item->setLocationType("LocalFile");*/
}

// set real meta and object data
Expand Down Expand Up @@ -1474,6 +1482,30 @@ public function addMediaItemFromUpload(
return $media_item;
}

public function addMediaItemFromLocalFile(
string $purpose,
string $tmp_name,
string $name
): \ilMediaItem {
$media_item = new ilMediaItem();
$this->addMediaItem($media_item);
$media_item->setPurpose($purpose);
$location = $name;
$this->manager->addFileFromLocal($this->getId(), $tmp_name, $name);

// get mime type
$format = self::getMimeType($location, true);

// set real meta and object data
$media_item->setFormat($format);
$media_item->setLocation($location);
$media_item->setLocationType("LocalFile");
if ($purpose === "Standard") {
$this->generatePreviewPic(320, 240);
}
return $media_item;
}

public function replaceMediaItemFromUpload(
string $purpose,
UploadResult $result,
Expand Down
56 changes: 0 additions & 56 deletions components/ILIAS/Survey/Export/class.ilSurveyImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,62 +107,6 @@ public function importXmlRepresentation(
$import->setSurveyObject($newObj);
$import->startParsing();


// this is "written" by Services/Survey/classes/class.ilSurveyImportParser
$mobs = $this->spl_import_manager->getMobs();
if (count($mobs) > 0) {
foreach ($mobs as $mob) {
$this->svy_log->debug("import mob xhtml, type: " . $mob["type"] . ", id: " . $mob["mob"]);

if (!isset($mob["type"])) {
$mob["type"] = "svy:html";
}

$importfile = dirname($xml_file) . "/" . $mob["uri"];
$this->svy_log->debug("import file: " . $importfile);

if (file_exists($importfile)) {
$media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);

// survey mob
if ($mob["type"] === "svy:html") {
ilObjMediaObject::_saveUsage($media_object->getId(), "svy:html", $newObj->getId());
$this->svy_log->debug("old introduction: " . $newObj->getIntroduction());
$newObj->setIntroduction(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $newObj->getIntroduction()));
$newObj->setOutro(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $newObj->getOutro()));

$this->svy_log->debug("new introduction: " . $newObj->getIntroduction());
} elseif ($import->questions[$mob["id"]]) {
$new_qid = $import->questions[$mob["id"]];
ilObjMediaObject::_saveUsage($media_object->getId(), $mob["type"], $new_qid);
$new_question = SurveyQuestion::_instanciateQuestion($new_qid);
$qtext = $new_question->getQuestiontext();

$this->svy_log->debug("old question text: " . $qtext);

$qtext = ilRTE::_replaceMediaObjectImageSrc($qtext, 0);
$qtext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $qtext);
$qtext = ilRTE::_replaceMediaObjectImageSrc($qtext, 1);
$new_question->setQuestiontext($qtext);
$new_question->saveToDb();

$this->svy_log->debug("new question text: " . $qtext);

// also fix existing original in pool
if ($new_question->getOriginalId()) {
$pool_question = SurveyQuestion::_instanciateQuestion($new_question->getOriginalId());
$pool_question->setQuestiontext($qtext);
$pool_question->saveToDb();
}
}
} else {
$this->svy_log->error("Error: Could not open XHTML mob file for test introduction during test import. File $importfile does not exist!");
}
}
$newObj->setIntroduction(ilRTE::_replaceMediaObjectImageSrc($newObj->getIntroduction(), 1));
$newObj->setOutro(ilRTE::_replaceMediaObjectImageSrc($newObj->getOutro(), 1));
$newObj->saveToDb();
}
$a_mapping->addMapping("components/ILIAS/Survey", "svy", (int) $a_id, $newObj->getId());
$a_mapping->addMapping(
"components/ILIAS/MetaData",
Expand Down

0 comments on commit 3148266

Please sign in to comment.