Skip to content

Commit

Permalink
Merge pull request #2621 from oat-sa/backport/AUT-3784/import-export-…
Browse files Browse the repository at this point in the history
…metadata

Backport Import Export Metadata fix
  • Loading branch information
bartlomiejmarszal authored Nov 14, 2024
2 parents 6d16146 + 101b7ae commit 5561be1
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 8 deletions.
45 changes: 45 additions & 0 deletions install/scripts/RemoveLegacyGenericLomExtractor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2024 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace oat\taoQtiItem\install\scripts;

use oat\oatbox\extension\InstallAction;
use oat\taoQtiItem\model\qti\metadata\MetadataService;

class RemoveLegacyGenericLomExtractor extends InstallAction
{
public function __invoke($params)
{
$metadataService = $this->getServiceManager()->getContainer()->get(MetadataService::SERVICE_ID);
$exportOption = $metadataService->getOption(MetadataService::EXPORTER_KEY);
$extractors = $exportOption->getOption('extractors');

$extractors = array_filter($extractors, function ($extractor) {
//phpcs:ignore
return $extractor !== 'oat\taoQtiItem\model\qti\metadata\ontology\GenericLomOntologyClassificationExtractor';
});

$exportOption->setOption('extractors', [... $extractors]);
$metadataService->setOption(MetadataService::EXPORTER_KEY, $exportOption);
$this->getServiceManager()->register(MetadataService::SERVICE_ID, $metadataService);
}
}
4 changes: 3 additions & 1 deletion manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use oat\taoQtiItem\controller\QtiPreview;
use oat\taoQtiItem\install\scripts\addValidationSettings;
use oat\taoQtiItem\install\scripts\ExtendConfigurationRegistry;
use oat\taoQtiItem\install\scripts\RemoveLegacyGenericLomExtractor;
use oat\taoQtiItem\install\scripts\SetDragAndDropConfig;
use oat\taoQtiItem\install\scripts\setXMLParserConfig;
use oat\taoQtiItem\model\qti\CustomInteractionAsset\ServiceProvider\{
Expand Down Expand Up @@ -93,7 +94,8 @@
RegisterNpmPaths::class,
ExtendConfigurationRegistry::class,
SetupQtiMetadataImportExportService::class,
AddLabelInjectorForExport::class
AddLabelInjectorForExport::class,
RemoveLegacyGenericLomExtractor::class,
]
],
'local' => [
Expand Down
32 changes: 32 additions & 0 deletions migrations/Version202411111526061101_taoQtiItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace oat\taoQtiItem\migrations;

use Doctrine\DBAL\Schema\Schema;
use oat\tao\scripts\tools\migrations\AbstractMigration;
use oat\taoQtiItem\install\scripts\RemoveLegacyGenericLomExtractor;

/**
* Auto-generated Migration: Please modify to your needs!
*
* phpcs:disable Squiz.Classes.ValidClassName
*/
final class Version202411111526061101_taoQtiItem extends AbstractMigration
{
public function getDescription(): string
{
return 'This will remove the legacy GenericLomExtractor';
}

public function up(Schema $schema): void
{
$this->runAction(new RemoveLegacyGenericLomExtractor());
}

public function down(Schema $schema): void
{
$this->throwIrreversibleMigrationException();
}
}
7 changes: 0 additions & 7 deletions model/qti/ImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,6 @@ public function importQtiItem(
//load the information about resources in the manifest
try {
$resourceIdentifier = $qtiItemResource->getIdentifier();

$this->getMetadataImporter()->setMetadataValues($metadataValues);
$guardian = false;

if ($enableMetadataGuardians === true) {
Expand Down Expand Up @@ -544,11 +542,8 @@ public function importQtiItem(
}

$targetClass = $this->getMetadataImporter()->classLookUp($resourceIdentifier, $createdClasses);

$tmpQtiFile = $tmpFolder . helpers_File::urlToPath($qtiItemResource->getFile());

common_Logger::i('file :: ' . $qtiItemResource->getFile());

$qtiModel = $this->createQtiItemModel($tmpQtiFile);

if (
Expand Down Expand Up @@ -635,8 +630,6 @@ public function importQtiItem(
$qtiModel = $this->createQtiItemModel($itemAssetManager->getItemContent(), false);
$qtiService->saveDataItemToRdfItem($qtiModel, $rdfItem);

$this->getMetadataImporter()->inject($resourceIdentifier, $rdfItem);

if ($importMetadataEnabled && isset($metadataValues[$resourceIdentifier])) {
$this->getMappedMetadataInjector()->inject(
$metaMedataValues,
Expand Down

0 comments on commit 5561be1

Please sign in to comment.