-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Wip copy between licences * Search by url
- Loading branch information
1 parent
e55ecf4
commit 3db2b48
Showing
42 changed files
with
1,220 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AnzuSystems\CoreDamBundle\Domain\Asset; | ||
|
||
use AnzuSystems\CoreDamBundle\Domain\AbstractManager; | ||
use AnzuSystems\CoreDamBundle\Domain\AssetFile\AssetFileFactory; | ||
use AnzuSystems\CoreDamBundle\Domain\AssetMetadata\AssetMetadataManager; | ||
use AnzuSystems\CoreDamBundle\Domain\AssetSlot\AssetSlotManager; | ||
use AnzuSystems\CoreDamBundle\Entity\Asset; | ||
use AnzuSystems\CoreDamBundle\Entity\AssetLicence; | ||
use AnzuSystems\CoreDamBundle\Entity\AssetSlot; | ||
use AnzuSystems\CoreDamBundle\Model\Enum\AssetStatus; | ||
|
||
class AssetCopyBuilder extends AbstractManager | ||
{ | ||
public function __construct( | ||
private readonly AssetMetadataManager $assetMetadataManager, | ||
private readonly AssetFileFactory $assetFileFactory, | ||
private readonly AssetSlotManager $assetSlotManager, | ||
) { | ||
} | ||
|
||
public function buildDraftAssetCopy(Asset $asset, AssetLicence $assetLicence, bool $flush = true): Asset | ||
{ | ||
$assetCopy = $asset->__copy(); | ||
$assetCopy->getAttributes()->setStatus(AssetStatus::Draft); | ||
$this->trackCreation($assetCopy); | ||
$assetCopy->setLicence($assetLicence); | ||
$assetCopy->setExtSystem($assetLicence->getExtSystem()); | ||
$this->entityManager->persist($assetCopy); | ||
$this->assetMetadataManager->create($assetCopy->getMetadata(), false); | ||
$this->copySlots($asset, $assetCopy); | ||
|
||
foreach ($assetCopy->getSlots() as $assetSlot) { | ||
if ($assetSlot->getFlags()->isMain()) { | ||
$assetCopy->setMainFile($assetSlot->getAssetFile()); | ||
|
||
break; | ||
} | ||
} | ||
|
||
$this->flush($flush); | ||
|
||
return $assetCopy; | ||
} | ||
|
||
private function copySlots(Asset $asset, Asset $assetCopy): void | ||
{ | ||
foreach ($asset->getSlots() as $assetSlot) { | ||
$slotCopy = $this->copySlotToAsset($assetSlot, $assetCopy); | ||
$assetCopy->addSlot($slotCopy); | ||
$slotCopy->setAsset($assetCopy); | ||
} | ||
} | ||
|
||
private function copySlotToAsset(AssetSlot $assetSlot, Asset $assetCopy): AssetSlot | ||
{ | ||
$slotCopy = $assetSlot->__copy(); | ||
$blankAssetFile = $this->assetFileFactory->createForAsset($assetCopy); | ||
$blankAssetFile->setAsset($assetCopy); | ||
$blankAssetFile->addSlot($slotCopy); | ||
$this->assetSlotManager->create($slotCopy, false); | ||
|
||
return $slotCopy; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AnzuSystems\CoreDamBundle\Domain\AssetFile; | ||
|
||
use AnzuSystems\CoreDamBundle\Domain\AssetFile\FileProcessor\AssetFileStorageOperator; | ||
use AnzuSystems\CoreDamBundle\Domain\Image\ImageFileCopyBuilder; | ||
use AnzuSystems\CoreDamBundle\Entity\AssetFile; | ||
use AnzuSystems\CoreDamBundle\Entity\ImageFile; | ||
use AnzuSystems\CoreDamBundle\Exception\RuntimeException; | ||
use League\Flysystem\FilesystemException; | ||
|
||
final readonly class AssetFileCopyBuilder | ||
{ | ||
public function __construct( | ||
private AssetFileStorageOperator $assetFileStorageOperator, | ||
private ImageFileCopyBuilder $imageFileCopyBuilder, | ||
) { | ||
} | ||
|
||
/** | ||
* @throws FilesystemException | ||
*/ | ||
public function copy(AssetFile $assetFile, AssetFile $targetAssetFile): void | ||
{ | ||
$targetAssetFile->setAssetAttributes(clone $assetFile->getAssetAttributes()); | ||
$this->assetFileStorageOperator->copyToAssetFile($assetFile, $targetAssetFile); | ||
if ($assetFile instanceof ImageFile && $targetAssetFile instanceof ImageFile) { | ||
$this->imageFileCopyBuilder->copy($assetFile, $targetAssetFile); | ||
|
||
return; | ||
} | ||
|
||
throw new RuntimeException( | ||
sprintf( | ||
'Unsupported copy AssetFile combination. Copy from (%s) to (%s)', | ||
$assetFile::class, | ||
$targetAssetFile::class | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.