Skip to content

Commit

Permalink
🐛 Fixing a bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
wisp-x committed Mar 19, 2020
1 parent ca06b2f commit 62b0ee5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 36 deletions.
25 changes: 7 additions & 18 deletions application/index/controller/User.php
Expand Up @@ -49,25 +49,14 @@ public function deleteImages($deleteId = null)
try {
$id = $deleteId ? $deleteId : $this->request->post('id');
$deletes = []; // 需要删除的文件
if (is_array($id)) {
$images = $this->user->images()->where('id', $id)->select();
foreach ($images as &$value) {
// 查找是否有相同 md5 的文件记录,有的话则只删除记录不删除文件
if (!$this->exists($value)) {
$deletes[$value->strategy][] = $value->pathname;
}
$value->delete();
unset($value);
}
} else {
$image = $this->user->images()->where('id', $id)->find();
if (!$image) {
throw new Exception('没有找到该图片数据');
}
if (!$this->exists($image)) {
$deletes[$image->strategy][] = $image->pathname;
$images = $this->user->images()->where('id', 'in', $id)->select();
foreach ($images as &$value) {
// 查找是否有相同 md5 的文件记录,有的话则只删除记录不删除文件
if (!$this->exists($value)) {
$deletes[$value->strategy][] = $value->pathname;
}
$image->delete();
$value->delete();
unset($value);
}
// 是否开启软删除(开启了只删除记录,不删除文件)
if (!$this->getConfig('soft_delete')) {
Expand Down
25 changes: 7 additions & 18 deletions application/index/controller/admin/Images.php
Expand Up @@ -77,25 +77,14 @@ public function delete()
try {
$id = $this->request->post('id');
$deletes = []; // 需要删除的文件
if (is_array($id)) {
$images = ImagesModel::all($id);
foreach ($images as &$value) {
// 查找是否有相同 md5 的文件记录,有的话则只删除记录不删除文件
if (!$this->exists($value)) {
$deletes[$value->strategy][] = $value->pathname;
}
$value->delete();
unset($value);
}
} else {
$image = ImagesModel::get($id);
if (!$image) {
throw new Exception('没有找到该图片数据');
}
if (!$this->exists($image)) {
$deletes[$image->strategy][] = $image->pathname;
$images = ImagesModel::where('id', 'in', $id)->select();
foreach ($images as &$value) {
// 查找是否有相同 md5 的文件记录,有的话则只删除记录不删除文件
if (!$this->exists($value)) {
$deletes[$value->strategy][] = $value->pathname;
}
$image->delete();
$value->delete();
unset($value);
}
// 是否开启软删除(开启了只删除记录,不删除文件)
if (!$this->getConfig('soft_delete')) {
Expand Down

0 comments on commit 62b0ee5

Please sign in to comment.