Skip to content

Commit

Permalink
モデルをリレーションしている場合リレーション先のモデルの画像が正常に削除できない問題を改善 fix baserproject#2034
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Apr 4, 2023
1 parent cb9cbf1 commit 65fd942
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions plugins/baser-core/src/Model/Behavior/BcUploadBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,17 @@ class BcUploadBehavior extends Behavior

/**
* BcFileUploader
*
* @var BcFileUploader[]
*/
public $BcFileUploader = [];

/**
* Old Entity
* @var EntityInterface
*
* @var EntityInterface[]
*/
public $oldEntity = null;
public $oldEntity = [];

/**
* Initialize
Expand Down Expand Up @@ -126,7 +128,7 @@ public function beforeMarshal(EventInterface $event, ArrayObject $data)
{
$this->BcFileUploader[$this->table()->getAlias()]->setupRequestData($data);
$this->BcFileUploader[$this->table()->getAlias()]->setupTmpData($data);
$this->oldEntity = (!empty($data['id']))? $this->getOldEntity($data['id']) : null;
$this->oldEntity[$this->table()->getAlias()] = (!empty($data['id']))? $this->getOldEntity($data['id']) : null;
}

/**
Expand Down Expand Up @@ -161,7 +163,7 @@ public function afterSave(EventInterface $event, EntityInterface $entity)
}
$this->BcFileUploader[$this->table()->getAlias()]->saveFiles($entity);
if ($entity->id) {
$this->BcFileUploader[$this->table()->getAlias()]->deleteFiles($this->oldEntity, $entity);
$this->BcFileUploader[$this->table()->getAlias()]->deleteFiles($this->oldEntity[$this->table()->getAlias()], $entity);
}
if ($this->BcFileUploader[$this->table()->getAlias()]->isUploaded()) {
$this->BcFileUploader[$this->table()->getAlias()]->renameToBasenameFields($entity);
Expand Down

0 comments on commit 65fd942

Please sign in to comment.