From 638a9a8cd24aa15736aeff11a93c210059bcc1dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Marsza=C5=82?= Date: Fri, 14 Jun 2024 15:00:07 +0200 Subject: [PATCH 1/3] fix: Copy Service now store correct link to an asset file source --- model/classes/Copier/AssetMetadataCopier.php | 4 ---- model/sharedStimulus/service/CopyService.php | 12 +++++++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/model/classes/Copier/AssetMetadataCopier.php b/model/classes/Copier/AssetMetadataCopier.php index 2398f2382..201879430 100644 --- a/model/classes/Copier/AssetMetadataCopier.php +++ b/model/classes/Copier/AssetMetadataCopier.php @@ -61,10 +61,6 @@ public function copy( $this->copyProperty($instance, $destinationInstance, self::PROPERTY_LANGUAGE); $this->copyProperty($instance, $destinationInstance, self::PROPERTY_MD5); $this->copyProperty($instance, $destinationInstance, self::PROPERTY_MIME); - - // References the original file instead of creating a copy - // - $this->copyProperty($instance, $destinationInstance, self::PROPERTY_LINK); } private function copyProperty( diff --git a/model/sharedStimulus/service/CopyService.php b/model/sharedStimulus/service/CopyService.php index 20ee8d1d5..3f42d1eda 100644 --- a/model/sharedStimulus/service/CopyService.php +++ b/model/sharedStimulus/service/CopyService.php @@ -32,6 +32,7 @@ use oat\taoMediaManager\model\sharedStimulus\dto\SharedStimulusInstanceData; use oat\taoMediaManager\model\sharedStimulus\SharedStimulus; use InvalidArgumentException; +use oat\taoMediaManager\model\TaoMediaOntology; class CopyService { @@ -86,15 +87,20 @@ public function copy(CopyCommand $command): SharedStimulus ); $srcXmlPath = $this->fileSourceUnserializer->unserialize($source->link); - - $this->sharedStimulusStoreService->storeStream( + $stimulusFilename = basename($source->link); + $dirname = $this->sharedStimulusStoreService->storeStream( $this->fileManagement->getFileStream($srcXmlPath)->detach(), - basename($source->link), + $stimulusFilename, $this->copyCSSFilesFrom($source) ); $target = $this->ontology->getResource($command->getDestinationUri()); + $target->setPropertyValue( + $target->getProperty(TaoMediaOntology::PROPERTY_LINK), + $dirname . DIRECTORY_SEPARATOR . $stimulusFilename + ); + return new SharedStimulus( $source->resourceUri, $target->getUri(), From dbcd502864b89bc979f4be019f731d3d2a34a733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Marsza=C5=82?= Date: Fri, 14 Jun 2024 15:12:16 +0200 Subject: [PATCH 2/3] fix: Remove unused const, fix unit test --- model/classes/Copier/AssetMetadataCopier.php | 5 ----- test/unit/model/classes/Copier/AssetMetadataCopierTest.php | 3 +-- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/model/classes/Copier/AssetMetadataCopier.php b/model/classes/Copier/AssetMetadataCopier.php index 201879430..e26e76314 100644 --- a/model/classes/Copier/AssetMetadataCopier.php +++ b/model/classes/Copier/AssetMetadataCopier.php @@ -27,11 +27,6 @@ class AssetMetadataCopier implements InstanceMetadataCopierInterface { - /** - * Base filename for the asset (i.e. 123456789abcdef123456.mp4) - */ - private const PROPERTY_LINK = TaoMediaOntology::PROPERTY_LINK; - /** * MD5 hash of the file contents */ diff --git a/test/unit/model/classes/Copier/AssetMetadataCopierTest.php b/test/unit/model/classes/Copier/AssetMetadataCopierTest.php index 68dbf183c..2a2694b52 100644 --- a/test/unit/model/classes/Copier/AssetMetadataCopierTest.php +++ b/test/unit/model/classes/Copier/AssetMetadataCopierTest.php @@ -133,12 +133,11 @@ function (core_kernel_classes_Property $p, array $opts) { ); $this->target - ->expects($this->exactly(3)) + ->expects($this->exactly(2)) ->method('setPropertyValue') ->withConsecutive( [$this->propertyMD5, 'c38cd6d9c873bf072d9753d730f87ce'], [$this->propertyMime, 'video/mp4'], - [$this->propertyLink, '123456789abcdef123456.mp4'] ); $this->target From 1ca17302e9e4ecc56180f8570dc3f3eb8137f707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Marsza=C5=82?= Date: Fri, 14 Jun 2024 15:32:01 +0200 Subject: [PATCH 3/3] fix: CopyServiceTest --- test/unit/model/sharedStimulus/service/CopyServiceTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/unit/model/sharedStimulus/service/CopyServiceTest.php b/test/unit/model/sharedStimulus/service/CopyServiceTest.php index 168f8701d..6493e1c90 100644 --- a/test/unit/model/sharedStimulus/service/CopyServiceTest.php +++ b/test/unit/model/sharedStimulus/service/CopyServiceTest.php @@ -175,6 +175,12 @@ public function testSuccessfulCopy(): void ->method('getUri') ->willReturn('http://example.com/resource2'); + $propertyMock = $this->createMock(core_kernel_classes_Property::class); + $targetResource + ->expects($this->once()) + ->method('getProperty') + ->willReturn($propertyMock); + $this->ontology ->expects($this->at(0)) ->method('getResource')