From ad0fbb577f128381382b0bc0b0c0b2f93302ca41 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Sat, 20 Apr 2024 21:34:49 +0300 Subject: [PATCH] ref --- application/Espo/Entities/Attachment.php | 7 +++++ application/Espo/Repositories/Attachment.php | 27 ++++++++++---------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/application/Espo/Entities/Attachment.php b/application/Espo/Entities/Attachment.php index 76f1d24217..db204b727a 100644 --- a/application/Espo/Entities/Attachment.php +++ b/application/Espo/Entities/Attachment.php @@ -140,6 +140,13 @@ class Attachment extends Entity return $this; } + public function setStorage(?string $storage): self + { + $this->set('storage', $storage); + + return $this; + } + public function setName(?string $name): self { $this->set('name', $name); diff --git a/application/Espo/Repositories/Attachment.php b/application/Espo/Repositories/Attachment.php index cfe472c4b9..6dbd490941 100644 --- a/application/Espo/Repositories/Attachment.php +++ b/application/Espo/Repositories/Attachment.php @@ -62,13 +62,13 @@ class Attachment extends Database implements protected function processBeforeSaveNew(AttachmentEntity $entity): void { if ($entity->isBeingUploaded()) { - $entity->set('storage', EspoUploadDir::NAME); + $entity->setStorage(EspoUploadDir::NAME); } if (!$entity->getStorage()) { $defaultStorage = $this->config->get('defaultFileStorage'); - $entity->set('storage', $defaultStorage); + $entity->setStorage($defaultStorage); } $contents = $entity->get('contents'); @@ -78,7 +78,7 @@ class Attachment extends Database implements } if (!$entity->isBeingUploaded()) { - $entity->set('size', strlen($contents)); + $entity->setSize(strlen($contents)); } $this->fileStorageManager->putContents($entity, $contents); @@ -89,23 +89,22 @@ class Attachment extends Database implements */ public function getCopiedAttachment(AttachmentEntity $entity, ?string $role = null): AttachmentEntity { - $attachment = $this->getNew(); + $new = $this->getNew(); - $attachment->set([ - 'sourceId' => $entity->getSourceId(), - 'name' => $entity->getName(), - 'type' => $entity->getType(), - 'size' => $entity->getSize(), - 'role' => $entity->getRole(), - ]); + $new + ->setSourceId($entity->getSourceId()) + ->setName($entity->getName()) + ->setType($entity->getType()) + ->setSize($entity->getSize()) + ->setRole($entity->getRole()); if ($role) { - $attachment->set('role', $role); + $new->setRole($role); } - $this->save($attachment); + $this->save($new); - return $attachment; + return $new; } public function getContents(AttachmentEntity $entity): string