From 19b55f5f8d3d31764a1e2e57cd591b18ebecfa14 Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Wed, 2 Jan 2019 17:15:43 +0100 Subject: [PATCH] Use Attach model while deleting in video tab --- mod/videos.php | 63 ++++++++------------------------------------------ 1 file changed, 10 insertions(+), 53 deletions(-) diff --git a/mod/videos.php b/mod/videos.php index d8aac18210..a117e0f1a8 100644 --- a/mod/videos.php +++ b/mod/videos.php @@ -11,6 +11,7 @@ use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\Model\Attach; use Friendica\Model\Contact; use Friendica\Model\Group; use Friendica\Model\Item; @@ -59,41 +60,6 @@ function videos_init(App $a) '$pdesc' => defaults($profile, 'pdesc', ''), ]); - /// @TODO Old-lost code? - /*$sql_extra = Security::getPermissionsSQLByUserId($a->data['user']['uid']); - - $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc", - intval($a->data['user']['uid']) - ); - - if(count($albums)) { - $a->data['albums'] = $albums; - - $albums_visible = ((intval($a->data['user']['hidewall']) && (!local_user()) && (!remote_user())) ? false : true); - - if($albums_visible) { - $o .= ''; - }*/ - // If not there, create 'aside' empty if (!isset($a->page['aside'])) { $a->page['aside'] = ''; @@ -148,25 +114,16 @@ function videos_post(App $a) $video_id = $_POST['id']; - $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1", - intval(local_user()), - DBA::escape($video_id) - ); + $r = Attach::exists(['id' => $video_id, 'uid' => local_user()]); + if ($r === true) { + // delete the attachment + Attach::delete(['id' => $video_id, 'uid' => local_user()]); - if (DBA::isResult($r)) { - q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'", - intval(local_user()), - DBA::escape($video_id) - ); - - $i = q("SELECT `id` FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1", - DBA::escape($video_id), - intval(local_user()) - ); - - if (DBA::isResult($i)) { - Item::deleteForUser(['id' => $i[0]['id']], local_user()); - } + // delete items where the attach is used + Item::deleteForUser(['`attach` LIKE ? AND `uid` = ?', + '%attach/' . $video_id . '%', + local_user() + ], local_user()); } $a->internalRedirect('videos/' . $a->data['user']['nickname']); -- 2.39.5