]> git.mxchange.org Git - friendica.git/commitdiff
Preparation for new deletion functionality
authorMichael <heluecht@pirati.ca>
Sat, 26 May 2018 20:23:49 +0000 (20:23 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 26 May 2018 20:23:49 +0000 (20:23 +0000)
src/Model/Item.php

index 6effb393a28adcef425a0c8d5f157520a31bea56..ea866152bb46126cc5f5b8a87da256b1ec7498bd 100644 (file)
@@ -92,12 +92,13 @@ class Item extends BaseObject
         *
         * @param array $condition The condition for finding the item entries
         * @param integer $priority Priority for the notification
+        * @param integer $uid User who wants to delete the item
         */
-       public static function delete($condition, $priority = PRIORITY_HIGH)
+       public static function delete($condition, $priority = PRIORITY_HIGH, $uid = 0)
        {
                $items = dba::select('item', ['id'], $condition);
                while ($item = dba::fetch($items)) {
-                       self::deleteById($item['id'], $priority);
+                       self::deleteById($item['id'], $priority, $uid);
                }
                dba::close($items);
        }
@@ -107,10 +108,11 @@ class Item extends BaseObject
         *
         * @param integer $item_id Item ID that should be delete
         * @param integer $priority Priority for the notification
+        * @param integer $uid User who wants to delete the item
         *
         * @return boolean success
         */
-       public static function deleteById($item_id, $priority = PRIORITY_HIGH)
+       public static function deleteById($item_id, $priority = PRIORITY_HIGH, $uid = 0)
        {
                // locate item to be deleted
                $fields = ['id', 'uri', 'uid', 'parent', 'parent-uri', 'origin',
@@ -132,6 +134,12 @@ class Item extends BaseObject
                        $parent = ['origin' => false];
                }
 
+               // "Deleting" global items just means hiding them
+               if (($item['uid'] == 0) && ($uid != 0)) {
+                       dba::update('user-item', ['hidden' => true], ['iid' => $item_id, 'uid' => $uid], true);
+                       return true;
+               }
+
                // clean up categories and tags so they don't end up as orphans
 
                $matches = false;