This commit is contained in:
Yuri Kuznetsov
2024-04-20 21:34:49 +03:00
parent df55323a04
commit ad0fbb577f
2 changed files with 20 additions and 14 deletions
+7
View File
@@ -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);
+13 -14
View File
@@ -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