Browse Source

Item model, fix deletion of all attachments

Item model delete all attachments on item deletion, but it should check
if same attachment isn't used somewhere else.
pull/6482/head
fabrixxm 2 years ago
committed by Hypolite Petovan
parent
commit
b640024b51
2 changed files with 5 additions and 1 deletions
  1. +3
    -1
      src/Model/Item.php
  2. +2
    -0
      vagrant.local.yaml

+ 3
- 1
src/Model/Item.php View File

@ -1028,6 +1028,7 @@ class Item extends BaseObject
* This only applies to photos uploaded from the photos page. Photos inserted into a post do not
* generate a resource-id and therefore aren't intimately linked to the item.
*/
/// @TODO: this should first check if photo is used elsewhere
if (strlen($item['resource-id'])) {
Photo::delete(['resource-id' => $item['resource-id'], 'uid' => $item['uid']]);
}
@ -1038,7 +1039,8 @@ class Item extends BaseObject
}
// If item has attachments, drop them
foreach (explode(", ", $item['attach']) as $attach) {
/// @TODO: this should first check if attachment is used elsewhere
foreach (explode(",", $item['attach']) as $attach) {
preg_match("|attach/(\d+)|", $attach, $matches);
if (is_array($matches) && count($matches) > 1) {
Attach::delete(['id' => $matches[1], 'uid' => $item['uid']]);


+ 2
- 0
vagrant.local.yaml View File

@ -0,0 +1,2 @@
server:
memory: "1024" # MB

Loading…
Cancel
Save