diff --git a/model/classes/Copier/AssetMetadataCopier.php b/model/classes/Copier/AssetMetadataCopier.php index 2398f2382..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 */ @@ -61,10 +56,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(), 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 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')