From 52eb2281e41b8493438d21b770572cdc9af8fcb2 Mon Sep 17 00:00:00 2001 From: Jonny Tischbein Date: Sat, 17 Nov 2018 12:41:00 +0100 Subject: [PATCH 1/5] Fix deleting last element from saved folder + Fix displaying empty saved folder --- mod/filerm.php | 12 +++++++++--- mod/network.php | 1 + src/Model/FileTag.php | 2 +- src/Model/Item.php | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/mod/filerm.php b/mod/filerm.php index 335b27b32..d8da0e125 100644 --- a/mod/filerm.php +++ b/mod/filerm.php @@ -14,7 +14,7 @@ function filerm_content(App $a) } $term = XML::unescape(trim($_GET['term'])); - $cat = XML::unescape(trim($_GET['cat'])); + $cat = XML::unescape(trim(defaults($_GET, 'cat', ''))); $category = (($cat) ? true : false); @@ -25,12 +25,18 @@ function filerm_content(App $a) $item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0); - Logger::log('filerm: tag ' . $term . ' item ' . $item_id); + Logger::log('filerm: tag ' . $term . ' item ' . $item_id . ' category ' . ($category ? 'true' : 'false')); if ($item_id && strlen($term)) { - FileTag::unsaveFile(local_user(), $item_id, $term, $category); + if (FileTag::unsaveFile(local_user(), $item_id, $term, $category)){ + info('Item removed'); + } + } + else { + info('Item was not deleted'); } + $a->internalRedirect('/network?f=&file=' . $term); killme(); } diff --git a/mod/network.php b/mod/network.php index 81a2f2b2b..37c7b4528 100644 --- a/mod/network.php +++ b/mod/network.php @@ -346,6 +346,7 @@ function networkConversation(App $a, $items, Pager $pager, $mode, $update, $orde // Set this so that the conversation function can find out contact info for our wall-wall items $a->page_contact = $a->contact; + $items = (empty($items) ? [] : $items); $o = conversation($a, $items, $pager, $mode, $update, false, $ordering, local_user()); if (!$update) { diff --git a/src/Model/FileTag.php b/src/Model/FileTag.php index d3baffdd4..b5c4cf2ae 100644 --- a/src/Model/FileTag.php +++ b/src/Model/FileTag.php @@ -290,7 +290,7 @@ class FileTag return false; } - $fields = ['file' => str_replace($pattern, '', $item['file'])]; + $fields = ['file' => str_replace($pattern, null, $item['file'])]; Item::update($fields, ['id' => $item_id]); $r = q("SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d", diff --git a/src/Model/Item.php b/src/Model/Item.php index 4a29e51d3..8e154b083 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -911,7 +911,7 @@ class Item extends BaseObject } } - if (!empty($files)) { + if (!is_null($files)) { Term::insertFromFileFieldByItemId($item['id'], $files); if (!empty($item['file'])) { DBA::update('item', ['file' => ''], ['id' => $item['id']]); From 56406b99101b6f8a45ffc910b353c52bf77c5523 Mon Sep 17 00:00:00 2001 From: Jonny Tischbein Date: Sat, 17 Nov 2018 13:22:32 +0100 Subject: [PATCH 2/5] Fix SQL Error if no items where found + Fix setting to null --- mod/network.php | 13 ++++++++++++- src/Model/FileTag.php | 6 +++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/mod/network.php b/mod/network.php index 37c7b4528..bfd5e9e87 100644 --- a/mod/network.php +++ b/mod/network.php @@ -346,7 +346,11 @@ function networkConversation(App $a, $items, Pager $pager, $mode, $update, $orde // Set this so that the conversation function can find out contact info for our wall-wall items $a->page_contact = $a->contact; - $items = (empty($items) ? [] : $items); + if (!is_array($items)){ + Logger::log("Expecting items to be an array. Got " . print_r($items, true)); + $items = []; + } + $o = conversation($a, $items, $pager, $mode, $update, false, $ordering, local_user()); if (!$update) { @@ -390,6 +394,10 @@ function network_content(App $a, $update = 0, $parent = 0) $o = networkThreadedView($a, $update, $parent); } + if ($o === ''){ + info("No items found"); + } + return $o; } @@ -464,6 +472,9 @@ function networkFlatView(App $a, $update = 0) } DBA::close($result); + if (count($posts) == 0){ + return ''; + } $condition = ['uid' => local_user(), 'id' => $posts]; } else { $condition = ['uid' => local_user()]; diff --git a/src/Model/FileTag.php b/src/Model/FileTag.php index b5c4cf2ae..403cbd233 100644 --- a/src/Model/FileTag.php +++ b/src/Model/FileTag.php @@ -290,7 +290,11 @@ class FileTag return false; } - $fields = ['file' => str_replace($pattern, null, $item['file'])]; + $fields = ['file' => str_replace($pattern, '', $item['file'])]; + if ($fields === '') { + $fields = null; + } + Item::update($fields, ['id' => $item_id]); $r = q("SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d", From 458b0f35459195b5db243e030778b1e685a7d6eb Mon Sep 17 00:00:00 2001 From: Jonny Tischbein Date: Sat, 17 Nov 2018 16:04:54 +0100 Subject: [PATCH 3/5] Change how to decide between empty update and not called field file --- src/Model/FileTag.php | 3 --- src/Model/Item.php | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Model/FileTag.php b/src/Model/FileTag.php index 403cbd233..06040403a 100644 --- a/src/Model/FileTag.php +++ b/src/Model/FileTag.php @@ -291,9 +291,6 @@ class FileTag } $fields = ['file' => str_replace($pattern, '', $item['file'])]; - if ($fields === '') { - $fields = null; - } Item::update($fields, ['id' => $item_id]); diff --git a/src/Model/Item.php b/src/Model/Item.php index 8e154b083..9aaac7f7a 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -832,7 +832,7 @@ class Item extends BaseObject $files = $fields['file']; $fields['file'] = null; } else { - $files = ''; + $files = null; } $delivery_data = ['postopts' => defaults($fields, 'postopts', ''), From 4f8e50d8346df4c26fdf57ea92161f1137b6db82 Mon Sep 17 00:00:00 2001 From: Jonny Tischbein Date: Sat, 17 Nov 2018 17:24:30 +0100 Subject: [PATCH 4/5] Code Standard --- mod/network.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/network.php b/mod/network.php index bfd5e9e87..1e744bd25 100644 --- a/mod/network.php +++ b/mod/network.php @@ -346,7 +346,7 @@ function networkConversation(App $a, $items, Pager $pager, $mode, $update, $orde // Set this so that the conversation function can find out contact info for our wall-wall items $a->page_contact = $a->contact; - if (!is_array($items)){ + if (!is_array($items)) { Logger::log("Expecting items to be an array. Got " . print_r($items, true)); $items = []; } From 590fbe8c6f809e54dfc054037215509fee392744 Mon Sep 17 00:00:00 2001 From: Jonny Tischbein Date: Sat, 17 Nov 2018 17:27:12 +0100 Subject: [PATCH 5/5] More Code Standard --- mod/filerm.php | 5 ++--- mod/network.php | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/mod/filerm.php b/mod/filerm.php index d8da0e125..30a7f69df 100644 --- a/mod/filerm.php +++ b/mod/filerm.php @@ -27,9 +27,8 @@ function filerm_content(App $a) Logger::log('filerm: tag ' . $term . ' item ' . $item_id . ' category ' . ($category ? 'true' : 'false')); - if ($item_id && strlen($term)) - { - if (FileTag::unsaveFile(local_user(), $item_id, $term, $category)){ + if ($item_id && strlen($term)) { + if (FileTag::unsaveFile(local_user(), $item_id, $term, $category)) { info('Item removed'); } } diff --git a/mod/network.php b/mod/network.php index 1e744bd25..ba02ee5cc 100644 --- a/mod/network.php +++ b/mod/network.php @@ -394,7 +394,7 @@ function network_content(App $a, $update = 0, $parent = 0) $o = networkThreadedView($a, $update, $parent); } - if ($o === ''){ + if ($o === '') { info("No items found"); } @@ -472,7 +472,7 @@ function networkFlatView(App $a, $update = 0) } DBA::close($result); - if (count($posts) == 0){ + if (count($posts) == 0) { return ''; } $condition = ['uid' => local_user(), 'id' => $posts];