From abacbf3e0ad668cc4bc2d57b032ceff046343905 Mon Sep 17 00:00:00 2001 From: Alexei Sorokin Date: Fri, 7 Aug 2020 10:20:03 +0300 Subject: [PATCH] [ACTIONS] Fix selftag --- actions/selftag.php | 46 ++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/actions/selftag.php b/actions/selftag.php index 72c6e47d37..2c5bcdf40f 100644 --- a/actions/selftag.php +++ b/actions/selftag.php @@ -92,31 +92,35 @@ class SelftagAction extends Action { $profile = new Profile(); + $profile->_join .= "\n" . <<<'END' + INNER JOIN profile_list ON profile.id = profile_list.tagger + LEFT JOIN profile_role ON profile.id = profile_role.profile_id + END; + + $profile->whereAdd(sprintf( + "profile_list.tag = '%s'", + $profile->escape($this->tag) + )); + $profile->whereAdd("COALESCE(profile_role.role, '') <> 'silenced'"); + + $user = common_current_user(); + if (!empty($user)) { + $profile->whereAdd(sprintf( + 'profile_list.tagger = %d OR profile_list.private IS NOT TRUE', + $user->getID() + )); + } else { + $profile->whereAdd('profile_list.private IS NOT TRUE'); + } + + $profile->orderBy('profile_list.modified DESC'); + $offset = ($this->page - 1) * PROFILES_PER_PAGE; $limit = PROFILES_PER_PAGE + 1; - // XXX: memcached this + $profile->limit($offset, $limit); - $qry = 'SELECT profile.* ' . - 'FROM profile JOIN ( profile_tag, profile_list ) ' . - 'ON profile.id = profile_tag.tagger ' . - 'AND profile_tag.tagger = profile_list.tagger ' . - 'AND profile_list.tag = profile_tag.tag ' . - 'WHERE profile_tag.tagger = profile_tag.tagged ' . - "AND profile_tag.tag = '%s' "; - - $user = common_current_user(); - if (empty($user)) { - $qry .= 'AND profile_list.private IS NOT TRUE '; - } else { - $qry .= 'AND (profile_list.tagger = ' . $user->id . - ' OR profile_list.private IS NOT TRUE) '; - } - - $qry .= 'ORDER BY profile_tag.modified DESC ' . - 'LIMIT ' . $limit . ' OFFSET ' . $offset; - - $profile->query(sprintf($qry, $this->tag)); + $profile->find(); $ptl = new SelfTagProfileList($profile, $this); // pass the ammunition $cnt = $ptl->show();