From b640024b517387be33442342635e483da92e782f Mon Sep 17 00:00:00 2001
From: fabrixxm <fabrix.xm@gmail.com>
Date: Wed, 2 Jan 2019 16:37:55 +0100
Subject: [PATCH] Item model, fix deletion of all attachments
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

Item model delete all attachments on item deletion, but it should check
if same attachment isn't used somewhere else.
---
 src/Model/Item.php | 4 +++-
 vagrant.local.yaml | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)
 create mode 100644 vagrant.local.yaml

diff --git a/src/Model/Item.php b/src/Model/Item.php
index a6e378034b..b71db999d0 100644
--- a/src/Model/Item.php
+++ b/src/Model/Item.php
@@ -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']]);
diff --git a/vagrant.local.yaml b/vagrant.local.yaml
new file mode 100644
index 0000000000..7347cc7def
--- /dev/null
+++ b/vagrant.local.yaml
@@ -0,0 +1,2 @@
+server:
+  memory: "1024" # MB
-- 
2.39.5