public function deleteNotExistFiles($relatedIds, $existIds) { foreach (array_diff($relatedIds, $existIds) as $id) { // 删除索引关系 AttachmentIndex::deleteAll(['attachment_id' => $id, 'entity_id' => $this->getEntityId(), 'attribute' => $this->attribute, 'entity' => $this->getEntityClass()]); // 尝试删除文件 $this->deleteFile($id); } }
public function afterDelete() { // 删除关系表 AttachmentIndex::deleteAll(['attachment_id' => $this->primaryKey]); try { $media = MediaItem::createFromAttachment($this); if ($media->isImage()) { $this->deleteThumbs(); } $this->deleteFile(); } catch (\Exception $ex) { } }