Skip to content

Commit

Permalink
Merge pull request #511 from oat-sa/fix/ADF-1669/link-asset-to-copied…
Browse files Browse the repository at this point in the history
…-source-file

fix: Copy Service now store correct link to an asset file source
  • Loading branch information
bartlomiejmarszal authored Jun 19, 2024
2 parents 693a789 + 1ca1730 commit fa10732
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
9 changes: 0 additions & 9 deletions model/classes/Copier/AssetMetadataCopier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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(
Expand Down
12 changes: 9 additions & 3 deletions model/sharedStimulus/service/CopyService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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(),
Expand Down
3 changes: 1 addition & 2 deletions test/unit/model/classes/Copier/AssetMetadataCopierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/unit/model/sharedStimulus/service/CopyServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit fa10732

Please sign in to comment.